我无法使用style
属性来配置模态框的高度和宽度。是否有其他方法来设置模态框的高度和宽度?
<Modal style={{height: 300, width: 300}}
visible={this.state.isVisible}
onRequestClose={this.closeModal}>
</Modal>
上述代码不起作用。
我无法使用style
属性来配置模态框的高度和宽度。是否有其他方法来设置模态框的高度和宽度?
<Modal style={{height: 300, width: 300}}
visible={this.state.isVisible}
onRequestClose={this.closeModal}>
</Modal>
上述代码不起作用。
style
属性。您可以尝试在<Modal>
内部设置<View>
尺寸。<Modal transparent={true}
visible={this.state.isVisible}
onRequestClose={this.closeModal}>
<View style={{
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center'}}>
<View style={{
width: 300,
height: 300}}>
...
</View>
</View>
</Modal>
<Modal>
组件的样式中添加 margin:0
。<Modal
style={styles.modalContent}
isVisible={this.state.isVisible}
onBackdropPress={this.closeModal}
>
<Component {...componentProps} />
</Modal>
const styles = StyleSheet.create({
modalContent: {
justifyContent: 'center',
alignItems: 'center',
margin: 0
},
});
唯一解决它的方法是在 Modal 属性中传递 transparent={true}
<Modal isVisible={this.state.isModalAddCompanionVisible} >
<Button
block
style={{ marginTop: 20}}>
<Text style={{ color: "white" }} >Add Another Companion</Text>
</Button>
<View style={{backgroundColor: "white", height: 120}}>
</View>
<View style={{flexDirection: 'row'}}>
<Button
block
style={{ marginTop: 0,width: '40%'}} onPress={this._toggleModalAddCompanion.bind(this)} >
<Text style={{ color: "white" }} >Cancel</Text>
</Button>
<Button
block
style={{ marginTop: 0,width: '60%',}} >
<Text style={{ color: "white" }} >Add</Text>
</Button>
</View>
</Modal>
backgroundColor:'#00000080'
(50%不透明度的白色),并为内部视图添加纯色和填充,例如,backgroundColor:'#fff',padding:20
。 - Tim Scottstyle={{width: Dimensions.get('window').width * 0.5, height: Dimensions.get('window').height * 0.5}}
。 - panchicore