carsonwah / react-native-push-notification-popup

A <NotificationPopup/> component for presenting your own push notification in react-native app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hide / disable popup on certain components

nica0012 opened this issue · comments

commented

Hi, first of all thanks for a great module.

Is it possible to hide the popup sometimes, for example when you get a message notification while you're already on the messages screen / component?

Cheers.

Hi, it is up to you when you call the show() method. You need to wrap it in an if statement that checks the condition you specify, currentScreen === "messages" for example.

Hi @nica0012. For such use case, following React paradigm, I think you should put the additional logic in this.popup.show(). You may use some global stores such as Redux and MobX to store (for example) the screen you are on.

E.g.

class MyComponent extends React.Component {

  onMessage = () => {
    if (this.stores.appState.currentScreen==='MessagesPage') return;  // Don't show the popup
    this.popup.show();
  }

  render() {
    return (
      <View>
        <NotificationPopup ref={ref => this.popup = ref} />
        <MaybeYourNavigator />
      </View>
    );
  }
}

export default inject('stores')(MyComponent);