【发布时间】:2018-08-15 03:01:58
【问题描述】:
我正在尝试在 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>
通过这种样式,我得到了这样的结果:
如果我将 flex 更改为 0,我会改为:
如何让对话框根据内容调整大小?
【问题讨论】:
-
你试过
left: 0, right: 0, top: 0, bottom: 0顶视图 -
尝试使用 react-native-modal facebook.github.io/react-native/docs/modal.html
标签: react-native flexbox react-native-flexbox