Skip to content

Commit 44ec762

Browse files
vonovakfacebook-github-bot
authored andcommitted
fix: ripple should be applied even when borderless == false (#28526)
Summary: With current master, when you render `<Pressable android_ripple={{borderless: false}}>`, there is no ripple effect at all. I think the expected behavior is to have ripple with default color and radius, just not borderless. This was how it was done (by me) in https://github.com/facebook/react-native/pull/28156/files but in the import process, the implementation was changed: bd38686 so either this PR is a fix or you can just close it (but I'd be curious why). ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [fixed] - ripple should be applied even when borderless == false Pull Request resolved: #28526 Test Plan: `<Pressable android_ripple={{borderless: false}}>` on master ![SVID_20200404_123614_1](https://user-images.githubusercontent.com/1566403/78424971-6b315a80-7671-11ea-8be4-5fea428bc556.gif) `<Pressable android_ripple={{borderless: false}}>` in this PR ![SVID_20200404_122754_1](https://user-images.githubusercontent.com/1566403/78424986-8bf9b000-7671-11ea-9804-37cd58dbb61e.gif) Differential Revision: D20952026 Pulled By: TheSavior fbshipit-source-id: df2b95fc6f20d7e958e91805b1a928c4f85904f1
1 parent dff17ef commit 44ec762

File tree

3 files changed

+39
-31
lines changed

3 files changed

+39
-31
lines changed

Libraries/Components/Pressable/Pressable.js

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import type {
2424
} from '../View/ViewAccessibility';
2525
import usePressability from '../../Pressability/usePressability';
2626
import {normalizeRect, type RectOrSize} from '../../StyleSheet/Rect';
27-
import type {ColorValue} from '../../StyleSheet/StyleSheetTypes';
2827
import type {LayoutEvent, PressEvent} from '../../Types/CoreEventTypes';
2928
import View from '../View/View';
3029

Libraries/Components/Pressable/useAndroidRippleForView.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ type NativeBackgroundProp = $ReadOnly<{|
2626
|}>;
2727

2828
export type RippleConfig = {|
29-
color?: ?ColorValue,
30-
borderless?: ?boolean,
31-
radius?: ?number,
29+
color?: ColorValue,
30+
borderless?: boolean,
31+
radius?: number,
3232
|};
3333

3434
/**
@@ -47,13 +47,12 @@ export default function useAndroidRippleForView(
4747
|}>,
4848
|}> {
4949
const {color, borderless, radius} = rippleConfig ?? {};
50-
const normalizedBorderless = borderless === true;
5150

5251
return useMemo(() => {
5352
if (
5453
Platform.OS === 'android' &&
5554
Platform.Version >= 21 &&
56-
(color != null || normalizedBorderless || radius != null)
55+
(color != null || borderless != null || radius != null)
5756
) {
5857
const processedColor = processColor(color);
5958
invariant(
@@ -67,7 +66,7 @@ export default function useAndroidRippleForView(
6766
nativeBackgroundAndroid: {
6867
type: 'RippleAndroid',
6968
color: processedColor,
70-
borderless: normalizedBorderless,
69+
borderless: borderless === true,
7170
rippleRadius: radius,
7271
},
7372
},
@@ -101,5 +100,5 @@ export default function useAndroidRippleForView(
101100
};
102101
}
103102
return null;
104-
}, [color, normalizedBorderless, radius, viewRef]);
103+
}, [color, borderless, radius, viewRef]);
105104
}

RNTester/js/examples/Pressable/PressableExample.js

+33-23
Original file line numberDiff line numberDiff line change
@@ -378,40 +378,50 @@ exports.examples = [
378378
},
379379
{
380380
title: 'Pressable with custom Ripple',
381-
description: ("Pressable can specify ripple's radius and borderless params": string),
381+
description: ("Pressable can specify ripple's radius, color and borderless params": string),
382382
platform: 'android',
383383
render: function(): React.Node {
384384
const nativeFeedbackButton = {
385385
textAlign: 'center',
386386
margin: 10,
387387
};
388388
return (
389-
<View
390-
style={[
391-
styles.row,
392-
{justifyContent: 'space-around', alignItems: 'center'},
393-
]}>
394-
<Pressable
395-
android_ripple={{color: 'orange', borderless: true, radius: 30}}>
396-
<View>
397-
<Text style={[styles.button, nativeFeedbackButton]}>
398-
radius 30
399-
</Text>
400-
</View>
401-
</Pressable>
389+
<View>
390+
<View
391+
style={[
392+
styles.row,
393+
{justifyContent: 'space-around', alignItems: 'center'},
394+
]}>
395+
<Pressable
396+
android_ripple={{color: 'orange', borderless: true, radius: 30}}>
397+
<View>
398+
<Text style={[styles.button, nativeFeedbackButton]}>
399+
radius 30
400+
</Text>
401+
</View>
402+
</Pressable>
402403

403-
<Pressable android_ripple={{borderless: true, radius: 150}}>
404-
<View>
405-
<Text style={[styles.button, nativeFeedbackButton]}>
406-
radius 150
407-
</Text>
408-
</View>
409-
</Pressable>
404+
<Pressable android_ripple={{borderless: true, radius: 150}}>
405+
<View>
406+
<Text style={[styles.button, nativeFeedbackButton]}>
407+
radius 150
408+
</Text>
409+
</View>
410+
</Pressable>
411+
412+
<Pressable android_ripple={{borderless: false, radius: 70}}>
413+
<View style={styles.block}>
414+
<Text style={[styles.button, nativeFeedbackButton]}>
415+
radius 70, with border
416+
</Text>
417+
</View>
418+
</Pressable>
419+
</View>
410420

411-
<Pressable android_ripple={{borderless: false, radius: 70}}>
421+
<Pressable android_ripple={{borderless: false}}>
412422
<View style={styles.block}>
413423
<Text style={[styles.button, nativeFeedbackButton]}>
414-
radius 70, with border
424+
with border, default color and radius
415425
</Text>
416426
</View>
417427
</Pressable>

0 commit comments

Comments
 (0)