2017-02-28 36 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

你的啓動選項將被傳遞給您的組件作爲道具的構造。 只實現構造

​​
相關問題