From e50ffdb5d0c74cef7f62c14c4d3ed6378f5a1295 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 20 Sep 2023 19:07:38 +0700 Subject: [PATCH 1/3] fix: 22388 --- src/pages/iou/steps/NewRequestAmountPage.js | 26 +++++++-------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/pages/iou/steps/NewRequestAmountPage.js b/src/pages/iou/steps/NewRequestAmountPage.js index 6712a8c7cd81..bc1dd6e2f3f6 100644 --- a/src/pages/iou/steps/NewRequestAmountPage.js +++ b/src/pages/iou/steps/NewRequestAmountPage.js @@ -69,24 +69,17 @@ function NewRequestAmountPage({route, iou, report, selectedTab}) { const currency = 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) { + const focusTimeoutRef = useRef(null); + + useFocusEffect(useCallback(() => { + focusTimeoutRef.current = setTimeout(() => textInput.current && textInput.current.focus(), CONST.ANIMATED_TRANSITION); + return () => { + if (!focusTimeoutRef.current) { return; } - - textInput.current.focus(); - }); - }; - - useFocusEffect( - useCallback(() => { - focusTextInput(); - }, []), - ); + clearTimeout(focusTimeoutRef.current); + }; + }, [])); // Check and dismiss modal useEffect(() => { @@ -175,7 +168,6 @@ function NewRequestAmountPage({route, iou, report, selectedTab}) { {({safeAreaPaddingBottomStyle}) => ( From 84e8ecfc0e67e850908581c47528062fcb3e02f2 Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 21 Sep 2023 20:55:56 +0700 Subject: [PATCH 2/3] run prettier --- src/pages/iou/steps/NewRequestAmountPage.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/pages/iou/steps/NewRequestAmountPage.js b/src/pages/iou/steps/NewRequestAmountPage.js index 5d92464aa9cf..8b4d73f0aee0 100644 --- a/src/pages/iou/steps/NewRequestAmountPage.js +++ b/src/pages/iou/steps/NewRequestAmountPage.js @@ -71,15 +71,17 @@ function NewRequestAmountPage({route, iou, report, selectedTab}) { const focusTimeoutRef = useRef(null); - useFocusEffect(useCallback(() => { - focusTimeoutRef.current = setTimeout(() => textInput.current && textInput.current.focus(), CONST.ANIMATED_TRANSITION); - return () => { - if (!focusTimeoutRef.current) { - return; - } - clearTimeout(focusTimeoutRef.current); - }; - }, [])); + useFocusEffect( + useCallback(() => { + focusTimeoutRef.current = setTimeout(() => textInput.current && textInput.current.focus(), CONST.ANIMATED_TRANSITION); + return () => { + if (!focusTimeoutRef.current) { + return; + } + clearTimeout(focusTimeoutRef.current); + }; + }, []), + ); // Check and dismiss modal useEffect(() => { From 6e247b0cc7d941955697859dfe73bcbb3c7a62de Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 21 Sep 2023 23:22:48 +0700 Subject: [PATCH 3/3] fix lint --- src/pages/iou/steps/NewRequestAmountPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/steps/NewRequestAmountPage.js b/src/pages/iou/steps/NewRequestAmountPage.js index 8b4d73f0aee0..32f4e6066063 100644 --- a/src/pages/iou/steps/NewRequestAmountPage.js +++ b/src/pages/iou/steps/NewRequestAmountPage.js @@ -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';