diff --git a/src/pages/NewChatPage.tsx b/src/pages/NewChatPage.tsx index cee4d1d98f7f..64e1d5a70955 100755 --- a/src/pages/NewChatPage.tsx +++ b/src/pages/NewChatPage.tsx @@ -1,3 +1,4 @@ +import {useFocusEffect} from '@react-navigation/native'; import isEmpty from 'lodash/isEmpty'; import reject from 'lodash/reject'; import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState} from 'react'; @@ -19,7 +20,6 @@ import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useOnyx from '@hooks/useOnyx'; import useSafeAreaInsets from '@hooks/useSafeAreaInsets'; -import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionStatus'; import useThemeStyles from '@hooks/useThemeStyles'; import {navigateToAndOpenReport, searchInServer, setGroupDraft} from '@libs/actions/Report'; import {canUseTouchScreen} from '@libs/DeviceCapabilities'; @@ -60,7 +60,8 @@ function useOptions() { const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true}); const [newGroupDraft] = useOnyx(ONYXKEYS.NEW_GROUP_CHAT_DRAFT, {canBeMissing: true}); const personalData = useCurrentUserPersonalDetails(); - const {didScreenTransitionEnd} = useScreenWrapperTransitionStatus(); + const focusTimeoutRef = useRef(null); + const [didScreenTransitionEnd, setDidScreenTransitionEnd] = useState(false); const {contacts} = useContactImport(); const {options: listOptions, areOptionsInitialized} = useOptionsList({ shouldInitialize: didScreenTransitionEnd, @@ -100,6 +101,16 @@ function useOptions() { ); }, [cleanSearchTerm, debouncedSearchTerm, options.personalDetails.length, options.recentReports.length, options.userToInvite, selectedOptions]); + useFocusEffect( + useCallback(() => { + focusTimeoutRef.current = setTimeout(() => { + setDidScreenTransitionEnd(true); + }, CONST.ANIMATED_TRANSITION); + + return () => focusTimeoutRef.current && clearTimeout(focusTimeoutRef.current); + }, []), + ); + useEffect(() => { if (!debouncedSearchTerm.length) { return; diff --git a/tests/ui/NewChatPageTest.tsx b/tests/ui/NewChatPageTest.tsx index a40402c0c4dc..15596a2611d2 100644 --- a/tests/ui/NewChatPageTest.tsx +++ b/tests/ui/NewChatPageTest.tsx @@ -76,7 +76,7 @@ describe('NewChatPage', () => { }); const spy = jest.spyOn(SectionList.prototype, 'scrollToLocation'); - const addButton = screen.getAllByText(translateLocal('newChatPage.addToGroup')).at(0); + const addButton = await waitFor(() => screen.getAllByText(translateLocal('newChatPage.addToGroup')).at(0)); if (addButton) { fireEvent.press(addButton); expect(spy).toHaveBeenCalledWith(expect.objectContaining({itemIndex: 0}));