Load custom native component in react native using expo kit(使用 expo kit 在 react native 中加载自定义原生组件)
问题描述
我正在尝试加载自定义 Android WebView 以便能够使用 html 文件输入上传文件(默认情况下,Android webview 不会与输入文件一起使用).
总结问题是我的自定义原生组件没有被 React Native 读取.有人可以帮帮我吗?
Expo 默认不支持任何自定义原生模块.这是因为它们只有一个 perbuilt 二进制文件,并且只加载您编写的 JS 包.因此,您使用 Expo 编写的任何代码都只能是纯 Javascript.但是 Expo 文档确实说您可以在分离后添加自定义本机模块.更多信息在这里:
https://docs.expo.io/版本/最新/指南/detach.html#should-i-detach
https://docs.expo.io/versions/latest/introduction/faq.html#what-is-the-difference-between-expo-and-react-native
https://github.com/expo/expo/issues/56
Im trying to load a custom Android WebView to be able to upload files using html file inputs (by default Android webview wont work with input file). Im using this code, the only difference is that im using expo kit, so my MainApplication.java is different (inherits from another class by default):
public class MainApplication extends MultiDexApplication {
// Needed for `react-native link`
public List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new CustomWebViewPackage()
);
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
Basically what the git code do is override the default react native webview to make it use the CustomWebView.java in Android, using requireNativeComponent with this code (this is on CustomWebView.android.js):
var RCTWebView = requireNativeComponent('CustomWebView', WebView, {
nativeOnly: {
messagingEnabled: PropTypes.bool,
},
});
But when i run the application using exp start and navigate to the screen that has the CustomWebView i receive this error:
Summarizing the problem is that my custom native component is not being read by React Native. Can someone help me please?
Expo by default will not support any custom native modules. This is because they have a single perbuilt binary and they only load the JS bundle that you write. So any code you write with Expo can only be pure Javascript. But Expo documentation does say that you can add custom native modules after detaching. More info here:
https://docs.expo.io/versions/latest/guides/detach.html#should-i-detach
https://docs.expo.io/versions/latest/introduction/faq.html#what-is-the-difference-between-expo-and-react-native
https://github.com/expo/expo/issues/56
这篇关于使用 expo kit 在 react native 中加载自定义原生组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 expo kit 在 react native 中加载自定义原生组件
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01