Set width and height to React-native modal

前端 未结 4 1802
我寻月下人不归
我寻月下人不归 2021-01-31 02:21

I can\'t configure modal height and width using style property. Is there any other way to set modal height and width?

 

        
相关标签:
4条回答
  • 2021-01-31 02:37

    The following worked for me after i have tried other methods

    <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>
    
    0 讨论(0)
  • 2021-01-31 02:43

    According to the Modal documentation, there is no style prop to be set.

    You can try setting the <View> dimensions inside the <Modal> instead:

    <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>
    
    0 讨论(0)
  • 2021-01-31 02:45

    In the Modal documentation it is not mentioned it but it has a style property.

    The following works for me.

    <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
        },
    });
    
    0 讨论(0)
  • 2021-01-31 02:55

    Try adding margin:0 in the style of the <Modal> Component

    0 讨论(0)
提交回复
热议问题