Skip to content

[Image] Add a resizeMode named 'fit' #2296

Closed

Description

@aleclarson

The new resizeMode would work similar to cover, but if the raw image dimensions are ever larger than both the Image width and height, it shrinks the image to fit at least one edge to the expected dimensions.

# The width/height of the raw image.
[ 1000, 1000 ]

# The width/height of the Image component.
[ 320, 200 ]

# If the resizeMode is set to 'cover', the large raw image is kept as is.
# This results in an unacceptable amount of information getting cropped off.
[ 1000, 1000 ]

# If the resizeMode is set to 'fit', the large raw image is scaled
# down to fit as much content as possible without leaving whitespace.
[ 320, 320 ]

Activity

  1. ide commented on Aug 11, 2015

    @ide
    Contributor

    "cover" should probably do what you're saying, and needs to support scaling down. This probably isn't very hard to add if someone wants to submit a PR.

    cc @nicklockwood @a2.

  2. nicklockwood commented on Aug 11, 2015

    @nicklockwood
    Contributor

    Yeah, this looks like it's just a bug in the resizing logic. I'll take a look at fixing it.

  3. cyprusglobe commented on Aug 11, 2015

    @cyprusglobe

    👍

  4. janmonschke commented on Aug 27, 2015

    @janmonschke
    Contributor

    👍

  5. christopherdro commented on Sep 13, 2015

    @christopherdro
    Contributor

    @aleclarson Maybe I'm missing something but shouldn't setting resizeMode to contain do what your asking?

    See: https://rnplay.org/apps/Vw3tCA

  6. satya164 commented on Jan 19, 2016

    @satya164
    Contributor

    Related #4031

  7. nicklockwood commented on Jan 19, 2016

    @nicklockwood
    Contributor

    I don't know specifically if/when this was fixed, but nobody else has reported it on iOS, so I assume cover is working correctly. Issue #4031 relates to Android, which I suspect is unrelated to this issue since it predates the Android release :-)

  8. satya164 commented on Jan 19, 2016

    @satya164
    Contributor

    @nicklockwood Yeah, just commented because the Android issue can refer to this one. Should have done the other way around :D

  9. aleclarson commented on Jul 13, 2016

    @aleclarson
    ContributorAuthor

    We could use a resizeMode that:

    • scales down when the image is larger than the frame
    • doesn't scale up when the image is smaller than the frame

    This would help with centering an icon within a button.

    Another solution would be a resizeMode that uses the image dimensions and centers the image within the frame (that is, no resizing ever occurs). It looks like UIViewContentModeCenter would work on iOS, not sure about Android.

    The current workaround is to:

    • set style.width and style.height of the Image to the exact size of the .png
    • wrap the Image in a View that centers its children using justifyContent and alignItems

    The workaround has a couple caveats:

    • needs both an Image and View (instead of just an Image)
    • must define the width and height explicitly (which means knowing the image size)
  10. aleclarson commented on Jul 14, 2016

    @aleclarson
    ContributorAuthor

    Oh, just realized that fb8340d is already in master! I'm using 0.22.2 at the moment. 👍

  11. aleclarson commented on Jul 14, 2016

    @aleclarson
    ContributorAuthor

    Oh, it looks like that only provides Android support. I guess I'll make a pull request that adds iOS support.

  12. ghost added a commit that references this issue on Jul 19, 2016
  13. locked as resolved and limited conversation to collaborators on Jul 22, 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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions