Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow custom ripple radius on TouchableNativeFeedback #28009

Closed
wants to merge 5 commits into from

Conversation

vonovak
Copy link
Contributor

@vonovak vonovak commented Feb 9, 2020

Summary

motivation: there are cases where one'd like to control the radius of the ripple effect that's present on TouchableNativeFeedback - in my case, I want to make sure that both icons and text have the same ripple appearance, but that's currently not possible as far as I can tell.

Currently (afaik) the only way to set (upper) ripple limits is by specifying width, height and border radius ( + overflow: hidden), and this works well for icons which can usually be bounded by a square, but not for text which can have rectangular shape.

This PR adds rippleRadius parameter to SelectableBackground(), SelectableBackgroundBorderless() and Ripple() static functions present on TouchableNativeFeedback. It can make the ripple smaller but also larger. The result looks like this:

added to RNTester:

SVID_20200219_182027_1

difference from the other ripples:

SVID_20200209_110918_1

I'm ofc open to changing the api if needed, but I'm not sure there's much space for manoeuvring. While I was at it, I did a slight refactor of the class into several smaller, more focused methods.

It's possible that in some cases, this might help to work around this issue #6480.

Changelog

[Android] [Added] - allow setting custom ripple radius on TouchableNativeFeedback

Test Plan

I tested this locally using RNTester

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 9, 2020
@vonovak vonovak changed the title allow setting custom ripple radius allow custom ripple radius on TouchableNativeFeedback Feb 9, 2020
@react-native-bot react-native-bot added Platform: Android Android applications. Type: Enhancement A new feature or enhancement of an existing feature. labels Feb 9, 2020
Copy link
Contributor

@dulmandakh dulmandakh left a comment

Choose a reason for hiding this comment

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

LGTM

@mdvacca
Copy link
Contributor

mdvacca commented Feb 14, 2020

CC @TheSavior

@elicwhite
Copy link
Member

The ripples that go inwards instead of outwards seem weird to me, is that intended?

Also, can you add examples to RNTester that demonstrate this behavior?

@vonovak
Copy link
Contributor Author

vonovak commented Feb 14, 2020

@TheSavior regarding the ripple going inwards - that indeed surprised me too, but that seems to be the way it works by default in android and I didn't find a way to change that docs.

If you look at the gif, you'll see that the ripple effect on the second to last touchable already starts pretty big, because the touchable is large and the ripple is borderless. In the last item, it also starts pretty large and only then it "goes toward" the specified radius, which in that case means making the ripple smaller.

I'm guessing that the underlying implementation determines the size that ripple has upon touch (which is given by the size of the target, ignoring the radius), and then it drives the ripple toward the set radius. It does not care if that means making the ripple smaller or bigger ¯_(ツ)_/¯.

I've added 3 examples to RNTester

@analysis-bot
Copy link

RNTester (Android/hermes/arm64-v8a): 3289088 bytes
RNTester (Android/hermes/armeabi-v7a): 3129344 bytes
RNTester (Android/hermes/x86): 3461120 bytes
RNTester (Android/hermes/x86_64): 3424256 bytes
RNTester (Android/jsc/arm64-v8a): 4446208 bytes
RNTester (Android/jsc/armeabi-v7a): 4268032 bytes
RNTester (Android/jsc/x86): 4358144 bytes
RNTester (Android/jsc/x86_64): 4644864 bytes

@analysis-bot
Copy link

RNTester.app (iOS): 10657792 bytes

@elicwhite
Copy link
Member

Thanks! Can you update your PR summary with a video of the new RNTester example? That way we can look back at this PR to remember how it was supposed to work when it is refactored in the future. :)

@vonovak
Copy link
Contributor Author

vonovak commented Feb 19, 2020

@TheSavior added the RNTester gif to the description

@analysis-bot
Copy link

RNTester (Android/hermes/arm64-v8a): 3291136 bytes
RNTester (Android/hermes/armeabi-v7a): 3129344 bytes
RNTester (Android/hermes/x86): 3461120 bytes
RNTester (Android/hermes/x86_64): 3424256 bytes
RNTester (Android/jsc/arm64-v8a): 4446208 bytes
RNTester (Android/jsc/armeabi-v7a): 4268032 bytes
RNTester (Android/jsc/x86): 4358144 bytes
RNTester (Android/jsc/x86_64): 4644864 bytes

@analysis-bot
Copy link

RNTester.app (iOS): 10657792 bytes

@elicwhite
Copy link
Member

Thanks! The JS changes seem fine. I defer the review to @mdvacca for the Android changes

Copy link
Contributor

@mdvacca mdvacca left a comment

Choose a reason for hiding this comment

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

@vonovak thanks for working on this, aI added a couple of minor comments

@analysis-bot
Copy link

RNTester (Android/hermes/arm64-v8a): 3289088 bytes
RNTester (Android/hermes/armeabi-v7a): 3129344 bytes
RNTester (Android/hermes/x86): 3461120 bytes
RNTester (Android/hermes/x86_64): 3424256 bytes
RNTester (Android/jsc/arm64-v8a): 4446208 bytes
RNTester (Android/jsc/armeabi-v7a): 4268032 bytes
RNTester (Android/jsc/x86): 4358144 bytes
RNTester (Android/jsc/x86_64): 4644864 bytes

@analysis-bot
Copy link

RNTester.app (iOS): 10657792 bytes

Copy link
Contributor

@mdvacca mdvacca left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@mdvacca has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @vonovak in 7f2a79f.

When will my fix make it into a release? | Upcoming Releases

