Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/components/GestureButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
BorderlessButtonWithRefProps,
BorderlessButtonProps,
} from './GestureButtonsProps';
import { isFabric } from '../utils';

export const RawButton = createNativeWrapper(GestureHandlerButton, {
shouldCancelWhenOutside: false,
Expand Down Expand Up @@ -122,10 +123,14 @@ class InnerBaseButton extends React.Component<BaseButtonWithRefProps> {
render() {
const { rippleColor, style, ...rest } = this.props;

const processedRippleColor = isFabric()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about maybeProcessedRippleColor?

Copy link
Contributor

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 isFabric instead of calling this everytime?

Copy link
Member Author

@latekvo latekvo Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about maybeProcessedRippleColor?

Not a big fan of that name, the word processed already allows for lack of change.
But I agree that processed may be confusing due to processColor() function.
Maybe this will do better:
rippleColor -> unprocessedRippleColor
processedRippleColor -> rippleColor
?

Also, why don't we memoize value of isFabric instead of calling this everytime?

Sure, done in ff48533

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, done in ff48533

Not exactly what I meant. I thought about storing it in a variable. Now we still call function in each render.

Maybe this will do better:
rippleColor -> unprocessedRippleColor
processedRippleColor -> rippleColor

Looks good 👍

Copy link
Member Author

@latekvo latekvo Feb 3, 2025

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.

Done for BaseButton in d62793c

Changed useCallback to useMemo in 2ff4683

If you're referring to storing IS_FABRIC outside of the Pressable, 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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

Done in 2513b9e

? rippleColor
: processColor(rippleColor ?? undefined);

return (
<RawButton
ref={this.props.innerRef}
rippleColor={processColor(rippleColor)}
rippleColor={processedRippleColor}
style={[style, Platform.OS === 'ios' && { cursor: undefined }]}
{...rest}
onGestureEvent={this.onGestureEvent}
Expand Down
9 changes: 7 additions & 2 deletions src/components/GestureButtonsProps.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import * as React from 'react';
import { AccessibilityProps, StyleProp, ViewStyle } from 'react-native';
import {
AccessibilityProps,
ColorValue,
StyleProp,
ViewStyle,
} from 'react-native';
import type { NativeViewGestureHandlerProps } from '../handlers/NativeViewGestureHandler';

export interface RawButtonProps
Expand All @@ -16,7 +21,7 @@ export interface RawButtonProps
*
* Defines color of native ripple animation used since API level 21.
*/
rippleColor?: any; // it was present in BaseButtonProps before but is used here in code
rippleColor?: number | ColorValue | null;

/**
* Android only.
Expand Down
18 changes: 14 additions & 4 deletions src/components/Pressable/Pressable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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' } : {};
Expand All @@ -380,6 +378,18 @@ export default function Pressable(props: PressableProps) {
? children({ pressed: pressedState })
: children;

const defaultRippleColor = useMemo(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both memo can be merged into only 1 ..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, fixed in a9d2031

() => (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
Expand All @@ -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}
Expand Down
Loading