diff --git a/Libraries/Components/Pressable/useAndroidRippleForView.js b/Libraries/Components/Pressable/useAndroidRippleForView.js index be31c5a2e91b49..6ecf6e280ca400 100644 --- a/Libraries/Components/Pressable/useAndroidRippleForView.js +++ b/Libraries/Components/Pressable/useAndroidRippleForView.js @@ -27,6 +27,7 @@ export type RippleConfig = {| color?: ColorValue, borderless?: boolean, radius?: number, + foreground?: boolean, |}; /** @@ -40,11 +41,11 @@ export default function useAndroidRippleForView( onPressIn: (event: PressEvent) => void, onPressMove: (event: PressEvent) => void, onPressOut: (event: PressEvent) => void, - viewProps: $ReadOnly<{| - nativeBackgroundAndroid: NativeBackgroundProp, - |}>, + viewProps: + | $ReadOnly<{|nativeBackgroundAndroid: NativeBackgroundProp|}> + | $ReadOnly<{|nativeForegroundAndroid: NativeBackgroundProp|}>, |}> { - const {color, borderless, radius} = rippleConfig ?? {}; + const {color, borderless, radius, foreground} = rippleConfig ?? {}; return useMemo(() => { if ( @@ -58,16 +59,18 @@ export default function useAndroidRippleForView( 'Unexpected color given for Ripple color', ); + const nativeRippleValue = { + 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 + ? {nativeForegroundAndroid: nativeRippleValue} + : {nativeBackgroundAndroid: nativeRippleValue}, onPressIn(event: PressEvent): void { const view = viewRef.current; if (view != null) { @@ -98,5 +101,5 @@ export default function useAndroidRippleForView( }; } return null; - }, [color, borderless, radius, viewRef]); + }, [borderless, color, foreground, radius, viewRef]); } diff --git a/packages/rn-tester/js/examples/Pressable/PressableExample.js b/packages/rn-tester/js/examples/Pressable/PressableExample.js index 3407d7afdcd3ec..7b1bdf1fca5e46 100644 --- a/packages/rn-tester/js/examples/Pressable/PressableExample.js +++ b/packages/rn-tester/js/examples/Pressable/PressableExample.js @@ -11,6 +11,7 @@ import * as React from 'react'; import { Animated, + Image, Pressable, StyleSheet, Text, @@ -310,6 +311,10 @@ const styles = StyleSheet.create({ fontWeight: '500', color: 'blue', }, + image: { + height: 100, + width: 100, + }, }); exports.displayName = (undefined: ?string); @@ -425,6 +430,22 @@ exports.examples = [ + + + + + + use foreground + ); },