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

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

Open rochapablo opened this issue 6 years ago • 9 comments

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.

rochapablo avatar Jun 13 '19 17:06 rochapablo

I think you need to assign width and height to your image

acevedo93 avatar Jun 20 '19 04:06 acevedo93

Like this?

const style: any = {
      backgroundColor: 'red',
      flex: 1,
      height: this.props.height,
      width: this.props.width,
    };

Nothing changes.

rochapablo avatar Jun 21 '19 18:06 rochapablo

I believe that StyleSheet.absoluteFill it's centering the image

rochapablo avatar Jul 05 '19 18:07 rochapablo

Hey @rochapablo did you end up solving this?

papidb avatar Dec 10 '20 13:12 papidb

I'm having the same issue, I don't want my image to center with the contain resize mode. Have you figured it out?

BrentRoberson avatar May 03 '21 20:05 BrentRoberson

Hey @rochapablo , Any update on this issue, It is really breaking design when we need to show wide images

mitesh-db avatar Aug 16 '21 04:08 mitesh-db

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.

Valeriy-Burlaka avatar Nov 24 '21 18:11 Valeriy-Burlaka

Hey @Valeriy-Burlaka, For me, Images are coming from url. I need to set every image's aspect ratio differently somehow. 🤔

mitesh-db avatar Nov 26 '21 04:11 mitesh-db

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.

No idea how, but this works! :100:

AdityaBelani avatar Apr 27 '24 06:04 AdityaBelani