resizeMode=“contain” takes up space of the original image
See original GitHub issueDescription
The style
below correctly resizes the image. However, it takes up the space of the original image and the resized image is center aligned. I’ve added the backgroundColor
to make it easier to visualize the screenshot attached.
image: {
width: '100%',
resizeMode: 'contain',
backgroundColor: 'black',
},
React Native version:
0.61
Expected Results
I’m expecting the “resized image” to take up the size of the resized image
Screenshot:
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:10
Top Results From Across the Web
resizeMode contain showing space before and after image in ...
resizeMode="contain " is Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image ...
Read more >Understanding “resizeMode” in React Native | by Mehran Khan
2 ) “contain” : Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image...
Read more >resizeMode=“contain” takes up space of the original image
I am trying to render an Image as below. The style below correctly resizes the image. However, it takes…
Read more >CSS object-fit Property - W3Schools
This property tells the content to fill the container in a variety of ways; such as "preserve that aspect ratio" or "stretch up...
Read more >[Solved]-react native image contain empty space-React Native
<Image source={{ uri: downloadDest, scale: 1 }} style={styles.image} > </Image> image: { flex: 1, resizeMode: 'cover', //or stretch/contain backgroundColor: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@chrisglein I believe I’ve updated the snack you’ve provided to demonstrate @alishehzad2017’s issue: https://snack.expo.io/FbQZQbcVO
From my understanding, the expectation is that “contain” would preserve the aspect ratio, take 100% width, and adjust the height of the image container so it mirrors the height of the rendered image – without specifically setting a height style.
This issue is still present in the latest react native. The expectation is that images should be resized according to their aspect ratio without additional padding/margins.