我尝试在我的应用中实现react-native-canvas。
在进入包含画布的屏幕上,在使用react-native run-ios
生成的版本中,我收到以下错误:
Invariant Violation: requireNativeComponent: "RNCWKWebView" was not found in the UIManager.
This error is located at:
in RNCWKWebView (at WebView.ios.js:297)
in RCTView (at View.js:45)
in View (at WebView.ios.js:300)
in WebView (at Canvas.js:148)
in RCTView (at View.js:45)
in View (at Canvas.js:147)
in Canvas (at LapDetails.tsx:47)
in RCTView (at View.js:45)
in View (at LapDetails.tsx:38)
in LapDetails (at ComponentWrapper.js:29)
in WrappedComponent (at renderApplication.js:34)
in RCTView (at View.js:45)
in View (at AppContainer.js:98)
in RCTView (at View.js:45)
in View (at AppContainer.js:115)
in AppContainer (at renderApplication.js:33)
getNativeComponentAttributes
a90c6db6-7158-4812-8a98-ea48c1a859f3:49643:5
<unknown>
a90c6db6-7158-4812-8a98-ea48c1a859f3:49596:14
Object.exports.get
a90c6db6-7158-4812-8a98-ea48c1a859f3:43914:20
createInstance
a90c6db6-7158-4812-8a98-ea48c1a859f3:22099:56
completeWork
a90c6db6-7158-4812-8a98-ea48c1a859f3:28453:34
completeUnitOfWork
a90c6db6-7158-4812-8a98-ea48c1a859f3:30472:32
performUnitOfWork
a90c6db6-7158-4812-8a98-ea48c1a859f3:30635:18
workLoop
a90c6db6-7158-4812-8a98-ea48c1a859f3:30645:30
renderRoot
a90c6db6-7158-4812-8a98-ea48c1a859f3:30716:13
再次进入视图时出错:
Invariant Violation: View config not found for name RNCWKWebView.
This error is located at:
in RNCWKWebView (at WebView.ios.js:297)
in RCTView (at View.js:45)
in View (at WebView.ios.js:300)
in WebView (at Canvas.js:148)
in RCTView (at View.js:45)
in View (at Canvas.js:147)
in Canvas (at LapDetails.tsx:47)
in RCTView (at View.js:45)
in View (at LapDetails.tsx:38)
in LapDetails (at ComponentWrapper.js:29)
in WrappedComponent (at renderApplication.js:34)
in RCTView (at View.js:45)
in View (at AppContainer.js:98)
in RCTView (at View.js:45)
in View (at AppContainer.js:115)
in AppContainer (at renderApplication.js:33)
Object.exports.get
ReactNativeViewConfigRegistry.js:94:6
createInstance
ReactNativeRenderer-dev.js:3946:49
completeWork
ReactNativeRenderer-dev.js:13385:25
completeUnitOfWork
ReactNativeRenderer-dev.js:15892:25
performUnitOfWork
ReactNativeRenderer-dev.js:16103:11
workLoop
ReactNativeRenderer-dev.js:16115:23
renderRoot
ReactNativeRenderer-dev.js:16219:6
performWorkOnRoot
ReactNativeRenderer-dev.js:17198:6
performWork
ReactNativeRenderer-dev.js:17099:6
现在有趣的部分。当我从XCode运行完全构建的应用程序时,我可以进入视图并显示画布。
我尝试了自动重新链接,重新安装,不同的设备和手动重新链接,因为那些提到最多的修复了此类问题。但是,用react-native run-ios
生成的版本的结果没有任何改变。
我很确定问题出在我的react-native-webview链接上,但是我不知道在哪里,我基本上做了安装指南中提到的所有事情……
我的android项目当前已损坏,因此我无法提供有关android行为的其他信息。
如果您想知道这是视图:
import React, { Component } from 'react';
import Canvas from 'react-native-canvas';
class App extends Component {
handleCanvas = (canvas) => {
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'purple';
ctx.fillRect(0, 0, 100, 100);
}
render() {
return (
<Canvas ref={this.handleCanvas}/>
);
}
}
答案 0 :(得分:2)
通常,此类问题是由不正确的链接本机依赖性引起的。您可以尝试react-native link <package name>
,但是在这种情况下似乎并非如此,因为完全构建的应用程序可以正常工作。
一些旧的构建文件会干扰开发的构建,我通过删除整个项目并再次使用git克隆来解决了这个问题。要在没有git的情况下执行此操作,您需要删除android /和ios /中的所有构建文件,并删除您的node_modules(这不是必须要做的,但是出于安全考虑)。
如果在此之后仍然遇到问题,您可能会认为第一个问题代表了您的情况,尤其是在您甚至无法编译生产版本的情况下。