diff --git a/src/components/AnimatedStep/AnimatedStepContext.ts b/src/components/AnimatedStep/AnimatedStepContext.ts index a95669c6b626..61b2cfc75cc5 100644 --- a/src/components/AnimatedStep/AnimatedStepContext.ts +++ b/src/components/AnimatedStep/AnimatedStepContext.ts @@ -9,7 +9,7 @@ type StepContext = { currentStep: string; previousStep: string | null; setStep: (newStep: string, direction: AnimationDirection) => void; - renderStep: (stepName: string) => React.ReactNode; + renderStep: () => React.ReactNode; currentScreenAnimatedStyle: StyleProp; previousScreenAnimatedStyle: StyleProp; }; diff --git a/src/components/AnimatedStep/AnimatedStepProvider.tsx b/src/components/AnimatedStep/AnimatedStepProvider.tsx index 9b607fc07eef..f1433f471a66 100644 --- a/src/components/AnimatedStep/AnimatedStepProvider.tsx +++ b/src/components/AnimatedStep/AnimatedStepProvider.tsx @@ -1,3 +1,4 @@ +import type {ReactNode} from 'react'; import React, {useCallback, useMemo, useState} from 'react'; import {Easing, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; @@ -12,10 +13,10 @@ const ANIMATED_SCREEN_TRANSITION = 400; type AnimatedStepProviderProps = ChildrenProps & { initialStep: string; - renderStep: (name: string) => React.ReactNode; + steps: Record; }; -function AnimatedStepProvider({children, renderStep, initialStep}: AnimatedStepProviderProps): React.ReactNode { +function AnimatedStepProvider({children, steps, initialStep}: AnimatedStepProviderProps): React.ReactNode { const [animationDirection, setAnimationDirection] = useState(CONST.ANIMATION_DIRECTION.IN); const [currentStep, setCurrentStep] = useState(initialStep); const [previousStep, setPreviousStep] = useState(null); @@ -30,21 +31,30 @@ function AnimatedStepProvider({children, renderStep, initialStep}: AnimatedStepP const setStep = useCallback( (newStep: string, direction: AnimationDirection) => { + console.log(`%%% currentStep`, currentStep); + console.log(`%%% newStep`, newStep); + console.log(`%%% currentStep === newStep`, currentStep === newStep); + + if (currentStep === newStep || !!previousStep) { + return; + } + setAnimationDirection(direction); setPreviousStep(currentStep); setCurrentStep(newStep); - const sideBarWidth = isSmallScreenWidth ? windowWidth : variables.sideBarWidth; - const currentStepPosition = direction === 'in' ? sideBarWidth : -CONST.ANIMATED_TRANSITION_FROM_VALUE; - const previousStepPosition = direction === 'in' ? -CONST.ANIMATED_TRANSITION_FROM_VALUE : sideBarWidth; - - currentTranslateX.set(currentStepPosition); - currentTranslateX.set(withTiming(0, {duration: ANIMATED_SCREEN_TRANSITION, easing: Easing.inOut(Easing.cubic)}, () => setPreviousStep(null))); + setTimeout(() => { + const sideBarWidth = isSmallScreenWidth ? windowWidth : variables.sideBarWidth; + const currentStepPosition = direction === 'in' ? sideBarWidth : -CONST.ANIMATED_TRANSITION_FROM_VALUE; + const previousStepPosition = direction === 'in' ? -CONST.ANIMATED_TRANSITION_FROM_VALUE : sideBarWidth; + currentTranslateX.set(currentStepPosition); + currentTranslateX.set(withTiming(0, {duration: ANIMATED_SCREEN_TRANSITION, easing: Easing.inOut(Easing.cubic)}, () => setPreviousStep(null))); - prevTranslateX.set(0); - prevTranslateX.set(withTiming(previousStepPosition, {duration: ANIMATED_SCREEN_TRANSITION, easing: Easing.inOut(Easing.cubic)})); + prevTranslateX.set(0); + prevTranslateX.set(withTiming(previousStepPosition, {duration: ANIMATED_SCREEN_TRANSITION, easing: Easing.inOut(Easing.cubic)})); + }, 1000); }, - [currentStep, currentTranslateX, prevTranslateX, isSmallScreenWidth, windowWidth], + [currentStep, previousStep, isSmallScreenWidth, windowWidth, currentTranslateX, prevTranslateX], ); const currentScreenAnimatedStyle = useAnimatedStyle(() => ({ @@ -63,9 +73,16 @@ function AnimatedStepProvider({children, renderStep, initialStep}: AnimatedStepP setStep, currentScreenAnimatedStyle, previousScreenAnimatedStyle, - renderStep, + renderStep: () => { + return ( + <> + {steps[currentStep]} + {previousStep && steps[previousStep]} + + ); + }, }), - [currentStep, previousStep, setStep, currentScreenAnimatedStyle, previousScreenAnimatedStyle, renderStep], + [currentStep, previousStep, setStep, currentScreenAnimatedStyle, previousScreenAnimatedStyle, steps], ); return {children}; diff --git a/src/components/AnimatedStep/index.tsx b/src/components/AnimatedStep/index.tsx index 0beffc72c3dd..987763fde038 100644 --- a/src/components/AnimatedStep/index.tsx +++ b/src/components/AnimatedStep/index.tsx @@ -40,10 +40,16 @@ function AnimatedStep({stepName, title = '', stepCounter, onBackButtonPress, chi onEntryTransitionEnd?.(); }, [onEntryTransitionEnd, previousStep]); + console.log(`%%% currentScreenAnimatedStyle`, currentScreenAnimatedStyle); + console.log(`%%% previousScreenAnimatedStyle`, previousScreenAnimatedStyle); + return ( void; + onFinish?: (value?: string) => void; /** Callback to add participants in MoneyRequestModal */ onParticipantsAdded: (value: Participant[]) => void; diff --git a/src/pages/settings/Security/TwoFactorAuth/Steps/GetCode.tsx b/src/pages/settings/Security/TwoFactorAuth/Steps/GetCode.tsx index d629817a6fff..3b0d76b7ab66 100644 --- a/src/pages/settings/Security/TwoFactorAuth/Steps/GetCode.tsx +++ b/src/pages/settings/Security/TwoFactorAuth/Steps/GetCode.tsx @@ -1,4 +1,4 @@ -import React, {useRef} from 'react'; +import React, {useEffect, useRef} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import AnimatedStep from '@components/AnimatedStep'; @@ -23,6 +23,16 @@ function GetCode() { const {setStep} = useTwoFactorAuthContext(); + useEffect(() => { + console.log('CONST.TWO_FACTOR_AUTH_STEPS.DISABLED 1'); + if (account?.requiresTwoFactorAuth) { + return; + } + + console.log('CONST.TWO_FACTOR_AUTH_STEPS.DISABLED 2'); + setStep(CONST.TWO_FACTOR_AUTH_STEPS.DISABLED); + }, [account?.requiresTwoFactorAuth, setStep]); + return ( { - TwoFactorAuthActions.clearTwoFactorAuthData(); - setStep(CONST.TWO_FACTOR_AUTH_STEPS.ENABLED); - if (backTo) { - Navigation.navigate(backTo); - } - if (forwardTo) { - Link.openLink(forwardTo, environmentURL); - } + setStep(CONST.TWO_FACTOR_AUTH_STEPS.VERIFY, 'out'); }} /> diff --git a/src/pages/settings/Security/TwoFactorAuth/Steps/VerifyStep.tsx b/src/pages/settings/Security/TwoFactorAuth/Steps/VerifyStep.tsx index 7a31a8deb0b8..f4088acae2bb 100644 --- a/src/pages/settings/Security/TwoFactorAuth/Steps/VerifyStep.tsx +++ b/src/pages/settings/Security/TwoFactorAuth/Steps/VerifyStep.tsx @@ -1,4 +1,4 @@ -import React, {useEffect, useRef} from 'react'; +import React, {useEffect, useRef, useState} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import expensifyLogo from '@assets/images/expensify-logo-round-transparent.png'; @@ -30,7 +30,7 @@ function VerifyStep() { const contactMethod = UserUtils.getContactMethod(); const [account] = useOnyx(ONYXKEYS.ACCOUNT); const formRef = useRef(null); - + const [x, setX] = useState(true); const {setStep} = useTwoFactorAuthContext(); useEffect(() => { @@ -41,11 +41,14 @@ function VerifyStep() { }, []); useEffect(() => { - if (!account?.requiresTwoFactorAuth) { + if (x) { return; } setStep(CONST.TWO_FACTOR_AUTH_STEPS.SUCCESS); - }, [account?.requiresTwoFactorAuth, setStep]); + setStep(CONST.TWO_FACTOR_AUTH_STEPS.SUCCESS); + }, [x, setStep]); + + console.log(`%%% rerender VerifyStep`); /** * Splits the two-factor auth secret key in 4 chunks @@ -121,13 +124,10 @@ function VerifyStep() {