2017-02-28 35 views
0

我是新来做出反应的,我遵循关于整合在React Native Docs中打开的现有应用程序的教程。React Native:与现有应用程序集成

private ReactRootView mReactRootView; 
....... 

Bundle launchOptions = new Bundle(); 
launchOptions.putBoolean("test", true); 
//mReactRootView.startReactApplication(mReactInstanceManager, "ThirdAwesomeComponent", launchOptions); 
mReactRootView.startReactApplication(mReactInstanceManager, "ThirdAwesomeComponent", null); // Actual example 

有没有办法在index.android.js阅读了HelloWorld组件launchOptions?

另外我有两个活动,我需要调用react native守护进程,并且想呈现服务器返回的两个不同的布局。

我如何能做到这一点,因为目前我只有一个:

​​

回答

0

做的是做这样的事情的最好方法,

重定向到App.js使用索引页

AppRegistry.registerComponent(“App”,()=> App)

这将重定向到应用程序

然后根据服务器输出渲染两个不同的场景。您可以创建一个状态变量并将其初始化为默认状态。

在您的组件的渲染功能中,您可以检查状态值并根据需要分配布局。

使用类似

export default Class App extends Component{ 
constructor(props){ 
super(props) 
this.state{ 
    data1:false, 
    data2:true, 
    loaded:false, 
} 
} 


//do all the fetching data to server here 


componentWillMount(){ 
//after fetching the data to server 

    change the state as 

    this.setState({ 
     data1:true, 
     data2:false, 
     loaded:true 
    }) 
} 


render({ 
    if(this.state.loaded && this.state.data1){ 
     return(
      //layout which you want to return 
     ) 
    }else if(this.state.loaded && this.state.data2){ 
     return(
      //second layout code 
     ) 
    }else{ 
     return(
       //can create a loading spinner here 
       <Text>Loading.....</Text> 
     ) 
    } 
    }) 
} 

希望这有助于

干杯

+0

我怎样才能改变服务器的详细信息,如从Android原生应用主机和端口号,同时呼吁 mReactRootView.startReactApplication(mReactInstanceManager,“ThirdAwesomeComponent”,launchOptions); 例如,我想改变端口为8899和主机服务器。 – Shash

+0

你是说网络服务器还是本地节点服务器?本地服务器可以改变使用http://stackoverflow.com/questions/34431052/react-native-change-listening-port我猜。我很不清楚你的服务器变化。提供更多关于您准确实施的信息的方便性? –

0

你的启动选项将被传递给您的组件作为道具的构造。 只实现构造

​​
相关问题