试图注册两个同名的视图ProgressBarAndroid [英] Tried to register two views with the same name ProgressBarAndroid
问题描述
使用 react 版本 16.0.0 和 react-native 版本 0.49.1 会引发红屏错误尝试注册两个具有相同名称的视图 ProgressBarAndroid".删除 ProgressBarAndroid 的所有导入和实例会导致程序运行良好.降级到 react-native 版本 0.48.4 也可以.如何在最新的 React Native 版本中使用 ProgressBarAndroid?
Using react version 16.0.0 with react-native version 0.49.1 raises the red screen error "Tried to register two views with the same name ProgressBarAndroid". Removing all imports and instances of ProgressBarAndroid results in a well functioning program. Downgrading to react-native version 0.48.4 works as well. How do I use ProgressBarAndroid with the latest React Native version?
推荐答案
React Native 从 0.49 版开始,如果您尝试多次调用同一组件的 requireNativeComponent()
会触发此错误.即使它们是从不同的模块调用的.
React Native starting from version 0.49 triggers this error if you are trying to call requireNativeComponent()
for same component more than once. Even if they are called from different modules.
我在自定义视图 MyCustomView
上遇到了类似的问题.所以我只是将它包装在一个模块中:
I had similar issue with custom view MyCustomView
. So I just wrapped it in a single module:
// MyCustomView.js
import {requireNativeComponent} from 'react-native'
const MyCustomView = requireNativeComponent('MyCustomView', null)
export default MyCustomView
虽然可能不是您的确切情况,但根本原因是相同的.
Though it might not be your exact case the root cause is the same.
这篇关于试图注册两个同名的视图ProgressBarAndroid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!