大家好,我想显示一个图像,但我不知道为什么,我不能显示它。我认为这是可能的,因为我用错了高度和宽度,但我正在搜索,我没有找到任何解决方案。
这是我的代码:
import React, {Component, useState, useEffect, useRef} from "react";
import {
View,
Text,
Image,
StyleSheet,
useWindowDimensions,
ScrollView,
TouchableOpacity,
Modal,
Pressable,
Alert,
TextInput,
Button,
Linking,
Animated,
LayoutAnimation,
} from "react-native";
import {Formik} from "formik";
import {useDispatch} from "react-redux";
import * as yup from "yup";
import RenderHtml from "react-native-render-html";
import AsyncStorage from "@react-native-async-storage/async-storage";
<ScrollView>
<View style={styles.descriptionPage}>
<View
style={{
alignItems: "center",
backgroundColor: "#fff",
height: "25%",
}}
>
<Pressable onPress={() => {}}>
<Image
style={{
width: "20%",
height: "20%",
}}
source={require("../../assets/images/cloche.png")}
/>
</Pressable>
<Image
style={styles.imageProduct}
source={{uri: data["image_url"]}}
/>
<TouchableOpacity
onPress={() => {
navigation.goBack();
}}
>
<Text style={styles.category}>{category}</Text>
</TouchableOpacity>
<Text style={styles.title}>{data["titre"]}</Text>
<View style={{display: "flex", flexDirection: "row", marginTop: 7}}>
<Text style={{color: "grey", top: 38}}>à partir de </Text>
<Text style={styles.price}>{data["prix"]} €</Text>
</View>
<TouchableOpacity style={{top: "10%"}} onPress={toggleText}>
<Text>Description Produit</Text>
</TouchableOpacity>
</View>
{showText && (
<ScrollView>
<Animated.View
style={{
transform: [{scaleY: scaleYInterpolation}],
height: "auto",
width: "85%",
left: "5%",
}}
>
<RenderHtml contentWidth={width} source={short_description} />
</Animated.View>
</ScrollView>
)}
<View
style={{
backgroundColor: "#EBEBEB",
right: "2%",
width: "110%",
bottom: "0.15%",
}}
>
<Text
style={{fontWeight: "bold", fontSize: 22, top: "2%", left: "5%"}}
>
{offerCpt} offres
</Text>
{offers.map((element, index) => {
const date = new Date(element["updated_at"]);
const dateOnly = date.toISOString().split("T")[0];
return (
<View style={styles.allOffer}>
<Text
style={{
color: "#ff7c00",
fontSize: 25,
paddingLeft: 10,
fontWeight: "bold",
top: 7,
}}
>
{element["prix"]} €
</Text>
<Text
style={{
paddingLeft: 10,
color: "grey",
fontSize: 11,
top: 5,
}}
>
TVA incl.
</Text>
<Text
style={{
color: "#8F8A84",
paddingLeft: 10,
fontSize: 10,
top: "15%",
width: "45%",
}}
>
Annonce valable aujourd'hui, mise à jour le : {dateOnly}
</Text>
<TouchableOpacity
onPress={() => Linking.openURL(element["url"])}
>
<Text
style={{
left: "70%",
bottom: "55%",
color: "#ff7c00",
borderRadius: 20,
fontSize: 15,
borderColor: "#ff7c00",
borderWidth: 1,
width: "25%",
textAlign: "center",
}}
>
Voir l'offre
</Text>
</TouchableOpacity>
</View>
);
})}
</View>
<View style={styles.centeredView}>
<Modal
animationType="slide"
transparent={true}
visible={modalVisible}
onRequestClose={() => {
Alert.alert("Modal has been closed.");
setModalVisible(!modalVisible);
}}
>
<View style={styles.centeredView}>
<View style={styles.modalView}>
<Pressable style={{left: "50%"}}>
<Button
style={{left: "50%", color: "black"}}
onPress={() => setModalVisible(!modalVisible)}
title="X"
color={"#ff7b0d"}
/>
</Pressable>
<Text style={{fontSize: 22, right: "25%", bottom: "5%"}}>
Prix trop élevé ?
</Text>
<Text style={styles.modalText}>Saisir le montant souhaité</Text>
<Formik
initialValues={{
targetPrice: "",
}}
validationSchema={formSchema}
onSubmit={handleSubmit}
>
{(props) => (
<View>
<TextInput
style={styles.input}
placeholderTextColor="#fff"
onChangeText={props.handleChange("targetPrice")}
value={props.values.targetPrice}
/>
<Text
style={{
fontSize: 25,
color: "#ff7b0d",
left: "90%",
}}
>
€
</Text>
<Button
color="#ff7b0d"
title="Valider"
onPress={props.handleSubmit}
/>
</View>
)}
</Formik>
</View>
</View>
</Modal>
</View>
</View>
</ScrollView>
款式:
imageProduct: {
alignSelf: "center",
width: "50%",
height: "50%",
top: "5%",
},
category: {
fontWeight: "bold",
fontSize: 15,
color: "#324160",
marginTop: 10,
},
title: {
fontWeight: "bold",
fontSize: 26,
marginTop: 10,
},
price: {
color: "#ff7b0d",
fontSize: 22,
fontWeight: "bold",
paddingLeft: 5,
},
所以,如果有人能解释一下我的"问题"在哪里。提前谢谢你,我继续在我身边。
1条答案
按热度按时间hyrbngr71#
在您的代码中,您需要给予特定的数字。或者使用具有特定百分比的Pressable(例如100%),并将您的图像包裹在其中,并将图像img {width:100%;}风格。
所以答案是你需要给予组件一个宽度