Skip to content

Commit

Permalink
Remove requestAnimationFrame when focusing input on mount
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Nov 22, 2019
1 parent 1610c08 commit 2177806
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,14 +702,25 @@ function useFocusOnMount(
// Since initialAutoFocusValue and inputRef will never change
// this should match the expected behavior
if (initialAutoFocusValue.current) {
const rafId = requestAnimationFrame(() => {
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 () => {
cancelAnimationFrame(rafId);
if (rafId != null) {
cancelAnimationFrame(rafId);
}
};
}
}, [initialAutoFocusValue, inputRef]);
Expand Down

0 comments on commit 2177806

Please sign in to comment.