React Native中的Flexbox高度

时间:2018-03-07 05:20:21

标签: react-native flexbox react-native-flexbox

我正在尝试在React Native中创建一个简单的内容大小的对话框。在这个层次结构中最高的我有我的叠加<View>样式:

 {
   position: 'absolute',
   top: 0,
   left: 0,
   width: '100%',
   height: '100%',
   zIndex: 100,
   backgroundColor: COLOR
} 

在此范围内,我有一个具有此样式的包装器<View>

{
   flex: 1,
   alignItems: 'center',
   justifyContent: 'center'
}

然后我有对话框<View>

{
   flex: 1,
   width: '86%',
   maxWidth: 450,
   flexDirection: 'column',
   justifyContent: 'flex-start',
   alignItems: 'flex-start',
   backgroundColor: 'white',
   borderWidth: 5,
   borderColor: 'gold'
}

看起来问题在于我正在构建对话框的方式:

<View style={{flex: 1, flexDirection: 'row', justifyContent: 'flex-start', alignItems: 'flex-start'}}>
  <Image source={require('../../assets/icons/warning.png')} 
   style={{resizeMode: 'contain', height: 50, width: 48, marginRight: 30}} />
  <View style={[flex: 1, flexDirection: 'column', justifyContent: 'flex-start', alignItems: 'flex-start']}>
    <Text>{this.props.dialogMessage}</Text>
    <View style={{flex: 1, width: '100%', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'flex-start'}}>
       <Button dismissOverlay={this.props.dismissOverlay} />
    </View>
  </View>
</View>

通过这种样式,我得到了这个结果:

Huge dialog

如果我将flex更改为0,我会改为:

Clipped dialog

如何让对话框调整内容大小?

1 个答案:

答案 0 :(得分:2)

在对话框<View>中根本不设置flex。喜欢这个

{
   width: '86%',
   maxWidth: 450,
   flexDirection: 'column',
   justifyContent: 'flex-start',
   alignItems: 'flex-start',
   backgroundColor: 'white',
   borderWidth: 5,
   borderColor: 'gold'
}

如果它不起作用,您能否在Dialog view内的内容上提供更多代码?