Skip to content

Commit 7628030

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

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

website/versioned_docs/version-3.x/common-mistakes.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,37 @@ const AppContainer = createAppContainer(AppNavigator);
112112

113113
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.
114114

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

0 commit comments

Comments
 (0)