-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix android ripple color bug on fabric #3369
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
389ec11
fix ripple color on Pressable
latekvo 3e9ac80
remove duplicate function
latekvo d42cefd
add fabric checking to base button
latekvo d461b40
add proper typing to RawButton
latekvo f7d895d
adjust name
latekvo 4e8dce8
remove unnecessary lint ignore
latekvo 286ead3
memoize ripple color and default ripple color
latekvo a9d2031
merge both useMemo
latekvo 1224637
Merge branch 'main' into @latekvo/fix-ripple-color-bug-on-fabric
latekvo ff48533
memo isFabric
latekvo 2513b9e
fix working in `BaseButton`
latekvo 2ff4683
change function to value
latekvo d62793c
add fabric value caching to BaseButton
latekvo 15e1841
Merge branch 'main' into @latekvo/fix-ripple-color-bug-on-fabric
latekvo f8b2de5
simplify IS_FABRIC logic in Pressable
latekvo 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 contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ import { | |
| } from './utils'; | ||
| import { PressabilityDebugView } from '../../handlers/PressabilityDebugView'; | ||
| import { GestureTouchEvent } from '../../handlers/gestureHandlerCommon'; | ||
| import { INT32_MAX } from '../../utils'; | ||
| import { INT32_MAX, isFabric } from '../../utils'; | ||
|
|
||
| const DEFAULT_LONG_PRESS_DURATION = 500; | ||
|
|
||
|
|
@@ -366,8 +366,6 @@ export default function Pressable(props: PressableProps) { | |
|
|
||
| const gesture = Gesture.Simultaneous(...gestures); | ||
|
|
||
| const defaultRippleColor = android_ripple ? undefined : 'transparent'; | ||
|
|
||
| // `cursor: 'pointer'` on `RNButton` crashes iOS | ||
| const pointerStyle: StyleProp<ViewStyle> = | ||
| Platform.OS === 'web' ? { cursor: 'pointer' } : {}; | ||
|
|
@@ -380,6 +378,18 @@ export default function Pressable(props: PressableProps) { | |
| ? children({ pressed: pressedState }) | ||
| : children; | ||
|
|
||
| const defaultRippleColor = useMemo( | ||
|
||
| () => (android_ripple ? undefined : 'transparent'), | ||
| [android_ripple] | ||
| ); | ||
|
|
||
| const rippleColor = useMemo(() => { | ||
| const unprocessedRippleColor = android_ripple?.color ?? defaultRippleColor; | ||
| return isFabric() | ||
| ? unprocessedRippleColor | ||
| : processColor(unprocessedRippleColor); | ||
| }, [android_ripple?.color, defaultRippleColor]); | ||
|
|
||
| return ( | ||
| <GestureDetector gesture={gesture}> | ||
| <NativeButton | ||
|
|
@@ -388,7 +398,7 @@ export default function Pressable(props: PressableProps) { | |
| hitSlop={appliedHitSlop} | ||
| enabled={isPressableEnabled} | ||
| touchSoundDisabled={android_disableSound ?? undefined} | ||
| rippleColor={processColor(android_ripple?.color ?? defaultRippleColor)} | ||
| rippleColor={rippleColor} | ||
| rippleRadius={android_ripple?.radius ?? undefined} | ||
| style={[pointerStyle, styleProp]}> | ||
| {childrenProp} | ||
|
|
||
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.
What about
maybeProcessedRippleColor?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.
Also, why don't we memoize value of
isFabricinstead of calling this everytime?Uh oh!
There was an error while loading. Please reload this page.
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.
Not a big fan of that name, the word
processedalready allows for lack of change.But I agree that
processedmay be confusing due toprocessColor()function.Maybe this will do better:
rippleColor->unprocessedRippleColorprocessedRippleColor->rippleColor?
Sure, done in ff48533
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.
Not exactly what I meant. I thought about storing it in a variable. Now we still call function in each render.
Looks good 👍
Uh oh!
There was an error while loading. Please reload this page.
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.
Done for
BaseButtonin d62793cChanged
useCallbacktouseMemoin 2ff4683If you're referring to storing
IS_FABRICoutside of thePressable, we can't do that,isFabric()will return incorrect data outside of the function component, as the value it reads will not be initialised before the first render.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.
Done in 2513b9e