Skip to content

Commit

Permalink
Merge pull request #54670 from ikevin127/ikevin127-iosModalComposerFl…
Browse files Browse the repository at this point in the history
…icker

Fix iOS Composer highlight flicker after closing attachment modal
  • Loading branch information
Beamanator authored Jan 8, 2025
2 parents 0f6756b + 8fce2ab commit 9293c26
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/hooks/useResetComposerFocus.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {useIsFocused} from '@react-navigation/native';
import type {MutableRefObject} from 'react';
import {useEffect, useRef} from 'react';
import {InteractionManager} from 'react-native';
import type {TextInput} from 'react-native';

export default function useResetComposerFocus(inputRef: MutableRefObject<TextInput | null>) {
Expand All @@ -11,8 +12,13 @@ export default function useResetComposerFocus(inputRef: MutableRefObject<TextInp
if (!isFocused || !shouldResetFocusRef.current) {
return;
}
inputRef.current?.focus(); // focus input again
shouldResetFocusRef.current = false;
const interactionTask = InteractionManager.runAfterInteractions(() => {
inputRef.current?.focus(); // focus input again
shouldResetFocusRef.current = false;
});
return () => {
interactionTask.cancel();
};
}, [isFocused, inputRef]);

return {isFocused, shouldResetFocusRef};
Expand Down

0 comments on commit 9293c26

Please sign in to comment.