@react-native-bot react-native-bot added the Merged This PR has been merged. label Feb 20, 2020
@elicwhite
Copy link
Member

Hey @vonovak! We just landed a new Pressable component that has very similar code to TouchableNativeFeedback. We didn’t make this same change to it before landing it, would you be willing to make that change? 3212f7d

@vonovak
Copy link
Contributor Author

vonovak commented Feb 21, 2020

@TheSavior sure thing!

@vonovak vonovak deleted the enableCustomRippleRadius branch February 21, 2020 08:32
osdnk pushed a commit to osdnk/react-native that referenced this pull request Mar 9, 2020
Summary:
motivation: there are cases where one'd like to control the radius of the ripple effect that's present on TouchableNativeFeedback  - in my case, I want to make sure that both icons and text have the same ripple appearance, but that's currently not possible as far as I can tell.

Currently (afaik) the only way to set  (upper) ripple limits is by specifying width, height and border radius ( + `overflow: hidden`), and this works well for icons which can usually be bounded by a square, but not for text which can have rectangular shape.

This PR adds `rippleRadius` parameter to `SelectableBackground()`, `SelectableBackgroundBorderless()` and `Ripple()` static functions present on `TouchableNativeFeedback`. It can make the ripple smaller but also larger. The result looks like this:

added to RNTester:

![SVID_20200219_182027_1](https://user-images.githubusercontent.com/1566403/74858131-147ff380-5345-11ea-8a9e-2730b79eec38.gif)

difference from the other ripples:

![SVID_20200209_110918_1](https://user-images.githubusercontent.com/1566403/74109152-4513a080-4b81-11ea-8ec3-bb5862c57244.gif)

I'm ofc open to changing the api if needed, but I'm not sure there's much space for manoeuvring. While I was at it, I did a slight refactor of the class into several smaller, more focused methods.

It's possible that in some cases, this might help to work around this issue facebook#6480.

## Changelog

[Android] [Added] - allow setting custom ripple radius on TouchableNativeFeedback
Pull Request resolved: facebook#28009

Test Plan: I tested this locally using RNTester

Reviewed By: TheSavior

Differential Revision: D20004509

Pulled By: mdvacca

fbshipit-source-id: 10de1754d54c17878f36a3859705c1188f15c2a2
facebook-github-bot pushed a commit that referenced this pull request Apr 4, 2020
Summary:
Motivation is to support ripple radius just like in TouchableNativeFeedback, plus borderless attribute. See #28009 (comment)

In the current form this means user needs to pass an `android_ripple` prop which is an object of this shape:
```
export type RippleConfig = {|
  color?: ?ColorValue,
  borderless?: ?boolean,
  radius?: ?number,
|};
```
Do we want to add methods that would create such config objects - https://facebook.github.io/react-native/docs/touchablenativefeedback#methods ?

## Changelog

[Android] [Added] - support borderless and custom ripple radius on Pressable
Pull Request resolved: #28156

Test Plan:
Tested locally in RNTester. I noticed that when some content is rendered after the touchables, the ripple effect is "cut off" by the boundaries of the next view. This is not specific to Pressable, it happens to TouchableNativeFeedback too but I just didn't notice it before in #28009. As it is an issue of its own, I didn't investigate that.

![pressable](https://user-images.githubusercontent.com/1566403/75098762-785f2200-55ba-11ea-8842-e648317610e3.gif)

I changed the Touchable example slightly too (I just moved the "custom ripple radius" up to show the "cutting off" issue), so just for completeness:

![touchable](https://user-images.githubusercontent.com/1566403/75098763-81e88a00-55ba-11ea-9528-e0343d1e054b.gif)

Reviewed By: yungsters

Differential Revision: D20071021

Pulled By: TheSavior

fbshipit-source-id: cb553030934205a52dd50a2a8c8a20da6100e23f
sasurau4 pushed a commit to sasurau4/react-native that referenced this pull request Apr 15, 2020
Summary:
Motivation is to support ripple radius just like in TouchableNativeFeedback, plus borderless attribute. See facebook#28009 (comment)

In the current form this means user needs to pass an `android_ripple` prop which is an object of this shape:
```
export type RippleConfig = {|
  color?: ?ColorValue,
  borderless?: ?boolean,
  radius?: ?number,
|};
```
Do we want to add methods that would create such config objects - https://facebook.github.io/react-native/docs/touchablenativefeedback#methods ?

## Changelog

[Android] [Added] - support borderless and custom ripple radius on Pressable
Pull Request resolved: facebook#28156

Test Plan:
Tested locally in RNTester. I noticed that when some content is rendered after the touchables, the ripple effect is "cut off" by the boundaries of the next view. This is not specific to Pressable, it happens to TouchableNativeFeedback too but I just didn't notice it before in facebook#28009. As it is an issue of its own, I didn't investigate that.

![pressable](https://user-images.githubusercontent.com/1566403/75098762-785f2200-55ba-11ea-8842-e648317610e3.gif)

I changed the Touchable example slightly too (I just moved the "custom ripple radius" up to show the "cutting off" issue), so just for completeness:

![touchable](https://user-images.githubusercontent.com/1566403/75098763-81e88a00-55ba-11ea-9528-e0343d1e054b.gif)

Reviewed By: yungsters

Differential Revision: D20071021

Pulled By: TheSavior

fbshipit-source-id: cb553030934205a52dd50a2a8c8a20da6100e23f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Platform: Android Android applications. Type: Enhancement A new feature or enhancement of an existing feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants