From 202980424b78354ea8347290ca9c8c9b59fc32a0 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 17 Dec 2024 15:02:40 -0700 Subject: [PATCH] Revert "Revert "Replace navigation blur listeners with `useFocusEffect`"" --- src/components/Button/index.tsx | 5 ++ src/components/ConfirmationPage.tsx | 1 + src/hooks/useWaitForNavigation.ts | 27 +++---- src/pages/workspace/upgrade/UpgradeIntro.tsx | 1 + .../upgrade/WorkspaceUpgradePage.tsx | 29 ++++--- tests/ui/WorkspaceUpgradeTest.tsx | 76 +++++++++++++++++++ 6 files changed, 109 insertions(+), 30 deletions(-) create mode 100644 tests/ui/WorkspaceUpgradeTest.tsx diff --git a/src/components/Button/index.tsx b/src/components/Button/index.tsx index 07edd148778d..84767c6347e7 100644 --- a/src/components/Button/index.tsx +++ b/src/components/Button/index.tsx @@ -122,6 +122,9 @@ type ButtonProps = Partial & { /** Id to use for this button */ id?: string; + /** Used to locate this button in ui tests */ + testID?: string; + /** Accessibility label for the component */ accessibilityLabel?: string; @@ -237,6 +240,7 @@ function Button( shouldShowRightIcon = false, id = '', + testID = undefined, accessibilityLabel = '', isSplitButton = false, link = false, @@ -405,6 +409,7 @@ function Button( ]} disabledStyle={disabledStyle} id={id} + testID={testID} accessibilityLabel={accessibilityLabel} role={CONST.ROLE.BUTTON} hoverDimmingValue={1} diff --git a/src/components/ConfirmationPage.tsx b/src/components/ConfirmationPage.tsx index a95cf9bf87d2..7b55f2317d46 100644 --- a/src/components/ConfirmationPage.tsx +++ b/src/components/ConfirmationPage.tsx @@ -82,6 +82,7 @@ function ConfirmationPage({ success large text={buttonText} + testID="confirmation-button" style={styles.mt6} pressOnEnter onPress={onButtonPress} diff --git a/src/hooks/useWaitForNavigation.ts b/src/hooks/useWaitForNavigation.ts index 73c0eb2bb14c..05981ec3322b 100644 --- a/src/hooks/useWaitForNavigation.ts +++ b/src/hooks/useWaitForNavigation.ts @@ -1,5 +1,5 @@ -import {useNavigation} from '@react-navigation/native'; -import {useEffect, useRef} from 'react'; +import {useFocusEffect} from '@react-navigation/native'; +import {useCallback, useRef} from 'react'; type UseWaitForNavigation = (navigate: () => void) => () => Promise; @@ -8,21 +8,18 @@ type UseWaitForNavigation = (navigate: () => void) => () => Promise; * Only use when navigating by react-navigation */ export default function useWaitForNavigation(): UseWaitForNavigation { - const navigation = useNavigation(); const resolvePromises = useRef void>>([]); - useEffect(() => { - const unsubscribeBlur = navigation.addListener('blur', () => { - resolvePromises.current.forEach((resolve) => { - resolve(); - }); - resolvePromises.current = []; - }); - - return () => { - unsubscribeBlur(); - }; - }, [navigation]); + useFocusEffect( + useCallback(() => { + return () => { + resolvePromises.current.forEach((resolve) => { + resolve(); + }); + resolvePromises.current = []; + }; + }, []), + ); return (navigate: () => void) => () => { navigate(); diff --git a/src/pages/workspace/upgrade/UpgradeIntro.tsx b/src/pages/workspace/upgrade/UpgradeIntro.tsx index d45e27905c28..029f8e78271f 100644 --- a/src/pages/workspace/upgrade/UpgradeIntro.tsx +++ b/src/pages/workspace/upgrade/UpgradeIntro.tsx @@ -75,6 +75,7 @@ function UpgradeIntro({feature, onUpgrade, buttonDisabled, loading, isCategorizi