-
-
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
Changes from 8 commits
389ec11
3e9ac80
d42cefd
d461b40
f7d895d
4e8dce8
286ead3
a9d2031
1224637
ff48533
2513b9e
2ff4683
d62793c
15e1841
f8b2de5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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,14 @@ export default function Pressable(props: PressableProps) { | |
| ? children({ pressed: pressedState }) | ||
| : children; | ||
|
|
||
| const rippleColor = useMemo(() => { | ||
| const defaultRippleColor = android_ripple ? undefined : 'transparent'; | ||
| const unprocessedRippleColor = android_ripple?.color ?? defaultRippleColor; | ||
|
Comment on lines
+389
to
+390
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't it be const unprocessedRippleColor = android_ripple?.color ?? 'transparent';? I don't really see the point of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return isFabric() | ||
| ? unprocessedRippleColor | ||
| : processColor(unprocessedRippleColor); | ||
| }, [android_ripple]); | ||
|
|
||
| return ( | ||
| <GestureDetector gesture={gesture}> | ||
| <NativeButton | ||
|
|
@@ -388,7 +394,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} | ||
|
|
||
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