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

resizeMode=“contain” takes up space of the original image

Open alishehzad2017 opened this issue 3 years ago • 11 comments

Description

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:

Screenshot for Stack Overflow

alishehzad2017 avatar Jul 25 '20 14:07 alishehzad2017

:warning: Using Old Version
:information_source: It looks like you are using an older version of React Native. Please upgrade to the latest version, and verify if the issue persists. If it does not, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the current release.

github-actions[bot] avatar Aug 05 '20 17:08 github-actions[bot]

:warning: Missing Reproducible Example
:information_source: It looks like your issue is missing a reproducible example. Please provide a Snack or a repository that demonstrates the issue you are reporting in a minimal, complete, and reproducible manner.

github-actions[bot] avatar Aug 05 '20 17:08 github-actions[bot]

Isn't the expected meaning of contain? If you want the image to fill you'd want cover or stretch (depending on whether you want to preserve aspect ratio or not). https://reactnative.dev/docs/image#resizemode

It'd be helpful to put together a Snack like this one to demonstrate your issue in context: https://snack.expo.io/@chrisglein/repro29491

chrisglein avatar Aug 05 '20 17:08 chrisglein

@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.

ahtierney avatar Aug 05 '20 17:08 ahtierney

I'm not positive what the expectation is. The documentation for height implies it should behave like CSS. But if you look at react-native-web in that Snack... it doesn't display the un-heighted items at all (behaving differently from iOS and Android). And if I put together the CSS equivalent of what I think this React Native markup intends, it behaves similarly (put together a fiddle here).

It makes sense to me that an image should infer the unspecified dimensions from the source image... but I don't actually know where that's specified. Do you?

chrisglein avatar Aug 07 '20 20:08 chrisglein

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

stale[bot] avatar Dec 26 '20 01:12 stale[bot]

ImageBackground does the trick for me

ezrogha avatar Mar 25 '21 09:03 ezrogha

please suggest the answer

Biplovkumar avatar Sep 03 '21 12:09 Biplovkumar

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

stale[bot] avatar Jan 09 '22 12:01 stale[bot]

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.

wouterh-dev avatar Dec 07 '22 15:12 wouterh-dev

This issue is still present in the latest react native.

xApep avatar Jan 11 '23 15:01 xApep

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

github-actions[bot] avatar Apr 12 '23 12:04 github-actions[bot]

This issue was closed because the author hasn't provided the requested feedback after 7 days.

github-actions[bot] avatar Apr 19 '23 18:04 github-actions[bot]

did this just get ignored until the bot closed it? Even though plenty of others commented to say it was still an issue...

iain-neirfeno avatar Mar 05 '24 20:03 iain-neirfeno