android跳转到rn界面,React-Native 如何实现原生页面跳转到 rn 页面

一个 React-Native Android 的项目,启动之后是一个用 js 写的登录页面(login.js),然后我会跳转到一个 android 原生的页面(NativeActivity.java),然后我现在希望从这个原生的页面跳转到另一个 js 的页面(other.js)。

我现在的做法是给 other.js 做了一个原生的容器 OtherActivity.java,部分代码是这样的:

public class OtherActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler {

private ReactRootView mReactRootView;

private ReactInstanceManager mReactInstanceManager;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

mReactRootView = new ReactRootView(this);

mReactInstanceManager = ReactInstanceManager.builder()

.setApplication(getApplication())

.setCurrentActivity(this)

.setBundleAssetName("index.android.bundle")

.setJSMainModulePath("index")

.addPackage(new MainReactPackage())

.setUseDeveloperSupport(BuildConfig.DEBUG)

.setInitialLifecycleState(LifecycleState.RESUMED)

.build();

mReactRootView.startReactApplication(mReactInstanceManager, "other", null);

setContentView(mReactRootView);

}

然后在 NativeActivity.java 中我使用以下方法跳转:

Intent i = new Intent(NativeActivity.this, OtherActivity.class);

startActivity(i);

在 index.js 中,我在原有基础上追加了一行代码:

AppRegistry.registerComponent('other', () => Other)

但是这样没办法从 NativeActivity.java 跳转到 other.js,我查了一下有人用

ReactActivityDelegate#getLaunchOptions

的方法实现从原生页跳转 rn 页的时候,通过传递不同的参数来实现 react-native 渲染不同的组件,但是没有什么思路,请问如何实现这部分跳转呢

950-390_%E7%94%BB%E6%9D%BF-1.jpg

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值