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

borderRadius is never applied on Android when image contains another component

Open dseemann opened this issue 10 years ago • 26 comments

While working perfectly on iOS, border radius is never applied to an image if it contains any other component:

<Image style={ { borderRadius: 10, width: 300, height: 100 } } source={{ uri: 'https://placekitten.com/300/100' }}> <Text>SampleText</Text> </Image>

ios: ios

android: android

I am using RN 0.29.0, and this is happening across all Android devices. I am currently building from osx

dseemann avatar Jul 19 '16 08:07 dseemann

I'd imagine the "fix" for this would be to wrap the image in a view that contains border radius instead. Eg. <View style = {{flex: 1, borderRadius: 10}} ><Image style={ {width: 300, height: 100 } } source={{ uri: 'https://placekitten.com/300/100' }}> <Text>SampleText</Text> </Image> </View>

austinksmith avatar Jul 21 '16 17:07 austinksmith

Tried it, unfortunately the images still had no borderRadius applied.

dseemann avatar Jul 22 '16 12:07 dseemann

@5in4 did you try it with a more recent RN version?

Dynom avatar Jul 25 '16 10:07 Dynom

I managed to get around this by having the Text after the image and setting it to absolute/top:0.

<View style={container}>
  <Image {/*...*/} />
  <Text style={{ position: 'absolute', top: 0 }}>{text}</Text>
</View>

This could could probably be fixed by using RN 0.30.0 (see v0.30.0 release notes )

yazgazan avatar Jul 25 '16 10:07 yazgazan

I tried it on RN 0.30 and on 0.31 RC, behavior doesn't change.

@yazgazan seems to be reasonable workaround

dseemann avatar Jul 27 '16 08:07 dseemann

Still having this issue with RN 0.31 on Android

StellwagJo avatar Sep 15 '16 09:09 StellwagJo

  1. https://github.com/facebook/react-native/issues/8649
  2. https://github.com/facebook/react-native/issues/3198

leeight avatar Sep 15 '16 12:09 leeight

Still having the same issue with RN 0.36 on Android.

Canedo avatar Nov 10 '16 20:11 Canedo

Managed to solve the problem using the borderRadius attribute on the Image instead of providing as style. RN 0.40

<Image
  source={{uri: 'http://lorempixel.com/400/300/'}}
  height={100}
  resizeMode="cover"
  borderRadius={10}
>
  <MyCustomComponent />
</Image>

SushilShrestha avatar Feb 20 '17 09:02 SushilShrestha

Thanks @SushilShrestha for this. It works for me and has maybe saved me a couple of potentially agonizing minutes trying to find solutions. I have a Button element within my image which screwed up with its styling a bit, but adding borderRadius={50} to the Image and maintaining resizeMode: "cover" in my styles fixes the issue.

crim3hound avatar Jul 17 '17 10:07 crim3hound

@SushilShrestha that works for me too, thanks :).

However, do you get a warning like You're setting the style { bordeRadius: ...} as a prop. You should nest it in a style object. E.g.: { style: { borderRadius: .. } } when using it? I guess it makes sense since the docs say it's meant to be used in the style only. However, there's a setter for it which I reckon it's why it works outside of style.

I wonder why it's not being picked up when it's defined as a style though because it works if the style is manually set through the react-devtools!

dariocravero avatar Sep 11 '17 23:09 dariocravero

@dariocravero I'm seeing the warning only on iOS. The warning goes away if I set bordeRadius prop only when Platform.OS === 'android'.

leethree avatar Sep 24 '17 09:09 leethree

We tried the trick of applying the border radius to the Image and it works inconsistently. Only some corners look rounded at random. This only happens on Android.

pintocarlos avatar Oct 27 '17 20:10 pintocarlos

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

stale[bot] avatar Dec 26 '17 21:12 stale[bot]

This was fixed in RN 0.50.4

pintocarlos avatar Dec 27 '17 19:12 pintocarlos

I am using RN 0.51.0 and issue still persists

vvavepacket avatar Jan 06 '18 19:01 vvavepacket

+1

xavier86 avatar Jan 15 '18 10:01 xavier86

I suggest you check this other issue https://github.com/facebook/react-native/issues/2468#issuecomment-308840184

(this is in fact a duplicate)

kelset avatar Jan 16 '18 12:01 kelset

borderRadius is not working in right Side only.

vijaya06 avatar Feb 21 '18 12:02 vijaya06

using .54 and issue still exsists on android

alzalabany avatar Mar 06 '18 03:03 alzalabany