css-to-react-native icon indicating copy to clipboard operation
css-to-react-native copied to clipboard

borderRadius property regression?

Open jh3y opened this issue 7 years ago • 21 comments

I had opened up an issue over on styled-components here about the borderRadius property on native.

It seems going from version 1.0.11 to 1.1.1 in styled-components regressed how borderRadius would work.

borderTopLeftRadius etc. seemingly have no effect when developing for native from what I can tell in the simulator and what works is simply using borderRadius.

After having a dive into the source, I think this just requires a slight change to the grammar file to only output borderRadius.

I'll submit a PR for this.

@jh3y

jh3y avatar Nov 24 '16 05:11 jh3y

I'll have to test this. RN claims to support this. https://facebook.github.io/react-native/docs/view.html#style

jacobp100 avatar Nov 24 '16 08:11 jacobp100

I don't quite understand what the issue here is, what should be happening that isn't happening?

mxstbr avatar Nov 24 '16 08:11 mxstbr

I’m not able to reproduce this on 0.38. You are correct in how border-radius splats into borter-{top,bottom}-{left,right}-radius, but that does seem to work.

screen shot 2016-11-24 at 10 08 22 screen shot 2016-11-24 at 10 17 41

jacobp100 avatar Nov 24 '16 10:11 jacobp100

I've just tested this out again using [email protected] and [email protected], same issue.

In the simulator, could you inspect that with the inspector and see what style properties are given?

What is cssta(View)? I'm using styled.Image to get this issue. With a View, you will get the correct borderRadius set but when you apply border radius to an Image it is ignored.

That's because rn needs the borderRadius prop for an Image it seems.

The way styled-components previously worked meant that the borderRadius property was set as expected and the Image itself was round so you could do as shown here but with styled-components

<RoundImage source={{uri: 'http://placehold.it/100x100'}}/>
// styles
import styled from 'styled-components/native'
const RoundImage = styled.Image`
    height: 100;
    border-radius: 50;
    width: 100;
`

This either means not being able to upgrade to the newer version or having to refactor everywhere in a project where an Image is round to be wrapped by a View with overflow: hidden set.

I've just given this another go without styled-components at all and although Image also supports the borderRadius props the same as View, it seems that it doesn't respect them and currently only respects borderRadius on its own for Image.

So I've gone from styled-components -> css-to-react-native -> to react-native :joy: I'll have raise an issue over there I guess.

@jh3y

jh3y avatar Nov 24 '16 12:11 jh3y

Got you. It’s fixed in #13.

jacobp100 avatar Nov 24 '16 14:11 jacobp100

I don't think it can be fixed here can it? I think this is potentially a react-native issue.

borderTopLeftRadius etc. work differently with Image to how they do with View, as in they don't :joy:

It would be a nice to have for now if only supplying one value, it only output borderRadius though 😎

border-radius: 10 -> borderRadius: 10

border-radius: 10 20 -> borderTopLeftRadius: 10, borderTopRightRadius: 20, etc.

Of course, if multiple props are supplied you can't really give a single value for borderRadius.

@jh3y

jh3y avatar Nov 24 '16 14:11 jh3y

Can you not wrap the image in a View, and use overflow: hidden?

Although we might need to look at some special casing.

jacobp100 avatar Nov 24 '16 14:11 jacobp100

Yeah I mentioned that as a solution above but then that means refactoring every instance of an Image component that is rounded to be wrapped by a View which isn't ideal overhead if it works how I intend when using [email protected] 😕

Image respects borderRadius. It just doesn't respect the specifics.

That's why I'm leaning towards this being an issue with react-native. However, that being said, upgrading to the newer styled-components highlighted it for me because it doesn't generate the borderRadius property anymore and only the specifics.

jh3y avatar Nov 24 '16 14:11 jh3y

I’m thinking, special casing is going to be hard:

const StyledImage = styled(Image)`...`; // This is hard enough to work out that we need to special case
const SuperSpecialStyledImage = styled(StyledImage)`...` // This is almost impossible

Maybe we need to turn off this shorthand for the time being. @mxstbr

jacobp100 avatar Nov 24 '16 14:11 jacobp100

Let's turn it off then!

mxstbr avatar Nov 24 '16 16:11 mxstbr

But that's a major version release again, ugh

mxstbr avatar Nov 24 '16 16:11 mxstbr

That's true. Maybe we just document the behaviour?

jacobp100 avatar Nov 24 '16 17:11 jacobp100

Although I suppose this was a breaking change in the first place? I believe semver says we should revert the breaking change.

jacobp100 avatar Nov 24 '16 17:11 jacobp100

Oh if it was a breaking change in the first place let's push this as a patch. Would you mind doing that?

mxstbr avatar Nov 24 '16 17:11 mxstbr

Happy to help if required :smile:

jh3y avatar Nov 24 '16 17:11 jh3y

Over here! https://github.com/styled-components/styled-components/pull/254

jacobp100 avatar Nov 24 '16 18:11 jacobp100

Looks like we could turn this off soon

https://github.com/facebook/react-native/commit/66a294032a41f489ef5407975b2a5276df825ceb

There's a few other cases that'll get fixed too

jacobp100 avatar Apr 12 '19 11:04 jacobp100

Poking on this one @jacobp100

magik-chorne avatar Jan 09 '20 21:01 magik-chorne

Has anyone confirmed this works now? And from what version it works

jacobp100 avatar Jan 10 '20 07:01 jacobp100

Also, the change to re-enable these has to happen in styled-components. We take a blacklist of properties, and the border-radius is passed in there in SC

Once SC removes this, we'll remove the code around blacklisting here too, since it will no longer be needed

jacobp100 avatar Jan 20 '20 20:01 jacobp100

https://github.com/styled-components/styled-components/pull/2976

jacobp100 avatar Jan 20 '20 21:01 jacobp100

I'm closing this because it's been years since this was an issue

jacobp100 avatar Feb 14 '23 11:02 jacobp100

I'm still having problem with it

My current setup: react-native 0.72.6 styled-components: 6.1.0

Edit: For future reference (for anyone around like me struggling to understand), I made it work by wrapping my Image inside a VIew, like this:

ImageWrapperView: styled(View)`
    overflow: hidden;
    width: 280px;
    height: 328px;
    border-radius: 20px;
`,
Image: styled(Image)`
    width: 100%;
    height: 100%;
`,

But it would be nice to rely directly on the styled Image

fershibli avatar Nov 30 '23 03:11 fershibli