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

Remove JS autoFocus implementation #27923

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,42 +686,6 @@ type ImperativeMethods = $ReadOnly<{|

const emptyFunctionThatReturnsTrue = () => true;

function useFocusOnMount(
initialAutoFocus: ?boolean,
inputRef: {|
current: null | React.ElementRef<HostComponent<mixed>>,
|},
) {
const initialAutoFocusValue = useRef<?boolean>(initialAutoFocus);

useEffect(() => {
// We only want to autofocus on initial mount.
// Since initialAutoFocusValue and inputRef will never change
// this should match the expected behavior
if (initialAutoFocusValue.current) {
const focus = () => {
if (inputRef.current != null) {
inputRef.current.focus();
}
};

let rafId;
if (Platform.OS === 'android') {
// On Android this needs to be executed in a rAF callback
// otherwise the keyboard opens then closes immediately.
rafId = requestAnimationFrame(focus);
} else {
focus();
}

return () => {
if (rafId != null) {
cancelAnimationFrame(rafId);
}
};
}
}, [initialAutoFocusValue, inputRef]);
}
/**
* A foundational component for inputting text into the app via a
* keyboard. Props provide configurability for several features, such as
Expand Down Expand Up @@ -875,8 +839,6 @@ function InternalTextInput(props: Props): React.Node {
}
}, [inputRef, props.value, lastNativeText, selection, lastNativeSelection]);

useFocusOnMount(props.autoFocus, inputRef);

useEffect(() => {
const tag = ReactNative.findNodeHandle(inputRef.current);
if (tag != null) {
Expand Down