Skip to content

Commit 0569d4c

Browse files
janicduplessisfacebook-github-bot
authored andcommitted
Remove JS autoFocus implementation (#27923)
Summary: Follow up to #27803 and #27924. We no longer need to call focus on mount from JS as both iOS and Android implements it natively now. ## Changelog [General] [Fixed] - Remove JS autoFocus implementation Pull Request resolved: #27923 Test Plan: Test that focus works in RN Tester with this, #27803 and #27924 Differential Revision: D19956373 Pulled By: TheSavior fbshipit-source-id: 5d99ead55011663b3edaf499ac7616765a24cb50
1 parent b23efc5 commit 0569d4c

File tree

1 file changed

+0
-38
lines changed

1 file changed

+0
-38
lines changed

Libraries/Components/TextInput/TextInput.js

-38
Original file line numberDiff line numberDiff line change
@@ -699,42 +699,6 @@ type ImperativeMethods = $ReadOnly<{|
699699

700700
const emptyFunctionThatReturnsTrue = () => true;
701701

702-
function useFocusOnMount(
703-
initialAutoFocus: ?boolean,
704-
inputRef: {|
705-
current: null | React.ElementRef<HostComponent<mixed>>,
706-
|},
707-
) {
708-
const initialAutoFocusValue = useRef<?boolean>(initialAutoFocus);
709-
710-
useEffect(() => {
711-
// We only want to autofocus on initial mount.
712-
// Since initialAutoFocusValue and inputRef will never change
713-
// this should match the expected behavior
714-
if (initialAutoFocusValue.current) {
715-
const focus = () => {
716-
if (inputRef.current != null) {
717-
inputRef.current.focus();
718-
}
719-
};
720-
721-
let rafId;
722-
if (Platform.OS === 'android') {
723-
// On Android this needs to be executed in a rAF callback
724-
// otherwise the keyboard opens then closes immediately.
725-
rafId = requestAnimationFrame(focus);
726-
} else {
727-
focus();
728-
}
729-
730-
return () => {
731-
if (rafId != null) {
732-
cancelAnimationFrame(rafId);
733-
}
734-
};
735-
}
736-
}, [initialAutoFocusValue, inputRef]);
737-
}
738702
/**
739703
* A foundational component for inputting text into the app via a
740704
* keyboard. Props provide configurability for several features, such as
@@ -935,8 +899,6 @@ function InternalTextInput(props: Props): React.Node {
935899
text,
936900
]);
937901

938-
useFocusOnMount(props.autoFocus, inputRef);
939-
940902
useEffect(() => {
941903
const inputRefValue = inputRef.current;
942904

0 commit comments

Comments
 (0)