Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Transition animation does not work for request money page #27947

Merged
merged 8 commits into from
Sep 25, 2023
24 changes: 9 additions & 15 deletions src/pages/iou/steps/NewRequestAmountPage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useCallback, useEffect, useRef} from 'react';
import {InteractionManager, View} from 'react-native';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import {useFocusEffect} from '@react-navigation/native';
Expand Down Expand Up @@ -69,22 +69,17 @@ function NewRequestAmountPage({route, iou, report, selectedTab}) {

const currency = CurrencyUtils.isValidCurrencyCode(currentCurrency) ? currentCurrency : iou.currency;

const focusTextInput = () => {
// Component may not be initialized due to navigation transitions
// Wait until interactions are complete before trying to focus
InteractionManager.runAfterInteractions(() => {
// Focus text input
if (!textInput.current) {
return;
}

textInput.current.focus();
});
};
const focusTimeoutRef = useRef(null);

useFocusEffect(
useCallback(() => {
focusTextInput();
focusTimeoutRef.current = setTimeout(() => textInput.current && textInput.current.focus(), CONST.ANIMATED_TRANSITION);
return () => {
if (!focusTimeoutRef.current) {
return;
}
clearTimeout(focusTimeoutRef.current);
};
}, []),
);

Expand Down Expand Up @@ -175,7 +170,6 @@ function NewRequestAmountPage({route, iou, report, selectedTab}) {
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
shouldEnableKeyboardAvoidingView={false}
onEntryTransitionEnd={focusTextInput}
testID={NewRequestAmountPage.displayName}
>
{({safeAreaPaddingBottomStyle}) => (
Expand Down
Loading