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

Added support for corner radii in Android #4252

Closed
wants to merge 1 commit into from
Closed

Added support for corner radii in Android #4252

wants to merge 1 commit into from

Conversation

mattds
Copy link

@mattds mattds commented Nov 20, 2015

This is a cut down version of a previous pull request with just the 4 corners catered for.

@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Nov 20, 2015
@ide ide added the Android label Nov 20, 2015
@nicklockwood
Copy link
Contributor

@mkonicek is this good-to-go?

@satya164
Copy link
Contributor

@mattds Can you rebase?

@facebook-github-bot
Copy link
Contributor

@mattds updated the pull request.

@mattds
Copy link
Author

mattds commented Dec 31, 2015

@satya164, apologies for the delay, sure, I've rebased.

@satya164
Copy link
Contributor

satya164 commented Jan 1, 2016

Thanks @mattds . cc @mkonicek @nicklockwood

@facebook-github-bot
Copy link
Contributor

@mattds updated the pull request.

@mattds
Copy link
Author

mattds commented Jan 1, 2016

It's a pleasure, I updated the pull request with a minor change to getOutline of ReactViewBackgroundDrawable - now it sets mNeedUpdatePathForBorderRadius = true only if mPathForBorderRadius == null so that the subsequent call to updatePath will only update the path if it's not set or changed.

@mkonicek
Copy link
Contributor

mkonicek commented Jan 6, 2016

@kmagiera Does this look OK to you?


RoundingParams roundingParams = hierarchy.getRoundingParams();
roundingParams.setCornersRadius(hierarchyRadius);
roundingParams.setCornersRadii(mBorderRadius);
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 perhaps use setCornersRadii(float topLeft, float topRight, float bottomRight, float bottomLeft) and this way have mBorderRadius to only store 4 floats

}

if (!FloatUtil.floatsEqual(mBorderRadius[position*2], radius)) {
mBorderRadius[position*2] = radius;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: [position * 2]

@kmagiera
Copy link
Contributor

kmagiera commented Jan 6, 2016

@mattds Thanks for your work on this PR. Please see my comments inline. Also do you mind adding an example to UIExplorer/BorderExample.js of a component with 2 different radii + another example with elevation?

@mattds
Copy link
Author

mattds commented Jan 6, 2016

@kmagiera thanks for reviewing, I will make the changes mentioned and resubmit. I see now that borderRadius will potentially overwrite corner radii as you mentioned - I think I will need to keep borderRadius around as a separate value as a default for unset corners, will revise and add the examples mentioned.

@nicklockwood
Copy link
Contributor

@mattds since that's basically how subviews inside <Image> are implemented on Android anyway, I'll wager you can make that work without the extra wrapper view by just debugging the code in Image.android.js - it's probably applying the border styles to the wrong element or something.

@joelcloralt
Copy link
Contributor

@mattds that works perfectly. Thank you!

@mattds
Copy link
Author

mattds commented Jan 19, 2016

@joelcloralt it's a pleasure :) @nicklockwood you're right, changing

var imageProps = merge(nativeProps, {
          style: styles.absoluteImage,
          children: undefined,
        });

to

var imageProps = merge(nativeProps, {
          style: flattenStyle([styles.absoluteImage, nativeProps.style.borderRadius ? {borderRadius: nativeProps.style.borderRadius} : null]),
          children: undefined,
        });

in Image.android.js seems to work without the extra view.

@brentvatne
Copy link
Collaborator

ping @kmagiera ;)

@kmagiera
Copy link
Contributor

@joelcloralt @nicklockwood is right. On android Image component with children is implemented in JS by wrapping children in a View with Image inside of it as a first child. Therefore corner radius won't work as you may expect as on Android we don't support children clipping based on the corner radius (see the explanation here)

