From 2a20b0557dbedc069a5c0e2986ae8e7d5817c004 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 17 Dec 2024 12:13:57 -0700 Subject: [PATCH] Merge pull request #54244 from Expensify/revert-53735-53360-replace-blur-listeners-with-useFocusEffect Revert "Replace navigation blur listeners with `useFocusEffect`" (cherry picked from commit 367e3c3631ada6b3b4eaa4a77654ea55618a5858) (CP triggered by luacmartins) --- 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, 30 insertions(+), 109 deletions(-) delete mode 100644 tests/ui/WorkspaceUpgradeTest.tsx diff --git a/src/components/Button/index.tsx b/src/components/Button/index.tsx index 84767c6347e7..07edd148778d 100644 --- a/src/components/Button/index.tsx +++ b/src/components/Button/index.tsx @@ -122,9 +122,6 @@ 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; @@ -240,7 +237,6 @@ function Button( shouldShowRightIcon = false, id = '', - testID = undefined, accessibilityLabel = '', isSplitButton = false, link = false, @@ -409,7 +405,6 @@ 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 7b55f2317d46..a95cf9bf87d2 100644 --- a/src/components/ConfirmationPage.tsx +++ b/src/components/ConfirmationPage.tsx @@ -82,7 +82,6 @@ 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 05981ec3322b..73c0eb2bb14c 100644 --- a/src/hooks/useWaitForNavigation.ts +++ b/src/hooks/useWaitForNavigation.ts @@ -1,5 +1,5 @@ -import {useFocusEffect} from '@react-navigation/native'; -import {useCallback, useRef} from 'react'; +import {useNavigation} from '@react-navigation/native'; +import {useEffect, useRef} from 'react'; type UseWaitForNavigation = (navigate: () => void) => () => Promise; @@ -8,18 +8,21 @@ type UseWaitForNavigation = (navigate: () => void) => () => Promise; * Only use when navigating by react-navigation */ export default function useWaitForNavigation(): UseWaitForNavigation { + const navigation = useNavigation(); const resolvePromises = useRef void>>([]); - useFocusEffect( - useCallback(() => { - return () => { - resolvePromises.current.forEach((resolve) => { - resolve(); - }); - resolvePromises.current = []; - }; - }, []), - ); + useEffect(() => { + const unsubscribeBlur = navigation.addListener('blur', () => { + resolvePromises.current.forEach((resolve) => { + resolve(); + }); + resolvePromises.current = []; + }); + + return () => { + unsubscribeBlur(); + }; + }, [navigation]); return (navigate: () => void) => () => { navigate(); diff --git a/src/pages/workspace/upgrade/UpgradeIntro.tsx b/src/pages/workspace/upgrade/UpgradeIntro.tsx index 029f8e78271f..d45e27905c28 100644 --- a/src/pages/workspace/upgrade/UpgradeIntro.tsx +++ b/src/pages/workspace/upgrade/UpgradeIntro.tsx @@ -75,7 +75,6 @@ function UpgradeIntro({feature, onUpgrade, buttonDisabled, loading, isCategorizi