From 875d7e809396db81b171ac1014cf31998f03d337 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Wed, 13 Sep 2023 10:54:54 +0200 Subject: [PATCH 1/5] ref: migrate focusWithDelay into Typescript --- src/libs/{focusWithDelay.js => focusWithDelay.ts} | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) rename src/libs/{focusWithDelay.js => focusWithDelay.ts} (82%) diff --git a/src/libs/focusWithDelay.js b/src/libs/focusWithDelay.ts similarity index 82% rename from src/libs/focusWithDelay.js rename to src/libs/focusWithDelay.ts index 367cc2b92f9f..26fb3c3c5506 100644 --- a/src/libs/focusWithDelay.js +++ b/src/libs/focusWithDelay.ts @@ -1,4 +1,4 @@ -import {InteractionManager} from 'react-native'; +import {InteractionManager, TextInput} from 'react-native'; import ComposerFocusManager from './ComposerFocusManager'; /** @@ -6,10 +6,10 @@ import ComposerFocusManager from './ComposerFocusManager'; * @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): (shouldDelay?: boolean) => void { /** * Focus the text input - * @param {Boolean} [shouldDelay=false] Impose delay before focusing the text input + * Impose delay before focusing the text input */ return (shouldDelay = false) => { // There could be other animations running while we trigger manual focus. @@ -18,6 +18,7 @@ function focusWithDelay(textInput) { if (!textInput) { return; } + if (!shouldDelay) { textInput.focus(); return; From 0c03dbb1f4468d1aa4e0aff89f4215b0d8cfebfe Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Wed, 13 Sep 2023 11:23:00 +0200 Subject: [PATCH 2/5] fix: removed JSDoc params --- src/libs/focusWithDelay.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/focusWithDelay.ts b/src/libs/focusWithDelay.ts index 26fb3c3c5506..ff7cbb5b7449 100644 --- a/src/libs/focusWithDelay.ts +++ b/src/libs/focusWithDelay.ts @@ -3,8 +3,6 @@ import ComposerFocusManager from './ComposerFocusManager'; /** * 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: TextInput | null): (shouldDelay?: boolean) => void { /** From 7cc0bb1144f57d815bb837c3fbd435f521706a0a Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Wed, 13 Sep 2023 12:45:15 +0200 Subject: [PATCH 3/5] ref: extract return type --- src/libs/focusWithDelay.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/focusWithDelay.ts b/src/libs/focusWithDelay.ts index ff7cbb5b7449..df01818b9d64 100644 --- a/src/libs/focusWithDelay.ts +++ b/src/libs/focusWithDelay.ts @@ -1,10 +1,11 @@ import {InteractionManager, TextInput} from 'react-native'; import ComposerFocusManager from './ComposerFocusManager'; +type FocusWithDelayReturn = (shouldDelay?: boolean) => void; /** * Create a function that focuses a text input. */ -function focusWithDelay(textInput: TextInput | null): (shouldDelay?: boolean) => void { +function focusWithDelay(textInput: TextInput | null): FocusWithDelayReturn { /** * Focus the text input * Impose delay before focusing the text input From a5c44fbad98c89e2f4cd3ea97acd58b15865a235 Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Thu, 14 Sep 2023 12:15:10 +0200 Subject: [PATCH 4/5] ref: resolve comment --- src/libs/focusWithDelay.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/focusWithDelay.ts b/src/libs/focusWithDelay.ts index df01818b9d64..8a30ade23303 100644 --- a/src/libs/focusWithDelay.ts +++ b/src/libs/focusWithDelay.ts @@ -1,11 +1,11 @@ import {InteractionManager, TextInput} from 'react-native'; import ComposerFocusManager from './ComposerFocusManager'; -type FocusWithDelayReturn = (shouldDelay?: boolean) => void; +type FocusWithDelay = (shouldDelay?: boolean) => void; /** * Create a function that focuses a text input. */ -function focusWithDelay(textInput: TextInput | null): FocusWithDelayReturn { +function focusWithDelay(textInput: TextInput | null): FocusWithDelay { /** * Focus the text input * Impose delay before focusing the text input From 3789cc36ed4c96ea4e94bf1552d87cc19b66beeb Mon Sep 17 00:00:00 2001 From: Jakub Butkiewicz Date: Mon, 18 Sep 2023 15:42:47 +0200 Subject: [PATCH 5/5] ref: resolve comment from review --- src/libs/focusWithDelay.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/focusWithDelay.ts b/src/libs/focusWithDelay.ts index 8a30ade23303..00d0e915879e 100644 --- a/src/libs/focusWithDelay.ts +++ b/src/libs/focusWithDelay.ts @@ -8,7 +8,7 @@ type FocusWithDelay = (shouldDelay?: boolean) => void; function focusWithDelay(textInput: TextInput | null): FocusWithDelay { /** * Focus the text input - * 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.