1- import React , { useCallback , useEffect , useRef , useState } from 'react' ;
2- import { InteractionManager , View } from 'react-native' ;
1+ import React , { useCallback , useState } from 'react' ;
2+ import { View } from 'react-native' ;
33import Icon from '@components/Icon' ;
44import PressableWithFeedback from '@components/Pressable/PressableWithFeedback' ;
55import type { ListItem } from '@components/SelectionList/types' ;
66import Text from '@components/Text' ;
77import type { BaseTextInputRef } from '@components/TextInput/BaseTextInput/types' ;
88import useAnimatedHighlightStyle from '@hooks/useAnimatedHighlightStyle' ;
9+ import useAutoFocusInput from '@hooks/useAutoFocusInput' ;
910import { useMemoizedLazyExpensifyIcons } from '@hooks/useLazyAsset' ;
1011import useLocalize from '@hooks/useLocalize' ;
11- import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionStatus' ;
1212import useTheme from '@hooks/useTheme' ;
1313import useThemeStyles from '@hooks/useThemeStyles' ;
1414import { getDecodedCategoryName } from '@libs/CategoryUtils' ;
@@ -37,8 +37,6 @@ function SplitListItem<TItem extends ListItem>({
3737 const theme = useTheme ( ) ;
3838 const styles = useThemeStyles ( ) ;
3939 const { translate} = useLocalize ( ) ;
40- const { didScreenTransitionEnd} = useScreenWrapperTransitionStatus ( ) ;
41-
4240 const splitItem = item as unknown as SplitListItemType ;
4341
4442 const formattedOriginalAmount = convertToDisplayStringWithoutCurrency ( splitItem . originalAmount , splitItem . currency ) ;
@@ -55,7 +53,7 @@ function SplitListItem<TItem extends ListItem>({
5553 [ splitItem ] ,
5654 ) ;
5755
58- const inputRef = useRef < BaseTextInputRef | null > ( null ) ;
56+ const { inputCallbackRef : autoFocusCallbackRef } = useAutoFocusInput ( ) ;
5957
6058 // Animated highlight style for selected item
6159 const animatedHighlightStyle = useAnimatedHighlightStyle ( {
@@ -75,23 +73,14 @@ function SplitListItem<TItem extends ListItem>({
7573 onInputFocus ?.( item ) ;
7674 } , [ onInputFocus , item ] ) ;
7775
78- // Auto-focus input when item is selected and screen transition ends
79- useEffect ( ( ) => {
80- if ( ! didScreenTransitionEnd || ! splitItem . isSelected || ! splitItem . isEditable || ! inputRef . current ) {
76+ // Only connect the auto-focus ref to the selected item so useAutoFocusInput's useFocusEffect
77+ // cleanup can cancel any pending focus task when the screen starts closing, preventing
78+ // the focused input from interfering with the close animation.
79+ const inputCallbackRef : ( ref : BaseTextInputRef | null ) => void = ( ref ) => {
80+ if ( ! splitItem . isSelected || ! splitItem . isEditable ) {
8181 return ;
8282 }
83-
84- // Use InteractionManager to ensure input focus happens after all animations/interactions complete.
85- // This prevents focus from interrupting modal close/open animations which would cause UI glitches
86- // and "jumping" behavior when quickly navigating between screens.
87- // eslint-disable-next-line @typescript-eslint/no-deprecated
88- InteractionManager . runAfterInteractions ( ( ) => {
89- inputRef . current ?. focus ( ) ;
90- } ) ;
91- } , [ didScreenTransitionEnd , splitItem . isSelected , splitItem . isEditable ] ) ;
92-
93- const inputCallbackRef = ( ref : BaseTextInputRef | null ) => {
94- inputRef . current = ref ;
83+ ( autoFocusCallbackRef as unknown as ( ref : BaseTextInputRef | null ) => void ) ( ref ) ;
9584 } ;
9685
9786 const isPercentageMode = splitItem . mode === CONST . TAB . SPLIT . PERCENTAGE ;
0 commit comments