【问题标题】:Redirection fails : react-native-svg : React.createElement: type is invalid重定向失败:react-native-svg:React.createElement:类型无效
【发布时间】:2020-08-18 12:37:19
【问题描述】:

我试图理解一个错误。当我将我的第一个屏幕重定向到另一个屏幕时,我会进入捆绑程序:

“警告:React.createElement:类型无效——需要一个字符串 (对于内置组件)或类/函数(对于复合 组件)但得到:%s.%s%s,对象,”

我猜问题出在 svg 包上 - 当我点击时:

      <TouchableOpacity onPress={() => this.props.navigation.navigate("Distance")}>
        <View style={styles.statContainer}>
          <ImageBackground
            source={require("../../assets/images/stats-background-1.png")}
            style={styles.statImage}
          >
            <View style={styles.row}>
              <Text style={styles.statText}>
                {i18n.t("stats.action.dist")}
                {"\n"}
                <AnimateNumber
                  value={this.state.stats.total_distance}
                  countBy={(this.state.stats.total_distance / 50).toFixed(0)}
                  style={styles.statTextData}
                />{" "}
                {i18n.t("stats.unit.kilometre")}
              </Text>
            </View>
          </ImageBackground>
        </View>
      </TouchableOpacity>

第二屏的代码是:

export default class Stats extends React.Component {
  constructor(props) {
    super(props);
    };

  render() {
    return (
    <ScrollView style={styles.containerScrollNoMargins}>
      <Header
        backgroundImage={require("../../assets/images/bg-header.png")}
        centerComponent={{
          text: i18n.t("stats.title"),
          style: styles.headerComponentStyle,
        }}
        containerStyle={styles.headerContainerStyle}
        statusBarProps={{ barStyle: "light-content" }}
      />
      <ImageBackground
        source={require("../../assets/images/background-stats.jpg")}
        style={{flex : 1 }}
        imageStyle={{ resizeMode: 'stretch' }}
      >
         <Svg height="50%" width="50%">
             <Image href={require('../../assets/images/Interface_Stat_1.svg')} />
        </Svg>
      </ImageBackground>
    </ScrollView>
    );
  }
}

我不明白是什么错误,你能给我任何提示,任何帮助吗? 非常感谢您的时间和解释。

【问题讨论】:

    标签: react-native svg expo react-native-svg


    【解决方案1】:

    这似乎失败了,因为您在SVG 标记内使用了RN 的Image 组件。

    它只支持list中的儿童,而Image只支持png, jpg, jpeg, bmp, gif, webp, psdhere中提到的一些格式。要解决这个问题,您可以查看react-native-svg-transformer,它将帮助您轻松导入本地 svg 文件。

    【讨论】:

    • 非常感谢,我还有一个错误,但感谢您,我更好地理解了它的工作方式,谢谢。
    猜你喜欢
    • 1970-01-01
    • 2017-10-16
    • 2018-02-07
    • 2020-10-02
    • 2017-12-23
    • 2018-05-18
    • 1970-01-01
    • 1970-01-01
    • 2021-07-04
    相关资源
    最近更新 更多