question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When resizeMode.contain is it possible not "center" the image?

See original GitHub issue

Describe the bug I’m not sure if this is a bug, but following the code and image bellow, I notice that there’s always a white space between the image, like the image it’s been centered some how. I tried flex alignments but noting seems to work.

Using resizeMode.contain I got the white spaces; using resizeMode.cover I loose a little of the width.

The white space increase as the image gets taller (huge height).

To Reproduce Follow the code:

<FastImage
    style={{ flex: 1 }}
    source={{
        priority: FastImage.priority.normal,
        uri: this.props.src
    }}
    resizeMode={this.props.resizeMode || FastImage.resizeMode.contain}
/>

Expected behavior The image should not have those white spaces at top and bottom of the element <FastImage.

Screenshots Imgur

Dependency versions

  • React Native version: 0.59.9
  • React version: 16.8.3
  • React Native Fast Image version: 6.0.3

Note: if these are not the latest versions of each I recommend updating as extra effort will not be taken to be backwards compatible, and updating might resolving your issue.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:6
  • Comments:8

github_iconTop GitHub Comments

5reactions
Valeriy-Burlakacommented, Nov 24, 2021

I just faced the same issue, - an image with resizeMode="contain" gets centered and ignored the justifyContent="flex-end" setting of the outer container. I managed to “fix” this by setting both width and height of the image to undefined and also specifying its aspectRatio, just like this:

    <View
      style={
          justifyContent: 'flex-end',
        }}
    >
      <Image
        source={require('./img/source.png')}
        style={{
          // This is as strange as it gets. The `flex-end` setting works _only_ if I pass the image's aspect ratio
          // and `undefined` for width and height properties. If any of these are missing, the image with `resizeMode="contain"
          // will be centered vertically and ignore the `justifyContent` setting of the outer container.
          aspectRatio: 0.5622, // In my case
          width: undefined,
          height: undefined,
          resizeMode: 'contain',
        }}
      />
    </View>

Hope this may help somebody.

2reactions
papidbcommented, Dec 10, 2020

Hey @rochapablo did you end up solving this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding “resizeMode” in React Native | by Mehran Khan
There are different options in Image “reiszeMode” ('cover', 'contain', 'stretch', 'repeat', 'center'). It can be tricky which one to use if you does...
Read more >
Image - React Native
center : Center the image in the view along both dimensions. If the image is larger than the view, scale it down uniformly...
Read more >
resizeMode=“contain” takes up space of the original image
The image is 800*487. Setting aspectRatio: 800/487 or height: '60%' inside styles.image does not solve the problem.
Read more >
CSS object-fit Property - W3Schools
none - The image is not resized; scale-down - the image is scaled down to the smallest version of none or contain. Using...
Read more >
How do I top align an image? - Thunkable Community
Picture resize mode = Contain** Screen's Vertical Alignment = Top. and the result is that - Image is getting placed in Center of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found