-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TS migration] Migrate 'EmojiPickerAction.js' lib to TypeScript #26795
Merged
hayata-suenaga
merged 5 commits into
Expensify:main
from
software-mansion-labs:ts-migration/EmojiPickerAction
Sep 28, 2023
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d3b1cf5
[TS migration] Migrate 'EmojiPickerAction.js' lib to TypeScript
blazejkustra 3d7c110
Adjust after review
blazejkustra 0ccbac1
Merge branch 'main' into ts-migration/EmojiPickerAction
blazejkustra ff8edae
Remove void return type
blazejkustra 17944fd
Merge branch 'main' into ts-migration/EmojiPickerAction
blazejkustra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<typeof CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL>; | ||
vertical: ValueOf<typeof CONST.MODAL.ANCHOR_ORIGIN_VERTICAL>; | ||
}; | ||
|
||
type EmojiPicker = { | ||
showEmojiPicker: (onModalHideValue?: () => void, onEmojiSelectedValue?: () => void, emojiPopoverAnchor?: View, anchorOrigin?: AnchorOrigin, onWillShow?: () => void, id?: string) => void; | ||
hayata-suenaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isActive: (id: string) => boolean; | ||
hideEmojiPicker: (isNavigating: boolean) => void; | ||
isEmojiPickerVisible: boolean; | ||
resetEmojiPopoverAnchor: () => void; | ||
}; | ||
|
||
const emojiPickerRef = React.createRef<EmojiPicker>(); | ||
hayata-suenaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* 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 { | ||
blazejkustra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!emojiPickerRef.current) { | ||
return; | ||
} | ||
|
||
emojiPickerRef.current.showEmojiPicker(onModalHide, onEmojiSelected, emojiPopoverAnchor, anchorOrigin, onWillShow, id); | ||
} | ||
|
||
/** | ||
* Hide the Emoji Picker modal. | ||
*/ | ||
function hideEmojiPicker(isNavigating: boolean): void { | ||
blazejkustra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 { | ||
blazejkustra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!emojiPickerRef.current) { | ||
return; | ||
} | ||
|
||
emojiPickerRef.current.resetEmojiPopoverAnchor(); | ||
} | ||
|
||
export {emojiPickerRef, showEmojiPicker, hideEmojiPicker, isActive, isEmojiPickerVisible, resetEmojiPopoverAnchor}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we defining the component type in this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not the component type, it's what is defined in
useImperativeHandle
here. Do you think the name is misleading? @hayata-suenagaThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean this is component API right? the methods exposed the component through
useImperativeHandle
?I think we should define this inside the component file instead of defining this here where we store the reference to the component.
I know we haven't started migration of component files, but I think we should start thinking about where type definitions should belong and how to coordinates the migration when the type needed are not defined yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that
EmojiPicker
type should be defined next toEmojiPicker
component. But until it's not migrated we have couple options:EmojiPicker
componentEmojiPicker
component is migrated (we can add a comment on the issue to remember about this)EmojiPicker
type next to the componentGenerally I think we won't be able to avoid such situations and sometimes we have to define types in undesirable places. At some point of the migration we will have to clean a bit, for example we'll have to clean style types or define shared types that are often used - until then we have to accept that we will repeat or litter the code sometimes.
cc @fabioh8010 @hayata-suenaga
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confortable with option two, and adding a TODO comment above the type as well:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can create some cleanup and review issues for some of the categories of files (I kinda have been done this cleanup for
styles
already) , e.g.styles
,models
,libs
,hooks
,hoc's
,components
andpages
I think are good candidates for these clean ups. After each migration of all issues of that category we will create a new issue to review all past work and ensure consistency. I can add these "checkpoints" on our spreadsheet, WDYT? @hayata-suenaga @blazejkustraThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fabioh8010 That sounds good to me 😄 Add it to the spreadsheet please, and we will get back to this.
Sure thing @hayata-suenaga, that's on me and @fabioh8010, we will coordinate such cleanups!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if issues need to be created in App 🙇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hayata-suenaga @blazejkustra I created new rows in the spreadsheet about these review issues, here are the lines:
@hayata-suenaga Could you please create the issues? Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hayata-suenaga bump