I fetch some images from Facebook API and I want to display them responsive, to be 100% width and auto height. The problem seems to be that React Native crops my image.
I tried these solutions:
Also, I have tried to use react-native-auto-height-image and set it’s width to the screen’s one.
Actual code:
<TouchableOpacity onPress={() => Linking.openURL(post.url)}>
<Card style={{ flex: 1 }}>
<CardItem>
<Left>
<Thumbnail source={ThumbnailImage} />
<Body>
<Text>My text</Text>
<Text note>{createdTime}</Text>
</Body>
</Left>
</CardItem>
<CardItem>
<Body>
<AutoHeightImage
width={Dimensions.get('window').width - 35}
source={{ uri: post.media.image.src }}
/>
<Text style={{ marginTop: 10 }}>{post.description}</Text>
</Body>
</CardItem>
</Card>
</TouchableOpacity>
PS: Application is using Native Base as a UI library.
2
Answers
I think that to solve this problem is simple, you could use
Dimensions
to set the width and height of the image with the width of the screen, like bellow:https://snack.expo.io/ryuCvY8cX
This problem can easily solve by using paddingTop, width, and position. Just try below code.
In the above code, change width and paddingTop as per the required image box size.