Skip to content

Commit 197a7b3

Browse files
napalm272brentvatne
authored andcommitted
Update common-mistakes.md for wrapping AppContainer in View without flex (react-navigation#402)
See github issue: react-navigation/react-navigation#5651
1 parent 7d00821 commit 197a7b3

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

docs/common-mistakes.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,41 @@ const AppContainer = createAppContainer(AppNavigator);
111111

112112
In previous version of React Navigation, the library used to dig through your component tree to find `navigationOptions`. This is no longer the case, and only `navigationOptions` on screen components of a particular navigator will apply to that navigator. You can read more about this in the [Navigation options resolution](navigation-options-resolution.html) guide.
113113

114+
## Wrapping AppContainer in a View without flex
115+
116+
If you wrap the `AppContainer` in a `View`, make sure the `View` is using flex.
117+
```javascript
118+
import React from 'react';
119+
import { Text, View } from 'react-native';
120+
import { createBottomTabNavigator, createAppContainer } from 'react-navigation';
121+
122+
class HomeScreen extends React.Component {
123+
render() {
124+
return (
125+
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
126+
<Text>Home!</Text>
127+
</View>
128+
);
129+
}
130+
}
131+
132+
class SettingsScreen extends React.Component {
133+
render() {
134+
return (
135+
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
136+
<Text>Settings!</Text>
137+
</View>
138+
);
139+
}
140+
}
141+
142+
const TabNavigator = createBottomTabNavigator({
143+
Home: HomeScreen,
144+
Settings: SettingsScreen,
145+
});
146+
147+
const AppContainer = createAppContainer(TabNavigator)
148+
149+
// without the style you will see a blank screen
150+
export default ()=><View style={{flex: 1}}><AppContainer/></View>;
151+
```

0 commit comments

Comments
 (0)