Search code examples
react-nativereact-native-elements

react native elements image component do not show image when using variable


I using the react-native-elements library to design my app and I want to create my product details page all data I passed whit props come true and but when I want to set image URI the image component shows nothing but when I put the URL as string manually it shows the Image

image URL: https://boho-box.com/storage/upload/product/IMG_1696_1609848185.jpg

Item.js file:

import * as React from 'react';
import { View, Text, StyleSheet, ActivityIndicator } from 'react-native';
import { Card, Button, Image } from 'react-native-elements';
import { useNavigation } from '@react-navigation/native';

function Item(props){

 const navigation = useNavigation();

 return(
   <View>
      <Image
         style={styles.image}
         source={{ uri: props.pDetail.img }}
         PlaceholderContent={<ActivityIndicator />}
       />
      <Text>{props.pDetail.title}</Text>
      <Text>Price: ${props.pDetail.price}</Text>
      <Text>{props.pDetail.img}</Text>
   </View>
 );
}

const styles = StyleSheet.create({
  row: {
      flex: 1,
      flexDirection: 'row',
      justifyContent: 'center',
  },
  col: {
      flex: 1,
  },
  image: {
    width: 200,
    height: 200,
  }
});

export default Item;

page screenshot when using source={{ uri: props.pDetail.img }} :

enter image description here

page screenshot when using source={{ uri: 'https://boho-box.com/storage/upload/product/IMG_1696_1609848185.jpg' }} :

enter image description here

It happens too when I using the react-native image component.

Detail.js :

import * as React from 'react';
import { View, Text, Button } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import Item from './components/Item';


function DetailsScreen({ route, navigation }) {

  const { name, price, img } = route.params;

  const detail = {
    title: JSON.stringify(name),
    price: JSON.stringify(price),
    img:   JSON.stringify(img),
  }

  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Item pDetail={detail} />
    </View>
  );
}

export default DetailsScreen;

Solution

  • change the detail const in Detail.js file to:

    JSON.stringify put image path between the " "

    const detail = {
        title: JSON.stringify(name),
        price: JSON.stringify(price),
        img:   img,
      }