mockingbot / react-native-immersive

Add Toggle for Android Immersive FullScreen Layout
MIT License
131 stars 23 forks source link

immersive is disabled after opening modal or coming back from sleep #4

Closed yanush closed 7 years ago

yanush commented 7 years ago

After opening a modal window, the immersive mode is disabled. I had to reactivate it after closing the modal window. Same thing happens when the application comes back from sleep mode

ThatBean commented 7 years ago

Sorry for the late reply.

We want to keep this module simple, and keep the state of immersive mode in JavaScript. For the mode reset when application comes back from sleep mode, try using AppState like this from ReactNative Docs:

class Root extends PureComponent {
  constructor (props) {
    super (props)

    this.setImmersiveOn = () => {
      Immersive.on()
      this.setState({ isImmersive: true })
    }
    this.setImmersiveOff = () => {
      Immersive.off()
      this.setState({ isImmersive: false })
    }
    this.onAppStateChange = (nextAppState) => {
      nextAppState === 'active' && console.log('App has come to the foreground!')
      nextAppState === 'active' && this.state.isImmersive && Immersive.on()
    }

    this.state = { isImmersive: false }
  }

  componentDidMount() { AppState.addEventListener('change', this.onAppStateChange) }

  componentWillUnmount() { AppState.removeEventListener('change', this.onAppStateChange) }

  render() {
    return <View style={styles.container}>
      <Button onPress={this.setImmersiveOn} title="Immersive on" />
      <Button onPress={this.setImmersiveOff} title="Immersive off" />
    </View>
  }
}
alimek commented 7 years ago

but what about modal, it makes sense for me to reactivate it when app changed state, but what about modal ? @ThatBean

ThatBean commented 7 years ago

Haven't tried modal in our project yet. But with our experience, the Immersive Flag will get reset on:


In our case, we combine the reset with StatusBar and use something like this:

const setLayoutStatus = PLATFORM_ANDROID ? ({ isHideStatusBar = false, isImmersive = false }) => {
  __DEV__ && console.log('[setLayoutStatus]', { isHideStatusBar, isImmersive })
  StatusBar.setHidden(isHideStatusBar)
  StatusBar.setTranslucent(true)
  StatusBar.setBackgroundColor('#00000066', true)
  Immersive.setImmersive(isImmersive)
} : () => {}
alimek commented 7 years ago

OK, thanks :)

ThatBean commented 7 years ago

@yanush @alimek you might want to try react-native-immersive@1.1.0 and check out Restore Immersive State.

alimek commented 7 years ago

great :) thanks

Jacky9425 commented 5 years ago

any idea what does the immersive listener do? cause if we can use default component listeners to control the immersive flag, then why there is a immersive listener?

ghost commented 3 years ago

Hi @ThatBean Have you tried using it with Modals? I'm facing a problem when using it with Modals. Help me out please.