1. 程式人生 > >原生初始化時initialProperties向StackNavigator screen傳值

原生初始化時initialProperties向StackNavigator screen傳值

1.原生initialProperties

 

Bundle bundle=new Bundle();

bundle.putString(RNConstants.RN_INIT_SERVER_KEY,serverKey);

bundle.putString(RNConstants.RN_INIT_UA,ua);

mReactRootView.startReactApplication(mReactInstanceManager, moduleName, bundle);

 

2.使用screenProps接收

const App = StackNavigator({

SplashScreen: { screen: SplashScreen},

ProfileScreen: {screen: ProfileScreen},

});

 

class GlobalConfig extends React.Component{

render(){

return <App screenProps={this.props}/>

}

}

 

AppRegistry.registerComponent('android', () => GlobalConfig);

 

3.screen中使用

return (

<View style={styles.container}>

<Text style={styles.hello}>native initialProps is {JSON.stringify(this.props.screenProps)}</Text>

</View>

);

參考:https://github.com/react-navigation/react-navigation/issues/876

demo地址:https://github.com/RightOfHand/NativeRMaven