【问题标题】:SVG picture not showing in react nativeSVG图片未在本机反应中显示
【发布时间】:2021-06-20 01:02:49
【问题描述】:

有人可以帮我理解为什么这个 svg 没有渲染到我的屏幕上吗?

  const fireee = this.state.h.map(e => { 
          <SvgUri
    width="10%"
    height="10%"
    uri="https://s3.us-east-2.amazonaws.com/nomics-api/static/images/currencies/btc.svg"
  /> }
      )

      return (    

<View>
{fireee}
</View>

【问题讨论】:

  • const fireee = this.state.h.map((e) => { if (e.logo_url.includes('svg')) { console.log(e.logo_url); return ( ); } else { return ( ) } });

标签: javascript reactjs react-native svg react-hooks


【解决方案1】:

试试这个:

<View>
  <SvgUri
    width="10%"
    height="10%"
    source={{ uri: "https://s3.us-east-2.amazonaws.com/nomics-api/static/images/currencies/btc.svg"}} 
  />
</View>

【讨论】:

  • 是的,我希望它可以使用地图工作,因为会有多个
  • 您可以将映射的链接存储到一个变量并使用 FlatList 来显示您的内容
【解决方案2】:
const fireee = this.state.h.map((e) => {
      if (e.logo_url.includes('svg')) {
        console.log(e.logo_url);
        return (
          <SvgUri
    width="3%"
    height="3%"
    
    uri={e.logo_url}/>
        );
      } else {
        return (
           <Image
            source={{ uri: e.logo_url }}
            style={{ width: 20, height: 20, left: '20%' }}
          />
        )
      }
    });

需要创建一个条件来处理 svg 和 png 的不同

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-21
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多