From 8a9127d22e2d281085fde88c951c7f132c72fa2c Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Velez Date: Sun, 4 Aug 2024 18:08:01 -0400 Subject: [PATCH] wip --- .../PromptPasswordConfirmationModal.tsx | 186 +++++++++++------- loc/en.json | 4 + 2 files changed, 119 insertions(+), 71 deletions(-) diff --git a/components/PromptPasswordConfirmationModal.tsx b/components/PromptPasswordConfirmationModal.tsx index f01e5d65a..fc59859e8 100644 --- a/components/PromptPasswordConfirmationModal.tsx +++ b/components/PromptPasswordConfirmationModal.tsx @@ -18,7 +18,6 @@ interface PromptPasswordConfirmationModalProps { modalType: ModalType; onConfirmationSuccess: (password: string) => Promise; onConfirmationFailure: () => void; - onDismiss?: () => void; } export interface PromptPasswordConfirmationModalHandle { @@ -27,16 +26,18 @@ export interface PromptPasswordConfirmationModalHandle { } const PromptPasswordConfirmationModal = forwardRef( - ({ modalType, onConfirmationSuccess, onConfirmationFailure, onDismiss }, ref) => { + ({ modalType, onConfirmationSuccess, onConfirmationFailure }, ref) => { const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [isLoading, setIsLoading] = useState(false); const [isSuccess, setIsSuccess] = useState(false); + const [showExplanation, setShowExplanation] = useState(true); // State to toggle between explanation and password input for CREATE_PASSWORD const modalRef = useRef(null); const fadeOutAnimation = useRef(new Animated.Value(1)).current; const fadeInAnimation = useRef(new Animated.Value(0)).current; const scaleAnimation = useRef(new Animated.Value(1)).current; const shakeAnimation = useRef(new Animated.Value(0)).current; + const explanationOpacity = useRef(new Animated.Value(1)).current; // New animated value for opacity const { colors } = useTheme(); const passwordInputRef = useRef(null); const confirmPasswordInputRef = useRef(null); @@ -64,7 +65,7 @@ const PromptPasswordConfirmationModal = forwardRef { resetState(); modalRef.current?.present(); - if (modalType === MODAL_TYPES.CREATE_PASSWORD) { + if (modalType === MODAL_TYPES.CREATE_PASSWORD && !showExplanation) { passwordInputRef.current?.focus(); } else if (modalType === MODAL_TYPES.ENTER_PASSWORD) { passwordInputRef.current?.focus(); @@ -72,7 +73,7 @@ const PromptPasswordConfirmationModal = forwardRef { await modalRef.current?.dismiss(); - onDismiss?.(); // Call onDismiss if provided after modal dismisses + resetState(); }, })); @@ -85,26 +86,46 @@ const PromptPasswordConfirmationModal = forwardRef { + resetState(); + }, [modalType]); + const handleShakeAnimation = () => { Animated.sequence([ Animated.timing(shakeAnimation, { toValue: 10, - duration: 100, - easing: Easing.bounce, + duration: 150, + easing: Easing.inOut(Easing.ease), useNativeDriver: true, }), Animated.timing(shakeAnimation, { toValue: -10, + duration: 150, + easing: Easing.inOut(Easing.ease), + useNativeDriver: true, + }), + Animated.timing(shakeAnimation, { + toValue: 5, duration: 100, - easing: Easing.bounce, + easing: Easing.inOut(Easing.ease), + useNativeDriver: true, + }), + Animated.timing(shakeAnimation, { + toValue: -5, + duration: 100, + easing: Easing.inOut(Easing.ease), useNativeDriver: true, }), Animated.timing(shakeAnimation, { toValue: 0, duration: 100, - easing: Easing.bounce, + easing: Easing.inOut(Easing.ease), useNativeDriver: true, }), ]).start(() => { @@ -175,22 +196,23 @@ const PromptPasswordConfirmationModal = forwardRef { + Animated.timing(explanationOpacity, { + toValue: 0, + duration: 300, + useNativeDriver: true, + }).start(() => { + setShowExplanation(false); + explanationOpacity.setValue(1); // Reset opacity for when transitioning back + passwordInputRef.current?.focus(); + }); + }; + const handleCancel = async () => { - resetState(); onConfirmationFailure(); await modalRef.current?.dismiss(); }; - useEffect(() => { - resetState(); - if (modalType === MODAL_TYPES.CREATE_PASSWORD) { - passwordInputRef.current?.focus(); - } else if (modalType === MODAL_TYPES.ENTER_PASSWORD) { - passwordInputRef.current?.focus(); - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [modalType]); - const animatedViewStyle: Animated.WithAnimatedObject = { opacity: fadeOutAnimation, transform: [{ scale: scaleAnimation }], @@ -201,65 +223,82 @@ const PromptPasswordConfirmationModal = forwardRef - - - - - - - ) || undefined + !isSuccess ? ( + showExplanation && modalType === MODAL_TYPES.CREATE_PASSWORD ? null : ( + + + + + + + + ) + ) : null } > - {!isSuccess && modalType !== MODAL_TYPES.SUCCESS && ( + {!isSuccess && ( - - {modalType === MODAL_TYPES.CREATE_PASSWORD ? loc.settings.password_explain : loc._.enter_password} - - - - + {modalType === MODAL_TYPES.CREATE_PASSWORD && showExplanation && ( + + {loc.settings.encrypt_storage_explanation_headline} + + {loc.settings.encrypt_storage_explanation_description_line1} + + + {loc.settings.encrypt_storage_explanation_description_line2} + + + - {modalType === MODAL_TYPES.CREATE_PASSWORD && ( - - - - )} - + )} + {(modalType === MODAL_TYPES.ENTER_PASSWORD || (modalType === MODAL_TYPES.CREATE_PASSWORD && !showExplanation)) && ( + <> + + {modalType === MODAL_TYPES.CREATE_PASSWORD ? loc.settings.password_explain : loc._.enter_password} + + + + + + {modalType === MODAL_TYPES.CREATE_PASSWORD && ( + + + + )} + + + )} )} {isSuccess && ( @@ -278,7 +317,7 @@ const PromptPasswordConfirmationModal = forwardRef