From 071c458a2fe250d5f430373a3c6810165e0a5389 Mon Sep 17 00:00:00 2001 From: Jakub Kosmydel <104823336+kosmydel@users.noreply.github.com> Date: Wed, 6 Sep 2023 13:05:38 +0200 Subject: [PATCH 1/3] migrate to ts --- ....js => ReportActionComposeFocusManager.ts} | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) rename src/libs/{ReportActionComposeFocusManager.js => ReportActionComposeFocusManager.ts} (61%) diff --git a/src/libs/ReportActionComposeFocusManager.js b/src/libs/ReportActionComposeFocusManager.ts similarity index 61% rename from src/libs/ReportActionComposeFocusManager.js rename to src/libs/ReportActionComposeFocusManager.ts index 7f31b17aaa57..af103c5d2fb4 100644 --- a/src/libs/ReportActionComposeFocusManager.js +++ b/src/libs/ReportActionComposeFocusManager.ts @@ -1,20 +1,21 @@ -import _ from 'underscore'; import React from 'react'; +import {TextInput} from 'react-native'; -const composerRef = React.createRef(); +type FocusCallback = () => void; + +const composerRef = React.createRef(); // There are two types of composer: general composer (edit composer) and main composer. // The general composer callback will take priority if it exists. -let focusCallback = null; -let mainComposerFocusCallback = null; +let focusCallback: FocusCallback | null = null; +let mainComposerFocusCallback: FocusCallback | null = null; /** * Register a callback to be called when focus is requested. * Typical uses of this would be call the focus on the ReportActionComposer. * - * @param {Function} callback callback to register - * @param {Boolean} isMainComposer + * @param callback callback to register */ -function onComposerFocus(callback, isMainComposer = false) { +function onComposerFocus(callback: FocusCallback, isMainComposer = false) { if (isMainComposer) { mainComposerFocusCallback = callback; } else { @@ -24,15 +25,10 @@ function onComposerFocus(callback, isMainComposer = false) { /** * Request focus on the ReportActionComposer - * */ function focus() { - if (!_.isFunction(focusCallback)) { - if (!_.isFunction(mainComposerFocusCallback)) { - return; - } - - mainComposerFocusCallback(); + if (!focusCallback) { + mainComposerFocusCallback?.(); return; } @@ -41,8 +37,6 @@ function focus() { /** * Clear the registered focus callback - * - * @param {Boolean} isMainComposer */ function clear(isMainComposer = false) { if (isMainComposer) { @@ -54,10 +48,9 @@ function clear(isMainComposer = false) { /** * Exposes the current focus state of the report action composer. - * @return {Boolean} isFocused */ -function isFocused() { - return composerRef.current && composerRef.current.isFocused(); +function isFocused(): boolean { + return !!composerRef.current?.isFocused(); } export default { From b628d01d1c794d4b903b1c890b190f61f51fcfce Mon Sep 17 00:00:00 2001 From: Jakub Kosmydel <104823336+kosmydel@users.noreply.github.com> Date: Wed, 6 Sep 2023 16:06:01 +0200 Subject: [PATCH 2/3] fix typecheck --- src/libs/ReportActionComposeFocusManager.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportActionComposeFocusManager.ts b/src/libs/ReportActionComposeFocusManager.ts index af103c5d2fb4..32f19e66d778 100644 --- a/src/libs/ReportActionComposeFocusManager.ts +++ b/src/libs/ReportActionComposeFocusManager.ts @@ -27,8 +27,12 @@ function onComposerFocus(callback: FocusCallback, isMainComposer = false) { * Request focus on the ReportActionComposer */ function focus() { - if (!focusCallback) { - mainComposerFocusCallback?.(); + if (typeof focusCallback !== 'function') { + if (typeof mainComposerFocusCallback !== 'function'){ + return; + } + + mainComposerFocusCallback(); return; } From 428c6535e2692e275096fad0a7056fe7c993b93a Mon Sep 17 00:00:00 2001 From: Jakub Kosmydel <104823336+kosmydel@users.noreply.github.com> Date: Wed, 6 Sep 2023 16:06:27 +0200 Subject: [PATCH 3/3] prettier --- src/libs/ReportActionComposeFocusManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportActionComposeFocusManager.ts b/src/libs/ReportActionComposeFocusManager.ts index 32f19e66d778..83493ed71fc5 100644 --- a/src/libs/ReportActionComposeFocusManager.ts +++ b/src/libs/ReportActionComposeFocusManager.ts @@ -28,7 +28,7 @@ function onComposerFocus(callback: FocusCallback, isMainComposer = false) { */ function focus() { if (typeof focusCallback !== 'function') { - if (typeof mainComposerFocusCallback !== 'function'){ + if (typeof mainComposerFocusCallback !== 'function') { return; }