Skip to content

Commit

Permalink
Remove JS autoFocus implementation (#27923)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
janicduplessis authored and facebook-github-bot committed Mar 2, 2020
1 parent b23efc5 commit 0569d4c
Showing 1 changed file with 0 additions and 38 deletions.
38 changes: 0 additions & 38 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,42 +699,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 @@ -935,8 +899,6 @@ function InternalTextInput(props: Props): React.Node {
text,
]);

useFocusOnMount(props.autoFocus, inputRef);

useEffect(() => {
const inputRefValue = inputRef.current;

Expand Down

0 comments on commit 0569d4c

Please sign in to comment.