Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
React Native Expo Image Resizing

I'm using react native expo to display images of various subjects. The images I'm using have a variety of widths, heights and aspect ratios. The images themselves come from google firebase storage and are retrieved from the currently selected subjects JSON data which contains the firebase storage Image URL.

Some subjects have no images at all, which is fine however I want the content below to therefore move up, so a fixed size/aspect ratio image or view in this case is not appropriate. And as I said Images are of various heights and widths (some landscape / some portrait.

Currently the styling for the image I'm attempting is like so:

   Image: {
      height: null,
      width: "90%",
      alignSelf: 'center',
      resizeMode: 'contain'
   },

Currently with the height set to null the image is not shown at all, and the content below sits above.

The width I want fixed at 90% of the screen's width which it currently is doing, however I'm having issues with the height. I've tried setting the height at 'undefined' and also percentages '40%' etc however this is not appropriate for the subjects missing images.

Another way I have tried is placing the image inside a view like so:

      <View style={styles.ImageContainer}>
          <Image style={styles.Image} source={{ url: subject.ImageUrl }}/>
      </View>
...
// Styling:
   Image: {
      height: null,
      width: "100%", // 100% of the image container which is 90% of screen.
      alignSelf: 'center',
      resizeMode: 'contain'
   },
   ImageContainer: {
      width: '90%',
      alignSelf: 'center',
      justifyContent: 'center'
   }

What I really want to achieve is setting the image container to the size of the image height, which is resized so it fills 90% of the screens width (without skewing/stretching the image).

Is there are way of doing this within the styling or do I have to attempt using a function? I'm sure I have had success achieving this through styling in the past.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could use a minHeight for the image to make sure it shows, it should use the actual image height but setting a minimum will allow it to display.

OR

You could use Image.getSize() and use the exact height of the image. However, Image.getSize() is an async function so you would have to await it to get the size until you can display the image.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!