Skip to content

Commit 286ead3

Browse files
committed
memoize ripple color and default ripple color
1 parent 4e8dce8 commit 286ead3

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/components/Pressable/Pressable.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,6 @@ export default function Pressable(props: PressableProps) {
366366

367367
const gesture = Gesture.Simultaneous(...gestures);
368368

369-
const defaultRippleColor = android_ripple ? undefined : 'transparent';
370-
371369
// `cursor: 'pointer'` on `RNButton` crashes iOS
372370
const pointerStyle: StyleProp<ViewStyle> =
373371
Platform.OS === 'web' ? { cursor: 'pointer' } : {};
@@ -380,10 +378,17 @@ export default function Pressable(props: PressableProps) {
380378
? children({ pressed: pressedState })
381379
: children;
382380

383-
const unprocessedRippleColor = android_ripple?.color ?? defaultRippleColor;
384-
const rippleColor = isFabric()
385-
? unprocessedRippleColor
386-
: processColor(unprocessedRippleColor);
381+
const defaultRippleColor = useMemo(
382+
() => (android_ripple ? undefined : 'transparent'),
383+
[android_ripple]
384+
);
385+
386+
const rippleColor = useMemo(() => {
387+
const unprocessedRippleColor = android_ripple?.color ?? defaultRippleColor;
388+
return isFabric()
389+
? unprocessedRippleColor
390+
: processColor(unprocessedRippleColor);
391+
}, [android_ripple?.color, defaultRippleColor]);
387392

388393
return (
389394
<GestureDetector gesture={gesture}>

0 commit comments

Comments
 (0)