diff --git a/src/libs/focusWithDelay.js b/src/libs/focusWithDelay.ts similarity index 72% rename from src/libs/focusWithDelay.js rename to src/libs/focusWithDelay.ts index 367cc2b92f9f..00d0e915879e 100644 --- a/src/libs/focusWithDelay.js +++ b/src/libs/focusWithDelay.ts @@ -1,15 +1,14 @@ -import {InteractionManager} from 'react-native'; +import {InteractionManager, TextInput} from 'react-native'; import ComposerFocusManager from './ComposerFocusManager'; +type FocusWithDelay = (shouldDelay?: boolean) => void; /** * Create a function that focuses a text input. - * @param {Object} textInput the text input to focus - * @returns {Function} a function that focuses the text input with a configurable delay */ -function focusWithDelay(textInput) { +function focusWithDelay(textInput: TextInput | null): FocusWithDelay { /** * Focus the text input - * @param {Boolean} [shouldDelay=false] Impose delay before focusing the text input + * @param [shouldDelay] Impose delay before focusing the text input */ return (shouldDelay = false) => { // There could be other animations running while we trigger manual focus. @@ -18,6 +17,7 @@ function focusWithDelay(textInput) { if (!textInput) { return; } + if (!shouldDelay) { textInput.focus(); return;