一些图像没有显示,链接不起作用反应原生

时间:2016-09-03 21:25:05

标签: react-native

编辑:图片问题已解决,但仍不确定链接。

好的,我有两个奇怪的问题。并提前为代码道歉。

首先,有些图像即使有效也无法显示。在我的IOS模拟器中运行时,第一个图像将不会显示。但有些图像总是有效。

第二件事,让我知道这应该是两个单独的问题,是链接到外部网站。它似乎无法在IOS中执行Linking.open。所以我想知道通过链接或其他方式在android和IOS中简单地打开外部URL最简单的方法是什么?

非常感谢!

  openUrl(url) {
    Linking.canOpenURL(url).then(supported => {
        if (supported) {
          Linking.open(url);
        } else {
          console.log('nope :: ' + url);
        }
    }).catch(err => console.error('An error occurred', err));
      // browser.open(url);
  },


  renderImage(event, index) {
      if (this.state.showBox && this.state.boxIndex == index) {
        return (
          <View>
            <TouchableHighlight onPress={()=>this._clickImage(event, index)}>
                <Image source={{ uri: event.image }} style={[styles.image, this.calculatedSize(), this.getImageStyles(event.featured), { height: 100 }]} />
            </TouchableHighlight>
            <View style={{ flexDirection:'row', padding: 15 }}>
                <Text style={styles.price}>{event.price}</Text>
                <Text style={styles.time}>{event.time}</Text>
                <TouchableHighlight onPress={()=>this.openUrl(event.website)}>
                    <Text style={styles.btn}>Website</Text>
                </TouchableHighlight>
            </View>

                {renderif(event.venue)(
                    <TouchableHighlight onPress={()=>this.openUrl(event.venue)}>
                        <Text style={styles.btn}>Venue</Text>
                    </TouchableHighlight>
                )}

          </View>
        )


      } else {
        return (
          <View>
              <TouchableHighlight onPress={()=>this._clickImage(event, index)}>
                  <Image source={{ uri: event.image }} style={[styles.image, this.calculatedSize(), this.getImageStyles(event.featured)]} />
              </TouchableHighlight>
          </View>
        )
      }
  },

1 个答案:

答案 0 :(得分:1)

这是因为您的某些图片正在尝试从http连接加载图片。\ n \ n应用程序要求您使用https进行图片处理。

例如在此

{
      title: 'test',
      image: 'http://www.piedmontpark.org/images/bird_pine_warbler_330.jpg',
      featured: true,
      category: 'Music',
      price: '$8.00',
      time: '7:00 PM-11:00 PM',
      venue: '',
      website: 'http://google.com'
  }

您的图像&#39;正试图从http加载jpg。

Check this out on how to configure your info.plist to accept http