Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rochapablo opened this issue Jun 13, 2019 · 9 comments
Open

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

rochapablo opened this issue Jun 13, 2019 · 9 comments
Labels

Comments

@rochapablo
Copy link

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 rochapablo added the bug label Jun 13, 2019
@acevedo93
Copy link

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

@rochapablo
Copy link
Author

Like this?

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

Nothing changes.

@rochapablo
Copy link
Author

rochapablo commented Jul 5, 2019

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

@papidb
Copy link

papidb commented Dec 10, 2020

Hey @rochapablo did you end up solving this?

@BrentRoberson
Copy link

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

@mitesh-db
Copy link

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

@Valeriy-Burlaka
Copy link

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.

@mitesh-db
Copy link

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

@AdityaBelani
Copy link

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! 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
7 participants