【问题标题】:Exception thrown while executing UI block when using react-native-svg使用 react-native-svg 时执行 UI 块时抛出异常
【发布时间】:2020-05-31 03:30:39
【问题描述】:

我的应用突然开始崩溃并给了我这个错误:

Exception thrown while executing UI block: -[__NSCFNumber firstObject]: unrecognized selector 
sent to instance 0xb553069cd18775de`

一段时间后,我能够隔离产生错误的部分,并发现它与从 react-native-svg 导入的 Svg 组件有关。
我尝试删除并重新安装 node_modules 并尝试重置缓存,甚至尝试从头开始创建一个新的 expo 应用程序,该应用程序除了渲染一个 Svg 组件之外什么都不做,但问题仍然存在。

在 android 上我收到不同的错误消息:

Error while updating property 'fill' of a View managed by: RNSVGGroup
null
java.Lang.Double cannot be cast to
java.Lang.String

我的代码如下所示:

import React from 'react';
import { View, StyleSheet } from 'react-native';
import { Svg } from 'react-native-svg';

const App = () =>  (
  <View style={styles.container}>
    <Svg width={100} height={100}>

    </Svg>
  </View>
);

const styles = StyleSheet.create({
  container:{
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  }
});

export default App;

【问题讨论】:

  • 同样的情况。使用“expo install”重新安装包 react-native-svg 对我有帮助。
  • 这确实为我解决了它。谢谢@JavlonTulkinov
  • 如果您使用 npm 安装它,请先使用 npm uninstall 删除软件包。然后使用@JavlonTulkinov 提到的expo install
  • 对于在react-native-svg-charts 和expo 中遇到此问题的任何人,请确保卸载react-native-svg-chartsreact-native-svg,然后先卸载expo install react-native-svg,然后再卸载npm install --save react-native-svg-charts。我为此浪费了一整天。

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


【解决方案1】:

根据 Javlon 的评论,解决方案是使用 npm uninstall react-native-svgyarn remove react-native-svg 删除软件包
然后使用 expo install react-native-svg 再次安装它

【讨论】:

    猜你喜欢
    • 2017-10-05
    • 2016-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-22
    • 2012-11-14
    相关资源
    最近更新 更多