Skip to content

Commit

Permalink
Make callback run on the JS thread
Browse files Browse the repository at this point in the history
  • Loading branch information
j-piasecki committed Jan 17, 2024
1 parent ea72d4b commit 4edc9dd
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/components/MagicCodeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,19 @@ function MagicCodeInput(props) {
* Tap gesture configuration, updates the indexes of the
* currently focused input.
*/
const tapGesture = Gesture.Tap().onBegin((event) => {
const index = Math.floor(event.x / (inputWidth.current / props.maxLength));
shouldFocusLast.current = false;
// TapGestureHandler works differently on mobile web and native app
// On web gesture handler doesn't block interactions with textInput below so there is no need to run `focus()` manually
if (!Browser.isMobileChrome() && !Browser.isMobileSafari()) {
inputRefs.current.focus();
}
setInputAndIndex(index);
lastFocusedIndex.current = index;
});
const tapGesture = Gesture.Tap()
.runOnJS(true)
.onBegin((event) => {
const index = Math.floor(event.x / (inputWidth.current / props.maxLength));
shouldFocusLast.current = false;
// TapGestureHandler works differently on mobile web and native app
// On web gesture handler doesn't block interactions with textInput below so there is no need to run `focus()` manually
if (!Browser.isMobileChrome() && !Browser.isMobileSafari()) {
inputRefs.current.focus();
}
setInputAndIndex(index);
lastFocusedIndex.current = index;
});

/**
* Updates the magic inputs with the contents written in the
Expand Down

0 comments on commit 4edc9dd

Please sign in to comment.