Update 2021
resizeMode not working while given as a style prop to Image in RN Android
borderRadius works as expected in iOS but not working as expected in Android. I tried to wrap the Image
in a View and gave borderRadius
and overFlow: 'hidden'
<View style={styles.userImageContainer}>
<Image source={require('../../assets/images/user1.png')}
style={styles.userImage}
/>
</View>
StyleSheet
const imageSize = 40;
userImageContainer: {
height: imageSize,
width: imageSize,
borderWidth: 1,
alignItems: 'center',
justifyContent: 'center',
borderRadius: imageSize/2,
overflow: 'hidden'
},
userImage: {
height: imageSize,
width: imageSize,
borderRadius: imageSize/2,
padding: 5,
resizeMode: 'contain'
},
End result Image
I am using RN 0.42.2 0.66.3
resizeMode contain : Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding). stretch : Scale width and height independently, This may change the aspect ratio of the src.
The default aspect ratio is 16/9 .
UPDATE
Applying borderRadius
and resizeMode
as props instead as a style attribute will fix the borderRadius issue in Android
<Image
source={{uri: 'path'}}
style={styles.image}
resizeMode="cover"
borderRadius={value}
/>
For those who are facing this issue, its a known issue with react-native android. As of now there is no fix for it.
https://facebook.github.io/react-native/releases/0.26/docs/known-issues.html#the-overflow-style-property-defaults-to-hidden-and-cannot-be-changed-on-android
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With