Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invariant Violation: requireNativeComponent:"***" was not found in theUIManager #28836

Closed
liyuewen opened this issue May 6, 2020 · 4 comments
Labels
Needs: Attention Issues where the author has responded to feedback. Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. Resolution: Locked This issue was locked by the bot.

Comments

@liyuewen
Copy link

liyuewen commented May 6, 2020

在MyWebViewManager.java中
`
public class MyWebViewManager extends SimpleViewManager {

public static final String REACT_CLASS = "MyWebViewManager";

@OverRide
public String getName() {
return REACT_CLASS;
}

@OverRide
protected TextView createViewInstance(ThemedReactContext reactContext) {
TextView tv = new TextView(reactContext);
tv.setText("hello from android !");
return tv;
}
}
`

在MyWebViewPackage.java中
`
public class MyWebViewPackage implements ReactPackage {

@OverRide
public List createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}

@OverRide
public List createNativeModules(
ReactApplicationContext reactContext) {
List modules = new ArrayList<>();

  modules.add(new MyWebViewManager());

  return modules;

}

}
`

在ScannerView.js中
`
import React, { Component } from 'react'
import { View, requireNativeComponent } from 'react-native'

const MyWebViewManager = requireNativeComponent('MyWebViewManager', ScannerView);

class ScannerView extends Component {
render() {
return
}
}

ScannerView.propTypes = {
...View.propTypes
}

export default ScannerView
`
在模拟器中发生错误
Invariant Violation: requireNativeComponent:"MyWebViewManager" was not found in theUIManager.

@react-native-bot react-native-bot added Needs: Author Feedback Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. and removed Needs: Triage 🔍 labels May 6, 2020
@github-actions
Copy link

github-actions bot commented May 6, 2020

⚠️ Missing Environment Information
ℹ️ Your issue may be missing information about your development environment. You can obtain the missing information by running react-native info in a console.

@liyuewen
Copy link
Author

liyuewen commented May 6, 2020

我的环境信息
System:
OS: Windows 10 10.0.17763
CPU: (8) x64 Intel(R) Core(TM) i7-4710MQ CPU @ 2.50GHz
Memory: 2.90 GB / 7.89 GB
Binaries:
Node: 10.16.3 - C:\Program Files\nodejs\node.EXE
Yarn: 1.17.3 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK:
API Levels: 23, 25, 27, 28, 29
Build Tools: 23.0.1, 27.0.3, 28.0.3, 29.0.2
System Images: android-23 | Intel x86 Atom, android-23 | Google APIs Intel x86 Atom, android-23 | Google APIs Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom
Android NDK: Not Found
IDEs:
Android Studio: Version 3.5.0.0 AI-191.8026.42.35.5791312
Languages:
Java: 1.8.0_221
Python: 2.7.12
npmPackages:
@react-native-community/cli: Not Found
react: 16.11.0 => 16.11.0
react-native: 0.62.2 => 0.62.2
npmGlobalPackages:
react-native: Not Found

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels May 6, 2020
@TheHothihi
Copy link

TheHothihi commented May 7, 2020

在MyWebViewPackage.java中, 需要將MyWebViewManager 添加到createViewManagers method之中,
如果只添加到createNativeModules method之中,只能在NativeModules中使用

`
public class MyWebViewPackage implements ReactPackage {

@OverRide
public List createViewManagers(ReactApplicationContext reactContext) {
/* 添加到createViewManagers method之後才能在requireNativeComponent中引用*/
List modules = new ArrayList<>();
modules.add(new MyWebViewManager());
return modules;
//return Collections.emptyList();
}

@OverRide
public List createNativeModules(
ReactApplicationContext reactContext) {
/* 添加到createNativeModules method之後才能在NativeModules中引用, eg.NativeModules. MyWebViewManager */
List modules = new ArrayList<>();
modules.add(new MyWebViewManager());
return modules;
}

}
`

@liyuewen
Copy link
Author

liyuewen commented May 7, 2020

在MyWebViewPackage.java中,需要将MyWebViewManager添加到createViewManagers方法之中,
如果只添加到createNativeModules方法之中,只能在NativeModules中使用

`
公共类MyWebViewPackage实现了ReactPackage {

@OverRide
public List createViewManagers(ReactApplicationContext reactContext){
/ 添加到createViewManagers方法之后才能在requireNativeComponent中引用 /
列表模块= new ArrayList <>();
modules.add(new MyWebViewManager());
返回模块;
//返回Collections.emptyList();
}

@OverRide
public List createNativeModules(
ReactApplicationContext reactContext){
/ *添加到createViewManagers方法之后才能在NativeModules中引用,例如。NativeModules。MyWebViewManager * /
列表模块= new ArrayList <>();
modules.add(new MyWebViewManager());
返回模块;
}

}
`

我已经找到问题了,是我js注册的时候发生了问题,但是还是感谢哦。

@liyuewen liyuewen closed this as completed May 7, 2020
@facebook facebook locked as resolved and limited conversation to collaborators Oct 1, 2021
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Oct 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs: Attention Issues where the author has responded to feedback. Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

3 participants