[英]How to pass props from android native code to react native
我正在尝试将一些属性从 android 本机代码 (Java) 传递给 react-native。 现在我在初始化中执行它,但稍后它将从一个函数中完成。
我通读了文档并尝试复制官方文档提交的代码,但这不起作用。
在我的 MainActivity 类中:
@Override
protected Bundle getLaunchOptions() {
Bundle initialProperties = new Bundle();
initialProperties.putString("testString", "This should be displayed now");
return initialProperties;
}
在我的 app.js 渲染方法中:
<Text>{this.props.testString}</Text>
该应用程序的其余部分工作正常,但是我在文本应该存在的地方得到了一个空白区域。 调试器说它的未定义/空
您错过了退货部分:
@Override
protected Bundle getLaunchOptions() {
Bundle initialProperties = new Bundle();
initialProperties.putString("testString", "This should be displayed now");
return initialProperties;
}
@Logan Wlv回答的内容部分正确,但您需要对其进行配置以使其使用承诺
@Override protected Bundle getLaunchOptions(promise Promise) //change here
{
Bundle initialProperties = new Bundle();
initialProperties.putString("testString", "This should be displayed
now");
return promise.resolve(initialProperties;//change here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.