ed9*_*133 1 flexbox react-native react-native-flexbox
我正在尝试在 React Native 中创建一个简单的内容大小的对话框。在这个层次结构中最高的,我的叠加层<View>样式如下:
{
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: '100%',
zIndex: 100,
backgroundColor: COLOR
}
Run Code Online (Sandbox Code Playgroud)
在其中,我有一个<View>具有这种风格的包装器:
{
flex: 1,
alignItems: 'center',
justifyContent: 'center'
}
Run Code Online (Sandbox Code Playgroud)
然后我有对话框<View>:
{
flex: 1,
width: '86%',
maxWidth: 450,
flexDirection: 'column',
justifyContent: 'flex-start',
alignItems: 'flex-start',
backgroundColor: 'white',
borderWidth: 5,
borderColor: 'gold'
}
Run Code Online (Sandbox Code Playgroud)
不过,问题似乎在于我构建对话框的方式:
<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>
Run Code Online (Sandbox Code Playgroud)
通过这种样式,我得到了这样的结果:
如果我更改flex为 0,我会得到以下结果:
如何使对话框的大小适合内容?
在你的对话框中根本<View>不要设置。flex像这样拥有
{
width: '86%',
maxWidth: 450,
flexDirection: 'column',
justifyContent: 'flex-start',
alignItems: 'flex-start',
backgroundColor: 'white',
borderWidth: 5,
borderColor: 'gold'
}
Run Code Online (Sandbox Code Playgroud)
如果它不起作用,您能否提供有关 Dialog 内部内容的更多代码view?
| 归档时间: |
|
| 查看次数: |
4381 次 |
| 最近记录: |