I'm new to react native development. I want the image to be in aspect ratio and when I try to change its bounds the area outside the bounds should be clipped off. In Android, it is working correctly but not in iOS the image is not clipping to its bounds and showing the whole image.
<View
style={{
backgroundColor: "#04894a",
padding: 10,
height: 110,
alignItems: "center"
}}
>
<View
style={{
alignItems: "center"
}}
>
<Image
style={{ height: 150, width: 150 }}
source={require("../images/wow_logo.png")}
/>
</View>
The image is going outside the view but still, it is showing in full. I want it to be cropped if going outside the bounds. Can anyone help me with this? Any links or suggestions are also appreciated. TIA
How do you change the size of image in React Native? To resize image with React Native, we set the width and height of the image to percentages and set resizeMode to 'cover' .
You have have to use position:'absolute' and put the circle element as the last element of the elements list so it comes to top (no need to use zIndex). also the container div must have styles for child elements to be centered. There won't be an issue since you can position that container div where ever you want.
To load images in react native from URL you must specify the image width, and height. React native cannot determine the width and height from downloaded images. After specifying width, and height we can specify the URL to the image source prop. Inside this prop we will specify a uri which holds our image URL.
Use overflow: hidden
- by default in react native the overflow flag is visible.
Also to maintain the aspect ratio, just have one parameter width or height to the image, then add style={{ aspectRatio: 3/2 }}
so that the width:height ratio is maintained.
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