: 0;
outline.setRoundRect(getBounds(), mBorderRadius + extraRadiusFromBorderWidth);
if((!CSSConstants.isUndefined(mBorderRadius) && mBorderRadius > 0) || mBorderCornerRadii != null) {
if (mPathForBorderRadiusOutline == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this check here? I think that what we should do instead is that we should set mNeedUpdatePathForBorderRadius = true in both setRadius methods to be consistent with the way how we update that property.

@kmagiera
Copy link
Contributor

Thanks @mattds and sorry for the delay in review. I have just last one comment inline. Will also let @mkonicek merge this as every time I "ship" stuff, something breaks :)

@facebook-github-bot
Copy link
Contributor

@mattds updated the pull request.

@mattds
Copy link
Author

mattds commented Jan 27, 2016

@kmagiera, no worries. I moved "mNeedUpdatePathForBorderRadius = true" to the setRadius methods, this will indeed make the check in getOutline unnecessary, thanks. I've checked in the changes. @mkonicek is this version ready to ship?

@mpretty-cyro
Copy link

@mattds Just FYI, there is a way to get something similar working on iOS by setting a layer mask (although it's performance isn't great) - https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIBezierPath_class/#//apple_ref/occ/clm/UIBezierPath/bezierPathWithRoundedRect:cornerRadius:

A better write up can be found here - http://ronnqvi.st/thinking-like-a-bzier-path/

@nicklockwood
Copy link
Contributor

@mpretty-homepass this already works on iOS (using pretty-much the technique you described).

@mpretty-cyro
Copy link

@nicklockwood oh really? Is this something I can do via React Native? (Couldn't seem to find it in the docs).

I mostly mentioned it because of the comment about iOS support here - #4252 (comment)

@nicklockwood
Copy link
Contributor

@mpretty-homepass yes, it's supported on iOS for everything except <Image> components, which only support equal borders and corner radii. (But you can work around that by wrapping your <Image> in another <View> with overflow:hidden).

@mkonicek
Copy link
Contributor

mkonicek commented Feb 8, 2016

@kmagiera do you want to take a look try shipit again? The plan is we'll make it work reliably this half :) Not sure all your comments have been addressed.

@kmagiera
Copy link
Contributor

kmagiera commented Feb 8, 2016

Yeah, let me try landing this. Looks good and all comments have been address. Thanks @mattds for your patience.

@facebook-github-bot shipit

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/535947113226769/int_phab to review.

@ghost ghost closed this in 4937a4c Feb 8, 2016
@mpretty-cyro
Copy link

@mattds Is this meant to be working on ImageView's as well?

@mattds
Copy link
Author

mattds commented Feb 22, 2016

@mpretty-homepass, so this pull request is just for regular views, #5197 is for images on Android, but since the same functionality is missing on iOS, it probably won't be merged in.

@mpretty-cyro
Copy link

@mattds that's fine in iOS since you can clip child views by adding a borderRadius to their parents; but that doesn't work in Android. Which means that without this, there is no way to replicate the effect on Android.

@mpretty-cyro
Copy link

Thanks for pointing to the other PR though, will merge with our fork and use that for the time being.

@nicklockwood
Copy link
Contributor

I (wrongly) assumed at the time of review that subview clipping worked on Android. Given that it doesn't, I think it's probably worth revisiting #5197 - although ideally I'd like us to get this working the same on both platforms, instead of needing separate platform-specific solutions.

@mpretty-cyro
Copy link

@nicklockwood I completely agree that ideally Android and iOS would function in the same way, but for the time being at least that would allow us to render the same elements on both platforms.

pglotov pushed a commit to pglotov/react-native that referenced this pull request Mar 15, 2016
Summary:
This is a cut down version of a previous pull request with just the 4 corners catered for.
Closes facebook#4252

Reviewed By: svcscm

Differential Revision: D2911959

Pulled By: androidtrunkagent

fb-gh-sync-id: 7ddcd684d90d4d92ccefed906c0126e92818dcde
ghost pushed a commit that referenced this pull request Apr 13, 2016
Summary:Split out from PR #4252 - kmagiera I've made the changes to how the radii arrays are allocated, is the approach I've taken correct? also it looks like ImageStylePropTypes are needed so I left them in for the moment. I suppose this pull request will only be valid if iOS supports image corner radii, but at least it's here if/when needed. Attached an image of how it handles the existing case:
![screen shot 2016-01-08 at 4 21 25 pm](https://cloud.githubusercontent.com/assets/1407729/12200126/d3caceac-b625-11e5-8281-06274732a281.png)
Closes #5197

Differential Revision: D3138725

Pulled By: mkonicek

fb-gh-sync-id: df772fd07fe85386ae4c681f9e79a19d2316d38b
fbshipit-source-id: df772fd07fe85386ae4c681f9e79a19d2316d38b
ide pushed a commit to expo/react-native that referenced this pull request May 5, 2016
Summary:Split out from PR facebook#4252 - kmagiera I've made the changes to how the radii arrays are allocated, is the approach I've taken correct? also it looks like ImageStylePropTypes are needed so I left them in for the moment. I suppose this pull request will only be valid if iOS supports image corner radii, but at least it's here if/when needed. Attached an image of how it handles the existing case:
![screen shot 2016-01-08 at 4 21 25 pm](https://cloud.githubusercontent.com/assets/1407729/12200126/d3caceac-b625-11e5-8281-06274732a281.png)
Closes facebook#5197

Differential Revision: D3138725

Pulled By: mkonicek

fb-gh-sync-id: df772fd07fe85386ae4c681f9e79a19d2316d38b
fbshipit-source-id: df772fd07fe85386ae4c681f9e79a19d2316d38b
ide pushed a commit to expo/react-native that referenced this pull request May 6, 2016
Summary:Split out from PR facebook#4252 - kmagiera I've made the changes to how the radii arrays are allocated, is the approach I've taken correct? also it looks like ImageStylePropTypes are needed so I left them in for the moment. I suppose this pull request will only be valid if iOS supports image corner radii, but at least it's here if/when needed. Attached an image of how it handles the existing case:
![screen shot 2016-01-08 at 4 21 25 pm](https://cloud.githubusercontent.com/assets/1407729/12200126/d3caceac-b625-11e5-8281-06274732a281.png)
Closes facebook#5197

Differential Revision: D3138725

Pulled By: mkonicek

fb-gh-sync-id: df772fd07fe85386ae4c681f9e79a19d2316d38b
fbshipit-source-id: df772fd07fe85386ae4c681f9e79a19d2316d38b
zebulgar pushed a commit to nightingale/react-native that referenced this pull request Jun 18, 2016
Summary:Split out from PR facebook#4252 - kmagiera I've made the changes to how the radii arrays are allocated, is the approach I've taken correct? also it looks like ImageStylePropTypes are needed so I left them in for the moment. I suppose this pull request will only be valid if iOS supports image corner radii, but at least it's here if/when needed. Attached an image of how it handles the existing case:
![screen shot 2016-01-08 at 4 21 25 pm](https://cloud.githubusercontent.com/assets/1407729/12200126/d3caceac-b625-11e5-8281-06274732a281.png)
Closes facebook#5197

Differential Revision: D3138725

Pulled By: mkonicek

fb-gh-sync-id: df772fd07fe85386ae4c681f9e79a19d2316d38b
fbshipit-source-id: df772fd07fe85386ae4c681f9e79a19d2316d38b
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants