如何在react-native中将屏幕分为两部分?

Abd*_*uya 1 flexbox react-native

我是反应原生的新手,我试图将屏幕分为两个部分,第一部分是标题或导航栏希望有一个大约 40px 的特定高度,第二部分是应用程序的主体或内容希望他的高度必须是手机屏幕上的可用高度,我尝试使用弹性框方法,但它不起作用!这是我的代码:

<View style={styles.mainContainer}>
    <View style={styles.navBar}>
    </View>
    <View style={styles.body}>
    </View>
</View>
Run Code Online (Sandbox Code Playgroud)

风格:

mainContainer: {
  height: '100%',
  display: 'flex',
  flexDirection: 'column',
},
navBar: {
  display: 'flex',
  flexDirection: 'row-reverse',
  justifyContent: 'space-between',
  alignItems: 'center',
  backgroundColor: '#f1f1f1',
  height: 30,
},
body: {
  flex: 3,
  display: 'flex',
},
Run Code Online (Sandbox Code Playgroud)

bps*_*v21 5

只需使用这种方式,我希望这会起作用。

 <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF'}}>
   <View style={{flex:1, backgroundColor:"green"}}>
    <Text>hello world 1.........</Text>
    <Text>hello world 1.........</Text>
    <Text>hello world 1.........</Text>
    <Text>hello world 1.........</Text>
    </View>
      <View style={{flex:1, backgroundColor:"yellow"}}>
    <Text>hello world 2.........</Text>
    <Text>hello world 2.........</Text>
    <Text>hello world 2.........</Text>
    <Text>hello world 2.........</Text>
    </View>
  </View>
Run Code Online (Sandbox Code Playgroud)