From d3b1cf5962e638007755ec2f60fc0715345a5602 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Tue, 5 Sep 2023 18:02:23 +0200 Subject: [PATCH 1/3] [TS migration] Migrate 'EmojiPickerAction.js' lib to TypeScript --- src/libs/actions/EmojiPickerAction.js | 62 --------------------- src/libs/actions/EmojiPickerAction.ts | 77 +++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 62 deletions(-) delete mode 100644 src/libs/actions/EmojiPickerAction.js create mode 100644 src/libs/actions/EmojiPickerAction.ts diff --git a/src/libs/actions/EmojiPickerAction.js b/src/libs/actions/EmojiPickerAction.js deleted file mode 100644 index 84621af3a5b4..000000000000 --- a/src/libs/actions/EmojiPickerAction.js +++ /dev/null @@ -1,62 +0,0 @@ -import React from 'react'; - -const emojiPickerRef = React.createRef(); - -/** - * Show the EmojiPicker modal popover. - * - * @param {Function} [onModalHide=() => {}] - Run a callback when Modal hides. - * @param {Function} [onEmojiSelected=() => {}] - Run a callback when Emoji selected. - * @param {Element} emojiPopoverAnchor - Element on which EmojiPicker is anchored - * @param {Object} [anchorOrigin] - Anchor origin for Popover - * @param {Function} [onWillShow=() => {}] - Run a callback when Popover will show - * @param {String} id - Unique id for EmojiPicker - */ -function showEmojiPicker(onModalHide = () => {}, onEmojiSelected = () => {}, emojiPopoverAnchor, anchorOrigin = undefined, onWillShow = () => {}, id) { - if (!emojiPickerRef.current) { - return; - } - - emojiPickerRef.current.showEmojiPicker(onModalHide, onEmojiSelected, emojiPopoverAnchor, anchorOrigin, onWillShow, id); -} - -/** - * Hide the Emoji Picker modal. - * - * @param {Boolean} isNavigating - */ -function hideEmojiPicker(isNavigating) { - if (!emojiPickerRef.current) { - return; - } - emojiPickerRef.current.hideEmojiPicker(isNavigating); -} - -/** - * Whether Emoji Picker is active for the given id. - * - * @param {String} id - * @return {Boolean} - */ -function isActive(id) { - if (!emojiPickerRef.current) { - return; - } - return emojiPickerRef.current.isActive(id); -} - -function isEmojiPickerVisible() { - if (!emojiPickerRef.current) { - return; - } - return emojiPickerRef.current.isEmojiPickerVisible; -} - -function resetEmojiPopoverAnchor() { - if (!emojiPickerRef.current) { - return; - } - return emojiPickerRef.current.resetEmojiPopoverAnchor(); -} - -export {emojiPickerRef, showEmojiPicker, hideEmojiPicker, isActive, isEmojiPickerVisible, resetEmojiPopoverAnchor}; diff --git a/src/libs/actions/EmojiPickerAction.ts b/src/libs/actions/EmojiPickerAction.ts new file mode 100644 index 000000000000..94716925e6b7 --- /dev/null +++ b/src/libs/actions/EmojiPickerAction.ts @@ -0,0 +1,77 @@ +import {ValueOf} from 'type-fest'; +import React from 'react'; +import {View} from 'react-native'; +import CONST from '../../CONST'; + +type AnchorOrigin = { + horizontal: ValueOf; + vertical: ValueOf; +}; + +type EmojiPicker = { + showEmojiPicker: (onModalHideValue?: () => void, onEmojiSelectedValue?: () => void, emojiPopoverAnchor?: View, anchorOrigin?: AnchorOrigin, onWillShow?: () => void, id?: string) => void; + isActive: (id: string) => boolean; + hideEmojiPicker: (isNavigating: boolean) => void; + isEmojiPickerVisible: boolean; + resetEmojiPopoverAnchor: () => void; +}; + +const emojiPickerRef = React.createRef(); + +/** + * Show the EmojiPicker modal popover. + * + * @param onModalHide - Run a callback when Modal hides. + * @param onEmojiSelected - Run a callback when Emoji selected. + * @param emojiPopoverAnchor - Element on which EmojiPicker is anchored + * @param anchorOrigin - Anchor origin for Popover + * @param onWillShow - Run a callback when Popover will show + * @param id - Unique id for EmojiPicker + */ +function showEmojiPicker(onModalHide = () => {}, onEmojiSelected = () => {}, emojiPopoverAnchor = undefined, anchorOrigin = undefined, onWillShow = () => {}, id = undefined): void { + if (!emojiPickerRef.current) { + return; + } + + emojiPickerRef.current.showEmojiPicker(onModalHide, onEmojiSelected, emojiPopoverAnchor, anchorOrigin, onWillShow, id); +} + +/** + * Hide the Emoji Picker modal. + */ +function hideEmojiPicker(isNavigating: boolean): void { + if (!emojiPickerRef.current) { + return; + } + + emojiPickerRef.current.hideEmojiPicker(isNavigating); +} + +/** + * Whether Emoji Picker is active for the given id. + */ +function isActive(id: string): boolean { + if (!emojiPickerRef.current) { + return false; + } + + return emojiPickerRef.current.isActive(id); +} + +function isEmojiPickerVisible(): boolean { + if (!emojiPickerRef.current) { + return false; + } + + return emojiPickerRef.current.isEmojiPickerVisible; +} + +function resetEmojiPopoverAnchor(): void { + if (!emojiPickerRef.current) { + return; + } + + emojiPickerRef.current.resetEmojiPopoverAnchor(); +} + +export {emojiPickerRef, showEmojiPicker, hideEmojiPicker, isActive, isEmojiPickerVisible, resetEmojiPopoverAnchor}; From 3d7c110baedd6a1faa0760361bebd64fc46ba46c Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Tue, 12 Sep 2023 13:13:23 +0200 Subject: [PATCH 2/3] Adjust after review --- src/libs/actions/EmojiPickerAction.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/EmojiPickerAction.ts b/src/libs/actions/EmojiPickerAction.ts index 94716925e6b7..98542b092d4e 100644 --- a/src/libs/actions/EmojiPickerAction.ts +++ b/src/libs/actions/EmojiPickerAction.ts @@ -8,7 +8,8 @@ type AnchorOrigin = { vertical: ValueOf; }; -type EmojiPicker = { +// TODO: Move this type to src/components/EmojiPicker/EmojiPicker.js once it is converted to TS +type EmojiPickerRef = { showEmojiPicker: (onModalHideValue?: () => void, onEmojiSelectedValue?: () => void, emojiPopoverAnchor?: View, anchorOrigin?: AnchorOrigin, onWillShow?: () => void, id?: string) => void; isActive: (id: string) => boolean; hideEmojiPicker: (isNavigating: boolean) => void; @@ -16,7 +17,7 @@ type EmojiPicker = { resetEmojiPopoverAnchor: () => void; }; -const emojiPickerRef = React.createRef(); +const emojiPickerRef = React.createRef(); /** * Show the EmojiPicker modal popover. @@ -28,7 +29,7 @@ const emojiPickerRef = React.createRef(); * @param onWillShow - Run a callback when Popover will show * @param id - Unique id for EmojiPicker */ -function showEmojiPicker(onModalHide = () => {}, onEmojiSelected = () => {}, emojiPopoverAnchor = undefined, anchorOrigin = undefined, onWillShow = () => {}, id = undefined): void { +function showEmojiPicker(onModalHide = () => {}, onEmojiSelected = () => {}, emojiPopoverAnchor = undefined, anchorOrigin = undefined, onWillShow = () => {}, id = undefined) { if (!emojiPickerRef.current) { return; } @@ -39,7 +40,7 @@ function showEmojiPicker(onModalHide = () => {}, onEmojiSelected = () => {}, emo /** * Hide the Emoji Picker modal. */ -function hideEmojiPicker(isNavigating: boolean): void { +function hideEmojiPicker(isNavigating: boolean) { if (!emojiPickerRef.current) { return; } @@ -66,7 +67,7 @@ function isEmojiPickerVisible(): boolean { return emojiPickerRef.current.isEmojiPickerVisible; } -function resetEmojiPopoverAnchor(): void { +function resetEmojiPopoverAnchor() { if (!emojiPickerRef.current) { return; } From ff8edae84fcbcb9b3f3efffe9313204fb8429742 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Mon, 18 Sep 2023 10:09:21 +0200 Subject: [PATCH 3/3] Remove void return type --- src/libs/actions/EmojiPickerAction.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/EmojiPickerAction.ts b/src/libs/actions/EmojiPickerAction.ts index ef58b9224a88..edf82eb46da3 100644 --- a/src/libs/actions/EmojiPickerAction.ts +++ b/src/libs/actions/EmojiPickerAction.ts @@ -60,7 +60,7 @@ function isActive(id: string): boolean { return emojiPickerRef.current.isActive(id); } -function clearActive(): void { +function clearActive() { if (!emojiPickerRef.current) { return; }