I am trying to create a feed page for an app with posts with images. Images can be different sizes, but they must either stretch or shrink to the correct width the post/screen like something you would see on facebook, or thread thumbnails on reddit.
This is an an example image that I am using: https://cdn.discordapp.com/attachments/469170673533583361/822830018794356736/1.jpg
using the following code:
Style Snippet:
postImageView : {
flex : 1,
width : '100%'
},
postImage : {
flex : 1,
resizeMode : 'stretch'
},
Component Snippet:
<View style={styles.postImageView}>
<Image source={imageList[0]} style={styles.postImage}/>
</View>
I get the following results: https://discord.com/channels/102860784329052160/469170673533583361/822829976616566785
As you can see the image is pushed up against the left side of the screen and expands well over the limits. Hard coding in the width and height can fix the size for a given image size, but does not work for different sizes.
I tested the props from https://reactnative.dev/docs/image-style-props#resizemode and most have no effect on the shape of the image.
Setting flex in the view or image or setting width to a 100% have no effect on the output.
For the full code goto: https://pastebin.com/K1QATwA5. Note that the last two imports are currently not required and so can be deleted if you decide to try and run it.