0

I'm new to react and I followed the tutorial about integrating existing apps open in the React Native Docs.

private ReactRootView mReactRootView;
.......

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

Is there a way to read launchOptions in the HelloWorld Component at index.android.js?

Also I have two activities from where I need to call the react native daemon and want to render two different layouts returned by the server.

How can I do that since currently I only have one:

AppRegistry.registerComponent('HelloWorld', () => HelloWorld);
wmcbain
  • 1,099
  • 9
  • 16
Shash
  • 11
  • 3

2 Answers2

0

The best way to do is doing something like,

Redirect to App.js from the index page using

AppRegistry.registerComponent("App",()=>App)

This will redirect to app

Then for rendering two different scenes based on server output. You can create a state variable and initialize it to be the default state.

in the render function of you component you can then check the state value and assign the layout as per your necessity.

Use something like

  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>
         )
     }
  })
}

Hope this helps

Cheers

Ujjwal Nepal
  • 546
  • 5
  • 13
  • How can I changes server details like host and port number from Android native App while calling mReactRootView.startReactApplication(mReactInstanceManager, "ThirdAwesomeComponent", launchOptions); for instance I want to change port to 8899 and host server on that. – Shash Mar 01 '17 at 09:09
  • Are you saying a web server or a local node server? Local server can be changed using http://stackoverflow.com/questions/34431052/react-native-change-listening-port I guess. I am quiet unclear about your changing server thing. Is it convenient to provide more information on what you are exactly trying to implement? – Ujjwal Nepal Mar 01 '17 at 15:18
0

Your launching options will be passed to the constructor of your component as props. Just implement the constructor

constructor(props){
  super(props)
  // do stuff to pops dictionary
}