2

I've hardcoded some datas and doing a map to fetch all data of my array, All datas are displaying except my image. I've tried several solution but nothing is working. When I'm using a require with a image path in string it's working but I don't find the way to display different images any idea ?

var articleData = [
    { name: "Textile motorcycle jacket", brand: "Dainese", img: "../assets/Jacket.jpg", price: '200' },
    { name: "Summer motorcycle gloves", brand: "Furygan", img: "../assets/summer_gloves.jpg", price: '30' },
    { name: "Winter motorcycle gloves", brand: "Triumph", img: "../assets/winter_gloves.jpg", price: '70' },
    { name: "Motorcycle boots", brand: "BMW", img: "../assets/boots.jpg", price: '180' },
    { name: "Goretex / waterproof pants", brand: "Dainese", img: "../assets/pants.jpg", price: '150' },
    { name: "Back and safety protection", brand: "Dainese", img: "../assets/back_protection.jpg", price: '100' },
  ]

  var ArticleList = articleData.map((article, i) => {
    return (<View  style={{ width: '47%', margin: 5 }}>

      <Image source={{uri: article.img}}  style={{ height: 250, width: 200}} />
      <View style={{ flex: 1, flexDirection: 'row', marginTop: 5, justifyContent: "space-between" }}>
        <Text style={{ fontWeight: 'bold' }}>{article.brand}</Text>
        <FontAwesome name="heart" size={20} color={colorLike} />
      </View>
      <Text>{article.name}</Text>
      <Text>{article.price}€</Text>
    </View>
    )
  }
  )

2 Answers 2

4

You could try add require in to the articleData like this

 { name: "Textile motorcycle jacket", brand: "Dainese", img: require("../assets/Jacket.jpg"), price: '200' }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it works ! , I also change my import <Image> from react-native-element to react-native.
1

You can use 'require'

 <Image source={require(article.img}  style={{ height: 250, width: 200}} />

2 Comments

Thanks for your answer ! As I explain in my previous post, I tried to use 'require' and it's work but only for ONE line of my array, not for all of my datas. As I read in react native documentation ' require' is expecting a string so <Image source={require(article.img)} is not working. Any other idea ? I was thinking it may be a conflict between react native and react native element ( I'm both using it )
use require in dummy data, for exaple; { name: "Goretex / waterproof pants", brand: "Dainese", img: require("../assets/pants.jpg"), price: '150' },

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.