-
Notifications
You must be signed in to change notification settings - Fork 3k
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 Hoverable #30339
Merged
AndrewGable
merged 11 commits into
Expensify:main
from
software-mansion-labs:ts-migration/Hoverable
Nov 13, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d2fcb5e
Migrate to Typescript
MaciejSWM 019919a
Fix TS ref.current is not assignable
MaciejSWM 5287856
Remove due to Property 'displayName' does not exist
MaciejSWM 21c123a
Implement eslint suggestions
MaciejSWM 07f9ee5
Merge branch 'main' into ts-migration/Hoverable
MaciejSWM 8432cd4
Reorder imports; use lodash
MaciejSWM 8a4b106
Migrate to Typescript
MaciejSWM cc222e7
Better typing - removes 'as'
MaciejSWM edc3ba6
Define component as function, not function expression
MaciejSWM f60aae1
Better types of assignRef
MaciejSWM a3c156f
Drop unnecessary 'as' casting
MaciejSWM 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 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,17 @@ | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import HoverableProps from './types'; | ||
|
||
/** | ||
* On mobile, there is no concept of hovering, so we return a plain wrapper around the component's children, | ||
* where the hover state is always false. | ||
*/ | ||
function Hoverable({children}: HoverableProps) { | ||
const childrenWithHoverState = typeof children === 'function' ? children(false) : children; | ||
|
||
return <View>{childrenWithHoverState}</View>; | ||
} | ||
|
||
Hoverable.displayName = 'Hoverable'; | ||
|
||
export default Hoverable; |
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
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,26 @@ | ||
import {ReactElement} from 'react'; | ||
|
||
type HoverableProps = { | ||
/** Children to wrap with Hoverable. */ | ||
children: ((isHovered: boolean) => ReactElement) | ReactElement; | ||
|
||
/** Whether to disable the hover action */ | ||
disabled?: boolean; | ||
|
||
/** Function that executes when the mouse moves over the children. */ | ||
onHoverIn?: () => void; | ||
|
||
/** Function that executes when the mouse leaves the children. */ | ||
onHoverOut?: () => void; | ||
|
||
/** Direct pass-through of React's onMouseEnter event. */ | ||
onMouseEnter?: (event: MouseEvent) => void; | ||
|
||
/** Direct pass-through of React's onMouseLeave event. */ | ||
onMouseLeave?: (event: MouseEvent) => void; | ||
|
||
/** Decides whether to handle the scroll behaviour to show hover once the scroll ends */ | ||
shouldHandleScroll?: boolean; | ||
}; | ||
|
||
export default HoverableProps; |
Oops, something went wrong.
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.
This was overlooked.
if (_.has(ref, 'current')) {
is equivalent to:Fixing here: #31306