question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Android]Modal becomes invalid state when power button is pressed.

See original GitHub issue

Environment

Run react-native info in your terminal and paste its contents here.

Environment:
  OS: macOS High Sierra 10.13.4
  Node: 8.3.0
  Yarn: 1.6.0
  npm: 5.6.0
  Watchman: 4.7.0
  Xcode: Xcode 9.4.1 Build version 9F2000
  Android Studio: 3.1 AI-173.4819257

Packages: (wanted => installed)
  react: 16.3.1 => 16.3.1
  react-native: 0.55.4 => 0.55.4

Description

This issue only confirmed in Android 7.x Pressing power button when Modal component is displayed causes invalid state of Modal. I see Modal contents disappears but its transparent background remains after Pressing power button again and screens turns on.

With Android 6.x or 8.x, Both modal contents won’t be hidden with the same operation.

screenshot_1529650789

Reproducible Demo

The code is almost same as Modal official document

https://github.com/satoshikumano/RN-Modal-Test

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

1reaction
satoshikumanocommented, Aug 2, 2018

Workaround Snippet:

import React, { Component } from 'react'
import { AppState, Platform, Modal } from 'react-native'

const isAndroid7 = Platform.OS === 'android' && (Platform.Version === 24 || Platform.Version === 25)

export default class ModalContainer extends Component<{}> {
  state = {
    appState: AppState.currentState
  }

  componentDidMount () {
    if (isAndroid7) {
      AppState.addEventListener('change', this.handleAppStateChange)
    }
  }

  componentWillUnmount () {
    if (isAndroid7) {
      AppState.removeEventListener('change', this.handleAppStateChange)
    }
  }

  handleAppStateChange = (nextAppState) => {
    this.setState({ appState: nextAppState })
  }

  render () {
    let { visible } = this.props
    const { appState } = this.state
    visible = isAndroid7 ? (visible && appState === 'active') : (visible)
    return (
      <Modal
       visible={visible}
        animationType='none'
        transparent={true}
      >
        {this.props.children}
      </Modal>
    )
  }
}
0reactions
stale[bot]commented, Dec 11, 2018

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent a dialog from closing when a button is clicked
You will need to set this in the onResume() method because getButton() will return null until after the dialog has been shown!
Read more >
Close modal when android back button pressed #115 - GitHub
I have the problem when keyboard is shown. In that case callback passed to onBackButtonPress is only fired on second back button press...
Read more >
androidx.compose.material - Android Developers
Executes when the user tries to dismiss the Dialog by clicking outside or pressing the back button. This is not called when the...
Read more >
OnePlus 7 Pro fingerprint BiometricPrompt does not show
Modal is maintained with ability to cancel by touching outside of modal or by actual 'cancel' button. With modal retained - 'retry' is...
Read more >
Top 18 Most Common AngularJS Developer Mistakes - Toptal
Common Mistake #5: Not Using Named Views With UI-ROUTER For Power”. The de facto routing solution for AngularJS has been, until now, the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found