React Native Transparent Modal Issue: Solution Needed

Recently, I encountered a problem with using a Modal to disable interactions on a screen while keeping everything visible. Oddly enough, it was working perfectly fine before, but when I attempted to turn the Modal into its own component, things took a turn for the worse. Even after reverting back to my original setup, the issue persisted. Perhaps I should have committed my code when it was functioning correctly.

Any insights on where I might have gone wrong?

Below is the snippet of 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,
  },

Answer №2

Experiment with using transparent={true} when rendering the <Modal /> component.

Answer №3

<Modal transparent></Modal>

It is important to note that this functionality only works with the presentation style set to "overFullScreen."

If you try to use other options, you may encounter an error similar to the following:

Modal with 'formSheet' presentation style and 'transparent' value is not supported

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Avoid directing to the identical component within a React application

When I try to redirect my component to the same component with different parameters, it is not working properly. <BrowserRouter basename={process.env.REACT_APP_DEFAULT_PATH ?? ''}> <Switch> ... < ...

Challenges with file types in the build directory of a React Express application

My website was running smoothly until yesterday, but now I am encountering some issues. It is a React app built with Express and NodeJS. While the website works fine in development mode using yarn start, I am facing errors in production: GET https://www.m ...

HTML5 generates a div element that is not editable using CSS

I am facing an issue with some HTML code I have. Here is the structure: <ion-content> <ion-tab> The problem arises when the DOM is generated, as the HTML5 tag creates a div element that I am unable to modify using CSS. It ends up looking ...

When using React.js, clicking on an answer option will change the color of all options, not just the one that was clicked

I'm currently working on my quiz page where all answer options change color when clicked. However, I only want the selected answer option to be colored based on its correctness. The data is being retrieved from a data.json array. export default functi ...

React developer server is failing to automatically refresh the code

I've encountered an issue with react-dev-server where changes I make to the code do not reflect on the app itself even after refreshing (not hot-loading). I've tried setting up my own project as well as using Facebook's Create-react-app, whi ...

Trim the name property of an object within an object's map function if it exceeds a certain length

Imagine having an object structured like this: var fullObj = { prop1: "myProp1", subobject: { Obj1_id: { id: "Obj3_id", name: "./", otherProperties:... }, Obj2_id: { id: "Obj2_id&q ...

What is the process for modifying the characteristics of an RMWC Component?

How can I dynamically change the icon attribute in my RMWC Button element when an onClick event occurs? <Button outlined icon={<CircularProgress />} onClick={(e)=> { // e.currentTarget.icon = ''; // console.log(e.c ...

Adjusting Flexbox Sidebar to Match Content Height

I'm facing an issue with my layout where the sidebar sometimes becomes taller than the page body, extending beyond the screen height and continuing to expand vertically. Here's a snippet of my code structure: <div class="fb-col"> < ...

Can the viewport width be captured and stored in a MySQL database using jQuery, and subsequently retrieved in PHP without needing to reload the page?

Appreciate you taking the time to go through this... I have a question regarding hidden content with CSS. As far as I know, hidden content still loads but remains hidden. Instead of using media queries to control the visibility of the content based on the ...

The functionality of WrapAll is not functioning properly in React JS

$('p').wrapAll($('<div class="wrapper"></div>')); .wrapper { background: #EEE; margin: 10px; padding: 5px; border: 1px solid black; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery. ...

A full-width CSS menu featuring dropdowns beneath each entry for easy navigation

Check out the JSFiddle here I've created a full-width CSS menu that spans the entire screen, but I'm struggling to figure out how to make the corresponding subnav items appear below their parent items. Is it even possible to achieve this design ...

Unable to implement a theme with Material UI's ThemeProvider and createTheme features

I encountered a compile error that kept failing: There was an import error: 'createTheme' is not exported from '@material-ui/core/styles'. Here is the code snippet: import React, { Suspense, lazy } from "react"; import &quo ...

Display the toggle button for expanding/collapsing text only when the length of the string exceeds 50 characters

Is there a way to only show a "read more/less" button in a table if the content exceeds 50 characters? The table contains a mix of content, some short announcements with about 10 characters and others with over 100. <div class="col"> <span ng-c ...

Can Vue.js be affected by cascading updates?

Presentations by Tom Occhino and other React speakers have discussed how Angular's 2-way bindings can lead to cascading updates, making it challenging to understand. These issues with Angular are unfamiliar to me since I haven't worked with it be ...

What is the best way to retrieve the data from this date object?

How can I access the date and time in the code below? I've attempted using functions within the Text block without success. It's unclear to me what mistake I'm making or how to correctly access this object, or transform it into an object th ...

What is the process for manually testing a TypeScript function within a React application?

Hey there, I have a question as a beginner. I am currently using React and TypeScript with create-react-app, and I have some JavaScript code that is not related to the user interface (it's a module for working with a REST API). Here is an example of w ...

Transitioning the Background Image is a common design technique

After spending hours trying to figure out how to make my background "jumbotron" change images smoothly with a transition, I am still stuck. I have tried both internal scripts and JavaScript, but nothing seems to work. Is there any way to achieve this witho ...

Position the vertical bar directly adjacent to the form input field

Looking for assistance with creating a unique webpage layout that includes a form where the employee ID is visually separated from the rest of the content by a vertical bar extending across the entire page. However, my attempts to achieve this using a gr ...

Having trouble with TypeScript error in React with Material-UI when trying to set up tabs?

I have developed my own custom accordion component hook, but I am encountering the following error export default const Tabs: OverridableComponent<TabsTypeMap<{}, ExtendButtonBase<ButtonBaseTypeMap<{}, "button">>>> Check ...

JSX tags without any inner content should be self-closed

After successfully running this code, I encountered an issue when committing it to git. The error message 'ERROR: src/layouts/index.tsx:25:9 - JSX elements with no children must be self-closing' appeared. I attempted to resolve the error by addi ...