本文介绍了React Native - initialProperties Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在React-Native下工作,我正在寻找通过Java将初始道具传递给JS。这可以在Objective-C中使用initialProperties轻松完成,如下所示:

I'm working under React-Native and I'm looking for passing initial props to JS via Java. This can be done easily in Objective-C with initialProperties like this :

RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"myapp"
                                               initialProperties:initialProperties
                                                   launchOptions:launchOptions];

其中initialProperties是 NSDictionary 这将是转换为JSON并通过 this.props 在JS中提供。
所以我想在Android中做同样的事情。有帮助吗?谢谢

Where initialProperties is an NSDictionary which will be converted in JSON and available in JS via this.props.So I'm looking to do the same in Android. Any help ? Thanks

推荐答案

在Android中,您可以使用 initialProperties code> launchOptions 作为捆绑包。

In Android, you can pass initialProperties in with the launchOptions as a Bundle.

如源代码中所述:

所以你可以这样做:

Bundle initialProps = new Bundle();
initialProps.putString("myKey", "myValue");

mReactRootView.startReactApplication(mReactInstanceManager, "MyAwesomeApp", initialProps);

这篇关于React Native - initialProperties Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 01:04
查看更多