Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Modal Transparent Not Working

So I want to use a Modal to disable all interactions on a screen but I still want everything on the screen to be visible. It's odd because it was working just fine for me earlier, then I tried to make the Modal its own component, but as soon as I did that, it stopped working properly. I then went back to what I originally did but still having the same issue. I should've committed it when it worked.

Any idea where I went wrong?

Here's my code:

import React, { Component } from 'react';
import { View, Image, Modal, Text, Button, TouchableHighlight } from 'react-native';

  constructor(props) {
    super(props);
    this.state = {
      modalVisible: true,
    };
  }

  openModal() {
    this.setState({modalVisible: true});
  }

  closeModal() {
    this.setState({modalVisible: false});
  }



  render() {
      return (
        <View style={styles.container}>
          <Modal
            visible={this.state.modalVisible}
            onRequestClose={() => this.closeModal()}
          >
            <TouchableHighlight
            style={styles.modalContainer}
            onPress={() => this.closeModal()}
            >
              <Text>"Words n stuff"</Text>
            </TouchableHighlight>
          </Modal>
          <View
            style={styles.upperContainer}
          />
          <View
            style={styles.lowerContainer}
          />
        </View>
      );
    }
  }
}

Styles:

 modalContainer: {
    flexGrow: 1,
    justifyContent: 'center',
    flexDirection: 'row',
    backgroundColor: 'transparent',
  },


 container: {
    flexGrow: 1,
    justifyContent: 'space-around',
    flexDirection: 'column',
    alignItems: 'center',
  },
  upperContainer: {
    flexGrow: 2,
    alignItems: 'center',
    justifyContent: 'flex-end',
    paddingBottom: 18,
    width: screenWidth,
    marginTop: -140,
  },
lowerContainer: {
    flexGrow: 2,
    alignItems: 'center',
    justifyContent: 'space-around',
    width: screenWidth,
  },
like image 237
Dres Avatar asked Feb 16 '18 16:02

Dres


People also ask

How make react-native modal transparent?

Transparent is used to make the modal transparent. For example if we pass transparent={true} prop to the modal then it will make the Modal transparent. Because by default modal has a White background on it and not shows the back of application.

How do you style modal in 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 I show and hide modal in react-native?

This state is used to Show and Hide the modal component in react native. const [isVisible, setVisible] = useState(false); 4. Creating return() block, Here we would make our main Modal component with visible prop and assign isVisible State to visible prop.

How do I use popup in react-native?

To use PopupDialog we have to install react-native-popup-dialog package. This command will copy all the dependencies into your node_module directory. –save is optional, it is just to update the react-native-popup-dialog dependency in your package. json file.


2 Answers

Try transparent={true} on <Modal />

like image 22
Alessandro Macanha Avatar answered Sep 27 '22 17:09

Alessandro Macanha


Try to add transparentproperty to your Modal.

Example:

<Modal
  transparent
  ...>
...
</Modal>

Doc: https://facebook.github.io/react-native/docs/modal.html#transparent

like image 178
Théo dvn Avatar answered Sep 27 '22 15:09

Théo dvn