简体   繁体   中英

Image does not load always in react native image component from network

Images from network does not load always, sometimes it do and sometimes it does not.Below is my render method.

render() {
let {title, image, text, publisher, id, date} = this.props.webDetail;
let dateString = Moment(date).format('dddd, MMMM Do YYYY');
let metaDetail = `${publisher}\n${dateString}`;

    return (
        <View style={styles.container}>
          <ScrollView showsVerticalScrollIndicator={false}>
              <Text style={styles.title}>{title}</Text>
              <Text style={styles.publisher}>{metaDetail}</Text>
              <Image
                 style={styles.image}
                 source={{ uri: image }} indicator={Progress}
              />
               <Text style={styles.text}>{text}</Text>
              {this.renderButton.call(this) }
         </ScrollView>
      </View>
    );
}

And image is passed in feed object. When parent's touch event is invoked, feed object is passed as props in child.

 renderContent(feed) {
    let dateString = Moment(feed.date).format('dddd, MMMM Do YYYY');
    let metaDetail = `${feed.publisher}\n${dateString}`;

    return (
        <ScrollView showsVerticalScrollIndicator={false}>
            <Text style={styles.title}>{feed.title}</Text>
            <Text style={styles.publisher}>{metaDetail}</Text>
            <TouchableWithoutFeedback
                onPress={this.onPress.bind(this, feed) }>
                <Image style={styles.image} key={feed.image} source={{ uri: `${feed.image}?version=outside` }} indicator={Progress} />
            </TouchableWithoutFeedback>
            <Text numberOfLines={7} style={styles.text}>{feed.description}</Text>
            <Share rank={feed.rank}/>
        </ScrollView>

    );
}

Could be a fresco caching issue, try making the url unique each time by adding a random number to the image url: imageUrl + ?"+new Date().getTime() .

There are various issues with fresco and images, like this one for example: https://github.com/facebook/react-native/issues/8677

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM