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

Modify TouchableNativeFeedback (Ripple) to follow borderRadius #6515

Closed
wants to merge 1 commit into from

Conversation

jeffchienzabinet
Copy link
Contributor

Using TouchableNativeFeedback has been a problem for me because the ripples it makes don't follow the child view's border radii so the ripples stick out of the child view's rounded corners. This PR should fix this problem with a minor caveat: this only works for TouchableNativeFeedback.Ripple and not TouchableNativeFeedback.SelectableBackground. I searched how I could apply corner radius to selectableItemBackground and it doesn't seem to be possible (the prevalent advice is to create the ripple manually which is equivalent to using TNF.Ripple in our case), though I could be wrong.

I added an example to UIExplorer (TouchableExample). This is my first PR to this repo so let me know if something's wrong. Cheers!

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @mkonicek, @kmagiera and @spicyj to be potential reviewers.

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

@@ -111,6 +111,17 @@ exports.examples = [
},
}];

if(Platform.OS === 'android') {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can add a platform prop to the example object instead of checking the platform manually. See the '3D Touch' example above that is ios only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha, updated.

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@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 Mar 18, 2016
@facebook-github-bot
Copy link
Contributor

@jeffchienzabinet updated the pull request.

@mkonicek
Copy link
Contributor

Thanks for the PR! Is there a way to do this only by changing implementation of TouchableNativeFeedback and not react/views/view directly?

cc @kmagiera who wrote TouchableNativeFeedback, can you take a look please? :)

