React Native Android:显示来自Java的活动 [英] React Native Android: Showing an Activity from Java
问题描述
我需要在React-native中显示一个Activity(Native android,Java)。
我知道它已被问过几次,但没有人帮助过我。我没有找到任何关于如何在React-Native中调用/打开活动的教程或文档。在哪里放置活动以及如何注册/添加到项目。
I need to show an Activity ( Native android, Java ) in React-native. I know it have been asked few times, But none helped me. I didn't find any tutorial or documentations on how to call/open the activity in React-Native. where to put the activity and how to register/add it to project.
是否有任何教程或示例代码?
Is there any tutorial or sample code?
我正在使用react-native-camera,当我从RN运行它时,它显示了来自rn-camera的视图,我查看了它的源代码,但它没有活动。
I'm using react-native-camera , when i run it from RN, it shows a view from rn-camera, i looked into it's source code but it doesn't have an Activity.
如果您可以确定哪些模块的react-native正在使用活动,那么它也可以提供帮助。 (在本机反应中显示一个android活动)。
If you could tell which modules for react-native are using activities it could help as well. (showing an android activity in react native).
有一些关于如何添加本机现有android项目的文档,但我找不到任何有关如何使用的指南从android导入一个活动。
There is some documentations on how to add react native to existing android projects but i couldn't find any guide on how to import an activity from android.
我非常感谢你的帮助。
推荐答案
希望我能正确理解你的问题:
你想要的是从javascript代码中显示一个Activity(java代码)。
Hope I understand your issue correctly: What you want is to show an Activity (java code) from javascript code.
我建议你实现本机模块: https://facebook.github.io /react-native/docs/native-modules-android.html
I would suggest to implement a native module: https://facebook.github.io/react-native/docs/native-modules-android.html
原生模块是java和javascript之间的桥梁。因此,如果你的原生模块有这个:
Native module is a bridge between java and javascript. So if your native module has this:
@Override
public String getName() {
return "YourModule";
}
@ReactMethod
public void showYourActivity() {
Intent intent = new Intent(mContext, YourActivity.class); // mContext got from your overriden constructor
getCurrentActivity().startActivity(intent);
}
然后在你的js代码中:
then in your js code:
import {NativeModules} from 'react-native';
NativeModule.YourModule.showYourActivity();
希望有所帮助。您也可以在它们之间传输数据,请查看文档。
hope that helps. You also can transfer data between them as well, please check at the document.
这篇关于React Native Android:显示来自Java的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!