Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set width and height to React-native modal

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

 <Modal style={{height: 300, width: 300}}
        visible={this.state.isVisible}
        onRequestClose={this.closeModal}>
 </Modal>

The code above doesn't work.

like image 770
TK-95 Avatar asked Nov 20 '16 11:11

TK-95


People also ask

How do you make a modal smaller react-native?

In your components folder, create a file called Modal. tsx and add the following code: import React from "react"; import { StyleSheet, View, Text, Button } from "react-native"; import RNModal from "react-native-modal"; type ModalProps = { isVisible: boolean; children: React.

How do you change the width of a modal?

Modal Size Change the size of the modal by adding the . modal-sm class for small modals, . modal-lg class for large modals, or . modal-xl for extra large modals.


3 Answers

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>
like image 102
max23_ Avatar answered Oct 05 '22 09:10

max23_


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

like image 23
Sathish Swaminathan Avatar answered Oct 05 '22 09:10

Sathish Swaminathan


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
    },
});
like image 41
Dibakar Halder Avatar answered Oct 05 '22 11:10

Dibakar Halder