2016-09-25 33 views
0

來自網絡的圖像不會始終加載,有時可以加載,有時不會加載。以下是我的渲染方法。圖像不會始終加載來自網絡的原始圖像組件

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> 
    ); 
} 

圖像在feed對象中傳遞。當父母的觸摸事件被調用時,feed對象作爲子項道具傳遞。

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> 

    ); 
} 
+0

共享代碼是用來設置webDetail –

+0

webDetail好,我總是得到有效的圖片網址,唯一的一點是它呈現的圖像某些時候,有時它不會 – Moniv

+0

您確定圖像url總是在渲染過程開始之前拍攝的。 –

回答

0

可能是一個壁畫緩存的問題,試圖通過增加一個隨機數到圖像URL使每一次的專屬網址:imageUrl + ?"+new Date().getTime()

沒有與壁畫和圖像的各種問題,像這樣的一個例子: https://github.com/facebook/react-native/issues/8677

+0

讓我試試這個解決方案 – Moniv