Skip to content
Closed
Changes from all 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
36 changes: 23 additions & 13 deletions Libraries/Components/Pressable/useAndroidRippleForView.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import invariant from 'invariant';
import {Commands} from '../View/ViewNativeComponent';
import type {ColorValue} from '../../StyleSheet/StyleSheet';
import type {PressEvent} from '../../Types/CoreEventTypes';
import {Platform, View, processColor} from 'react-native';
import {
Platform,
View,
processColor,
TouchableNativeFeedback,
} from 'react-native';
import * as React from 'react';
import {useMemo} from 'react';

Expand All @@ -27,6 +32,7 @@ export type RippleConfig = {|
color?: ColorValue,
borderless?: boolean,
radius?: number,
foreground?: boolean,
|};

/**
Expand All @@ -41,10 +47,11 @@ export default function useAndroidRippleForView(
onPressMove: (event: PressEvent) => void,
onPressOut: (event: PressEvent) => void,
viewProps: $ReadOnly<{|
nativeBackgroundAndroid: NativeBackgroundProp,
nativeBackgroundAndroid?: NativeBackgroundProp,
nativeForegroundAndroid?: NativeBackgroundProp,
|}>,
|}> {
const {color, borderless, radius} = rippleConfig ?? {};
const {color, borderless, foreground, radius} = rippleConfig ?? {};

return useMemo(() => {
if (
Expand All @@ -58,16 +65,19 @@ export default function useAndroidRippleForView(
'Unexpected color given for Ripple color',
);

const background = {
type: 'RippleAndroid',
color: processedColor,
borderless: borderless === true,
rippleRadius: radius,
};

return {
viewProps: {
// Consider supporting `nativeForegroundAndroid`
nativeBackgroundAndroid: {
type: 'RippleAndroid',
color: processedColor,
borderless: borderless === true,
rippleRadius: radius,
},
},
viewProps:
foreground === true &&
TouchableNativeFeedback.canUseNativeForeground()
? {nativeForegroundAndroid: background}
: {nativeBackgroundAndroid: background},
onPressIn(event: PressEvent): void {
const view = viewRef.current;
if (view != null) {
Expand Down Expand Up @@ -98,5 +108,5 @@ export default function useAndroidRippleForView(
};
}
return null;
}, [color, borderless, radius, viewRef]);
}, [color, borderless, foreground, radius, viewRef]);
}