Pass props through CreateAppContainer
You have to scope the props under screenProps
to be able to access it at the screen
level.
// App.js
<AppNavigator
screenProps={{
handler: () => {},
hello: "World"
}}
/>
// Navigator.js
const StackNavigator = createStackNavigator({
Login: {
screen: ({ screenProps, navigation }) => {
screenProps.handler();
// ...
},
},
})
Okay, I got this to work with help of Samuel Vaillant. I had to make couple of modifications.
My App.js:
render() {
return (
this.state.isLoggedIn ? <DrawerNavigator /> : <SignedOutNavigator
screenProps={{
handler: (settings) => { this.saveUserSettings(settings) }
}}
/>
)
}
My SignedOutNavigator:
import React from "react";
import { View, Text } from "react-native";
import { createStackNavigator, createAppContainer } from "react-navigation";
import LoginScreen from "../screens/LoginScreen";
const SignedOutNavigator = createStackNavigator({
Login: {
// screen: LoginScreen
screen: screenProps => <LoginScreen screenProps={value => {
screenProps.screenProps.handler(value)
}} />,
navigationOptions: ({ navigation }) => ({
header: null,
}),
}
});
export default createAppContainer(SignedOutNavigator);