@kmagiera kmagiera assigned sebmck and kmagiera and unassigned sebmck Mar 21, 2016
private void refreshTranslucentBackgroundDrawable() {
Drawable background = null;
if (mNativeBackground != null) {
float[] cornerRadii = getOrCreateReactViewBackground().getBorderRadii();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you may want to check if mReactBackgroundDrawable != null first. Otherwise this line will create that background object for every view with native background which is undesirable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah good catch, updated.

@kmagiera
Copy link
Contributor

I left one comment inline. Otherwise this looks good to me.

@facebook-github-bot
Copy link
Contributor

@jeffchienzabinet updated the pull request.

@kmagiera
Copy link
Contributor

@jeffchienzabinet sorry for bugging you again: would you be able to squash your commit so that it only adds 1 commit instead of 9. This helps to keep the history of changes cleaner

@facebook-github-bot
Copy link
Contributor

@jeffchienzabinet updated the pull request.

@facebook-github-bot
Copy link
Contributor

@jeffchienzabinet updated the pull request.

@jeffchienzabinet
Copy link
Contributor Author

I messed up the first rebase attempt so I had to hard reset and copy over the changes. I think it should be right...I hope

<View>
<TouchableNativeFeedback
style={[styles.row, styles.block]}
onPress={() => console.log('TNF Ripple with Border Radius has been clicked')}

Choose a reason for hiding this comment

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

quotes: Strings must use singlequote.

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I personally find TNF a bit unclear. Can you use TouchableNativeFeedback?

@mkonicek
Copy link
Contributor

Thanks a lot for the review @kmagiera! I'll wait for the tests to pass before merging. You can also use the shipit bot if you want.

@mkonicek
Copy link
Contributor

mkonicek commented Apr 1, 2016

I've just restarted the tests.

@mkonicek
Copy link
Contributor

mkonicek commented Apr 1, 2016

@facebook-github-bot shipit

@jeffchienzabinet
Copy link
Contributor Author

Alright, done. Also fixed some conflicts.

@facebook-github-bot
Copy link
Contributor

@jeffchienzabinet updated the pull request.

if (!drawableDescriptionDict.hasKey("borderless") ||
drawableDescriptionDict.isNull("borderless") ||
!drawableDescriptionDict.getBoolean("borderless")) {
mask = new ColorDrawable(Color.WHITE);
mask = new PaintDrawable(Color.WHITE);
if (cornerRadii != null)
Copy link
Contributor

@mkonicek mkonicek Apr 21, 2016

Choose a reason for hiding this comment

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

nit: Please always add braces to keep the formatting consistent with the rest of the codebase:

if (foo) {
  oneLiner();
}

It's just a coding convention.

@mkonicek
Copy link
Contributor

Thanks @jeffchienzabinet! Just some small nits, then this is good to go! 👍

Non-ripples generated by TNF.Ripple are now clipped by border radii the
same way that the ReactViewGroup it's a background of gets clipped. This
is achieved by refreshing those backgrounds in ReactViewGroup whenever
nativeBackground or any of the borderRadii is updated, rather than
ReactViewManager just setting the background Drawable. Note that
TNF.SelectableBackground is not clipped because it's not possible to
clip the selectableItemBackground Drawable.
@jeffchienzabinet
Copy link
Contributor Author

Alright, done!

@facebook-github-bot
Copy link
Contributor

@jeffchienzabinet updated the pull request.

@mkonicek
Copy link
Contributor

Thanks @jeffchienzabinet!

@facebook-github-bot shipit

@facebook-github-bot facebook-github-bot added Import Started This pull request has been imported. This does not imply the PR has been approved. and removed GH Review: needs-revision labels Apr 22, 2016
@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to Phabricator to review.

@ghost ghost closed this in e438954 Apr 22, 2016
ghost pushed a commit that referenced this pull request Apr 24, 2016
Summary:Using TouchableNativeFeedback has been a problem for me because the ripples it makes don't follow the child view's border radii so the ripples stick out of the child view's rounded corners. This PR should fix this problem with a minor caveat: this only works for TouchableNativeFeedback.Ripple and not TouchableNativeFeedback.SelectableBackground. I searched how I could apply corner radius to selectableItemBackground and it doesn't seem to be possible (the prevalent advice is to create the ripple manually which is equivalent to using TNF.Ripple in our case), though I could be wrong.

I added [an example to UIExplorer (TouchableExample)](http://i.imgur.com/CHY9xjW.png). This is my first PR to this repo so let me know if something's wrong. Cheers!
Closes #6515

Differential Revision: D3126513

Pulled By: AaaChiuuu

fb-gh-sync-id: 4a00e7177ee4ffd8dffeca143f4f43f08c99b5a1
fbshipit-source-id: 4a00e7177ee4ffd8dffeca143f4f43f08c99b5a1
ide pushed a commit to expo/react-native that referenced this pull request Apr 25, 2016
Summary:Using TouchableNativeFeedback has been a problem for me because the ripples it makes don't follow the child view's border radii so the ripples stick out of the child view's rounded corners. This PR should fix this problem with a minor caveat: this only works for TouchableNativeFeedback.Ripple and not TouchableNativeFeedback.SelectableBackground. I searched how I could apply corner radius to selectableItemBackground and it doesn't seem to be possible (the prevalent advice is to create the ripple manually which is equivalent to using TNF.Ripple in our case), though I could be wrong.

I added [an example to UIExplorer (TouchableExample)](http://i.imgur.com/CHY9xjW.png). This is my first PR to this repo so let me know if something's wrong. Cheers!
Closes facebook#6515

Differential Revision: D3126513

Pulled By: mkonicek

fb-gh-sync-id: 1d3e92243abf9706132ae47c485d9e04a9b47d81
fbshipit-source-id: 1d3e92243abf9706132ae47c485d9e04a9b47d81
@mkonicek
Copy link
Contributor

mkonicek commented Apr 25, 2016

@jeffchienzabinet Product teams at fb reported this broke a few things, such as standard borderRadius and JS-based modals.

The commit was reverted in 475f1b5.

Feel free to submit this again. Can you implement this in a way that only affects TouchableNativeFeedback and nothing else?

Sorry about that, I should have asked for a very thorough Test plan on this pull request that not only tests the new functionality but also the existing one (e.g. borders on views), especially since this modifies such core parts of the codebase (ReactViewGroup, ReactViewBackgroundDrawable).

@jeffchienzabinet
Copy link
Contributor Author

Ahh, damn. Alright, give me some time. Do you guys know what the problem is exactly?

ptmt pushed a commit to ptmt/react-native that referenced this pull request May 9, 2016
Summary:Using TouchableNativeFeedback has been a problem for me because the ripples it makes don't follow the child view's border radii so the ripples stick out of the child view's rounded corners. This PR should fix this problem with a minor caveat: this only works for TouchableNativeFeedback.Ripple and not TouchableNativeFeedback.SelectableBackground. I searched how I could apply corner radius to selectableItemBackground and it doesn't seem to be possible (the prevalent advice is to create the ripple manually which is equivalent to using TNF.Ripple in our case), though I could be wrong.

I added [an example to UIExplorer (TouchableExample)](http://i.imgur.com/CHY9xjW.png). This is my first PR to this repo so let me know if something's wrong. Cheers!
Closes facebook#6515

Differential Revision: D3126513

Pulled By: mkonicek

fb-gh-sync-id: 1d3e92243abf9706132ae47c485d9e04a9b47d81
fbshipit-source-id: 1d3e92243abf9706132ae47c485d9e04a9b47d81
ptmt pushed a commit to ptmt/react-native that referenced this pull request May 9, 2016
Summary:Using TouchableNativeFeedback has been a problem for me because the ripples it makes don't follow the child view's border radii so the ripples stick out of the child view's rounded corners. This PR should fix this problem with a minor caveat: this only works for TouchableNativeFeedback.Ripple and not TouchableNativeFeedback.SelectableBackground. I searched how I could apply corner radius to selectableItemBackground and it doesn't seem to be possible (the prevalent advice is to create the ripple manually which is equivalent to using TNF.Ripple in our case), though I could be wrong.

I added [an example to UIExplorer (TouchableExample)](http://i.imgur.com/CHY9xjW.png). This is my first PR to this repo so let me know if something's wrong. Cheers!
Closes facebook#6515

Differential Revision: D3126513

Pulled By: AaaChiuuu

fb-gh-sync-id: 4a00e7177ee4ffd8dffeca143f4f43f08c99b5a1
fbshipit-source-id: 4a00e7177ee4ffd8dffeca143f4f43f08c99b5a1
@cancan101
Copy link
Contributor

Any updates on this?

zebulgar pushed a commit to nightingale/react-native that referenced this pull request Jun 18, 2016
Summary:Using TouchableNativeFeedback has been a problem for me because the ripples it makes don't follow the child view's border radii so the ripples stick out of the child view's rounded corners. This PR should fix this problem with a minor caveat: this only works for TouchableNativeFeedback.Ripple and not TouchableNativeFeedback.SelectableBackground. I searched how I could apply corner radius to selectableItemBackground and it doesn't seem to be possible (the prevalent advice is to create the ripple manually which is equivalent to using TNF.Ripple in our case), though I could be wrong.

I added [an example to UIExplorer (TouchableExample)](http://i.imgur.com/CHY9xjW.png). This is my first PR to this repo so let me know if something's wrong. Cheers!
Closes facebook#6515

Differential Revision: D3126513

Pulled By: mkonicek

fb-gh-sync-id: 1d3e92243abf9706132ae47c485d9e04a9b47d81
fbshipit-source-id: 1d3e92243abf9706132ae47c485d9e04a9b47d81
zebulgar pushed a commit to nightingale/react-native that referenced this pull request Jun 18, 2016
Summary:Using TouchableNativeFeedback has been a problem for me because the ripples it makes don't follow the child view's border radii so the ripples stick out of the child view's rounded corners. This PR should fix this problem with a minor caveat: this only works for TouchableNativeFeedback.Ripple and not TouchableNativeFeedback.SelectableBackground. I searched how I could apply corner radius to selectableItemBackground and it doesn't seem to be possible (the prevalent advice is to create the ripple manually which is equivalent to using TNF.Ripple in our case), though I could be wrong.

I added [an example to UIExplorer (TouchableExample)](http://i.imgur.com/CHY9xjW.png). This is my first PR to this repo so let me know if something's wrong. Cheers!
Closes facebook#6515

Differential Revision: D3126513

Pulled By: AaaChiuuu

fb-gh-sync-id: 4a00e7177ee4ffd8dffeca143f4f43f08c99b5a1
fbshipit-source-id: 4a00e7177ee4ffd8dffeca143f4f43f08c99b5a1
@antoinerousseau
Copy link
Contributor

antoinerousseau commented Jul 14, 2016

@mkonicek @jeffchienzabinet @kmagiera any plan to make this again? it sounds awesome ^^

bubblesunyum pushed a commit to iodine/react-native that referenced this pull request Aug 23, 2016
Summary:Using TouchableNativeFeedback has been a problem for me because the ripples it makes don't follow the child view's border radii so the ripples stick out of the child view's rounded corners. This PR should fix this problem with a minor caveat: this only works for TouchableNativeFeedback.Ripple and not TouchableNativeFeedback.SelectableBackground. I searched how I could apply corner radius to selectableItemBackground and it doesn't seem to be possible (the prevalent advice is to create the ripple manually which is equivalent to using TNF.Ripple in our case), though I could be wrong.

I added [an example to UIExplorer (TouchableExample)](http://i.imgur.com/CHY9xjW.png). This is my first PR to this repo so let me know if something's wrong. Cheers!
Closes facebook#6515

Differential Revision: D3126513

Pulled By: mkonicek

fb-gh-sync-id: 1d3e92243abf9706132ae47c485d9e04a9b47d81
fbshipit-source-id: 1d3e92243abf9706132ae47c485d9e04a9b47d81
bubblesunyum pushed a commit to iodine/react-native that referenced this pull request Aug 23, 2016
Summary:Using TouchableNativeFeedback has been a problem for me because the ripples it makes don't follow the child view's border radii so the ripples stick out of the child view's rounded corners. This PR should fix this problem with a minor caveat: this only works for TouchableNativeFeedback.Ripple and not TouchableNativeFeedback.SelectableBackground. I searched how I could apply corner radius to selectableItemBackground and it doesn't seem to be possible (the prevalent advice is to create the ripple manually which is equivalent to using TNF.Ripple in our case), though I could be wrong.

I added [an example to UIExplorer (TouchableExample)](http://i.imgur.com/CHY9xjW.png). This is my first PR to this repo so let me know if something's wrong. Cheers!
Closes facebook#6515

Differential Revision: D3126513

Pulled By: AaaChiuuu

fb-gh-sync-id: 4a00e7177ee4ffd8dffeca143f4f43f08c99b5a1
fbshipit-source-id: 4a00e7177ee4ffd8dffeca143f4f43f08c99b5a1
This pull request was closed.
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. Import Started This pull request has been imported. This does not imply the PR has been approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants