-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Conversation
@mkonicek is this good-to-go? |
@mattds Can you rebase? |
@mattds updated the pull request. |
@satya164, apologies for the delay, sure, I've rebased. |
Thanks @mattds . cc @mkonicek @nicklockwood |
@mattds updated the pull request. |
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. |
@kmagiera Does this look OK to you? |
|
||
RoundingParams roundingParams = hierarchy.getRoundingParams(); | ||
roundingParams.setCornersRadius(hierarchyRadius); | ||
roundingParams.setCornersRadii(mBorderRadius); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: [position * 2]
@mattds Thanks for your work on this PR. Please see my comments inline. Also do you mind adding an example to |
@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. |
@mattds since that's basically how subviews inside |
@mattds that works perfectly. Thank you! |
@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. |
ping @kmagiera ;) |
@joelcloralt @nicklockwood is right. On android |
: 0; | ||
outline.setRoundRect(getBounds(), mBorderRadius + extraRadiusFromBorderWidth); | ||
if((!CSSConstants.isUndefined(mBorderRadius) && mBorderRadius > 0) || mBorderCornerRadii != null) { | ||
if (mPathForBorderRadiusOutline == null) { |
There was a problem hiding this comment.
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.
@mattds updated the pull request. |
@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/ |
@mpretty-homepass this already works on iOS (using pretty-much the technique you described). |
@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) |
@mpretty-homepass yes, it's supported on iOS for everything except |
@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. |
Yeah, let me try landing this. Looks good and all comments have been address. Thanks @mattds for your patience. @facebook-github-bot shipit |
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. |
4937a4c
@mattds Is this meant to be working on ImageView's as well? |
@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. |
@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. |
Thanks for pointing to the other PR though, will merge with our fork and use that for the time being. |
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. |
@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. |
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
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
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
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
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 is a cut down version of a previous pull request with just the 4 corners catered for.