I have one app in React Native and I’m trying to introduce an image in my app, but the image it’s to big and the image takes up the entire screen. To fix that, I tried
imagem:{
flex: 1,
width: null,
height: null,
resizeMode: 'contain'
}
The image itself is at a good size, but the component it’s to larger, so it’s harder to see the other components.
The full script is here:
import { StatusBar } from 'expo-status-bar';
import React, { useState } from 'react';
import { SafeAreaView, StyleSheet, Text, View, Button, Image } from 'react-native';
export default function App() {
return (
<SafeAreaView style={estilos.container}>
<View>
<Text>Cara ou Coroa</Text>
<Image style={estilos.imagem} source={moedaAtual}/>
<Button
title='Girar'
onPress={()=>{}}
/>
</View>
</SafeAreaView>
);
}
const estilos = StyleSheet.create({
container:{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
imagem:{
flex: 1,
width: null,
height: null,
resizeMode: 'contain'
}
});
2
Answers
You can remove the flex: 1 property from the estilos.imagem
Set
width
to 100% andheight
to fixed size (to leave space for other components) and then either contain or cover forresizeMode
to get the desired result.