Skip to content

Commit

Permalink
fix: ripple should be applied when borderless == false
Browse files Browse the repository at this point in the history
  • Loading branch information
vonovak committed Apr 4, 2020
1 parent caa7829 commit 33d16d0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
7 changes: 3 additions & 4 deletions Libraries/Components/Pressable/useAndroidRippleForView.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ export default function useAndroidRippleForView(
|}>,
|}> {
const {color, borderless, radius} = rippleConfig ?? {};
const normalizedBorderless = borderless === true;

return useMemo(() => {
if (
Platform.OS === 'android' &&
Platform.Version >= 21 &&
(color != null || normalizedBorderless || radius != null)
(color != null || borderless != null || radius != null)
) {
const processedColor = processColor(color);
invariant(
Expand All @@ -67,7 +66,7 @@ export default function useAndroidRippleForView(
nativeBackgroundAndroid: {
type: 'RippleAndroid',
color: processedColor,
borderless: normalizedBorderless,
borderless: borderless === true,
rippleRadius: radius,
},
},
Expand Down Expand Up @@ -101,5 +100,5 @@ export default function useAndroidRippleForView(
};
}
return null;
}, [color, normalizedBorderless, radius, viewRef]);
}, [color, borderless, radius, viewRef]);
}
56 changes: 33 additions & 23 deletions RNTester/js/examples/Pressable/PressableExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,40 +378,50 @@ exports.examples = [
},
{
title: 'Pressable with custom Ripple',
description: ("Pressable can specify ripple's radius and borderless params": string),
description: ("Pressable can specify ripple's radius, color and borderless params": string),
platform: 'android',
render: function(): React.Node {
const nativeFeedbackButton = {
textAlign: 'center',
margin: 10,
};
return (
<View
style={[
styles.row,
{justifyContent: 'space-around', alignItems: 'center'},
]}>
<Pressable
android_ripple={{color: 'orange', borderless: true, radius: 30}}>
<View>
<Text style={[styles.button, nativeFeedbackButton]}>
radius 30
</Text>
</View>
</Pressable>
<View>
<View
style={[
styles.row,
{justifyContent: 'space-around', alignItems: 'center'},
]}>
<Pressable
android_ripple={{color: 'orange', borderless: true, radius: 30}}>
<View>
<Text style={[styles.button, nativeFeedbackButton]}>
radius 30
</Text>
</View>
</Pressable>

<Pressable android_ripple={{borderless: true, radius: 150}}>
<View>
<Text style={[styles.button, nativeFeedbackButton]}>
radius 150
</Text>
</View>
</Pressable>
<Pressable android_ripple={{borderless: true, radius: 150}}>
<View>
<Text style={[styles.button, nativeFeedbackButton]}>
radius 150
</Text>
</View>
</Pressable>

<Pressable android_ripple={{borderless: false, radius: 70}}>
<View style={styles.block}>
<Text style={[styles.button, nativeFeedbackButton]}>
radius 70, with border
</Text>
</View>
</Pressable>
</View>

<Pressable android_ripple={{borderless: false, radius: 70}}>
<Pressable android_ripple={{borderless: false}}>
<View style={styles.block}>
<Text style={[styles.button, nativeFeedbackButton]}>
radius 70, with border
with border, default color and radius
</Text>
</View>
</Pressable>
Expand Down

0 comments on commit 33d16d0

Please sign in to comment.