2017-04-04 31 views
1

我将反应本机整合到现有的应用程序中。我正在将自己的原生页面作为独立应用程序单独开发。是否有可能从默认道具作为arg从命令行运行反应本机应用程序?

在我现有的遗留应用程序,我叫

RCTRootView(bridge: bridge, moduleName: "AnAlert", initialProperties: someProperties)

哪里someProperties是[String: Any]类型的词典,它的JSON表示可能类似于这样的:

{"title": "Alert title", "body": "Alert body"}

我想设计独立于我的主应用程序的反应原生页面,但问题是我需要这些初始属性来完全配置页面。

有谁知道是否有可能运行react-native run-ios <option>,其中<option>是一个参数,被解释为默认props

当我运行react-native run-ios --help时,我看到了其他选项,但没有一个可以描述我想要做什么。

-h, --help output usage information --simulator [string] Explicitly set simulator to use --configuration [string] Explicitly set the scheme configuration to use --scheme [string] Explicitly set Xcode scheme to use --project-path [string] Path relative to project root where the Xcode project (.xcodeproj) lives. The default is 'ios'. --device [string] Explicitly set device to use by name. The value is not required if you have a single device connected. --udid [string] Explicitly set device to use by udid --no-packager Do not launch packager while building --config [string] Path to the CLI configuration file

谢谢!

回答

0

这里是我工作围绕这个 - 我只是编辑我的主要index.ios.js文件,并把这个顶部:文件

<Text style={styles.instructions}> 
     {defaultProps.params.foo} 
    </Text> 

if (this.props == null) { 
    var defaultProps = {"params": {"foo": "bar"}} 
} else { 
    var defaultProps = this.props 
} 

再后来现在当我通过命令行启动时,我得到了嵌入到文件中的默认值,但是当我通过RCTRootView启动时,这些调试默认值将被覆盖。

相关问题