Estoy tratando de cambiar el tamaño de una imagen (más pequeña para ajustarse a la pantalla) en mi aplicación nativa de reacción, pero no puedo hacerlo porque es demasiado grande.
Aquí está el código:
'use strict'; var React = require('react-native'); var { StyleSheet, Text, TextInput, View, TouchableHighlight, ActivityIndicatorIOS, Image, Component } = React; var styles = StyleSheet.create({ description: { marginBottom: 20, fontSize: 18, textAlign: 'center', color: '#656565' }, container: { padding: 30, marginTop: 65, alignItems: 'center' }, flowRight: { flexDirection: 'row', alignItems: 'center', alignSelf: 'stretch' }, buttonText: { fontSize: 18, color: 'white', alignSelf: 'center' }, button: { height: 36, flex: 1, flexDirection: 'row', backgroundColor: '#48BBEC', borderColor: '#48BBEC', borderWidth: 1, borderRadius: 8, marginBottom: 10, alignSelf: 'stretch', justifyContent: 'center' }, searchInput: { height: 36, padding: 4, marginRight: 5, flex: 4, fontSize: 18, borderWidth: 1, borderColor: '#48BBEC', borderRadius: 8, color: '#48BBEC' }, image: { width: 200, height: 220 }, }); class SearchPage extends Component { render() { return ( <View style={styles.container}> <Image source={require('image!rclogo')} style={styles.image}/> <Text style={styles.description}> Search for RCers! </Text> <Text style={styles.description}> Search </Text> <View style={styles.flowRight}> <TextInput style={styles.searchInput} placeholder='Search by Batch, Name, Interest...'/> <TouchableHighlight style={styles.button} underlayColor='#99d9f4'> <Text style={styles.buttonText}>Go</Text> </TouchableHighlight> </View> <TouchableHighlight style={styles.button} underlayColor='#99d9f4'> <Text style={styles.buttonText}>Location</Text> </TouchableHighlight> </View> ); } }Traté de sacarlo de la etiqueta del contenedor, pero parece que no puedo entender por qué no se representa correctamente.
¿Se puede hacer esto con flexbox resizeMode? ¿Cómo lo haces? No puedo encontrar ningún documento al respecto ...
la imagen corrige automáticamente la vista
image: { flex: 1, width: null, height: null, resizeMode: 'contain' }Ajusto un poco tu respuesta (shixukai)
image: { flex: 1, width: 50, height: 50, resizeMode: 'contain' }Cuando lo configuro en nulo, la imagen no se mostrará en absoluto. Me puse en cierto tamaño como 50
Esto funcionó para mí:
image: { flex: 1, aspectRatio: 1.5, resizeMode: 'contain', }la relación de aspecto es solo ancho/alto (mi imagen tiene 45 px de ancho x 30 px de alto).