Skip to content

Image resizeModes contain & center render incorrectly on Android #17684

Description

@motiz88

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

I don't have the CLI set up, or rather, I don't know how to invoke it from a local Git copy of react-native. For the sake of complying with the issue template, my environment is:

Environment:
OS: macOS High Sierra 10.13.2
Node: 8.9.3
Yarn: 1.3.2
npm: 5.5.1
Watchman: 4.7.0
Xcode: Xcode 9.0.1 Build version 9A1004
Android Studio: 3.0.1 AI-171.4443003

Packages:
react-native at latest master (431670f)
react: 16.2.0 => 16.2.0

Target Platform: Android (I am running 7.0 on Genymotion)

Steps to Reproduce

  1. Run RNTester on both iOS and Android.
  2. Go to the <Image> page on both and scroll down to the "Resize Mode" section.
  3. Observe the difference between the rendering of the contain images on both, for the case where the image is larger than its view.
  4. Observe the similarly broken rendering of center (which is an Android-only value of resizeMode)

Expected Behavior

resizeMode="contain"

The image should be scaled down to fit the view in a "letterboxed" manner, leaving empty space at the top and bottom in this case. See documentation:

contain: Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).

And see correct behaviour on iOS:

resizeMode="center"

(See also: #17759)

No corresponding iOS screenshot, and the documentation currently omits this value. However, it's clear from the actual behaviour (see below) that there is a bug, similar to the contain case.

Actual Behavior

On Android, for both resizeMode="contain" and resizeMode="center", the shrunk image (bottom set of examples, blue background) seems to be drawn on top of an incorrectly scaled or unscaled copy of itself:

Reproducible Demo

Reproducible in RNTester as-is. I can also put together a Snack if that helps.

Activity

  1. RidaRidss commented on Jan 24, 2018

    @RidaRidss

    import ImageResizer from "react-native-image-resizer";

    // first upload image with resizing using below block of code

    if (image_uri) {
    ImageResizer.createResizedImage(image_uri, 800, 600, "JPEG", 100)
    .then(resizedImage => {
    this.setState({
    image: resizedImage.uri
    });
    })
    .catch(err => {
    console.log(err);
    });
    }

    // show image after resize

    <Image
    style={{
    // marginTop: 20,
    width: Metrics.image.tiny,
    height: Metrics.image.tiny
    }}
    source={Images.next}
    resizeMode="contain"
    />

  2. motiz88 commented on Jan 24, 2018

    @motiz88
    ContributorAuthor

    @RidaRidss that looks like a reasonable workaround for these resizeMode issues; there's also ImageManipulator for Expo users. However, this issue is about the behaviour of <Image> itself.

  3. motiz88 commented on Jan 27, 2018

    @motiz88
    ContributorAuthor

    After a bit of digging, this is likely due to the Fresco/Android caveat discussed in facebook/fresco#153 and http://frescolib.org/docs/rounded-corners-and-circles.html#caveats.

  4. added
    Ran CommandsOne of our bots successfully processed a command.
    StaleThere has been a lack of activity on this issue and it may be closed soon.
    on Feb 24, 2018
  5. removed
    StaleThere has been a lack of activity on this issue and it may be closed soon.
    on Feb 24, 2018
  6. deleted a comment from react-native-bot on Jun 12, 2018
  7. reopened this on Jun 12, 2018
  8. kimthangatm commented on Aug 18, 2018

    @kimthangatm

    I get sample error, because I forgot style Image with width and height

    {image && (
      <Image
        source={image}
        style={{
          width: 188,
          height: 188,
          position: 'absolute',
          resizeMode: 'contain',
        }}
      />
    )}
  9. stale commented on Nov 16, 2018

    @stale

    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 "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

  10. added
    StaleThere has been a lack of activity on this issue and it may be closed soon.
    on Nov 16, 2018
  11. stale commented on Nov 23, 2018

    @stale

    Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

  12. locked as resolved and limited conversation to collaborators on Nov 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Ran CommandsOne of our bots successfully processed a command.StaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions