Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native navigation cross screens notification "snackbar"

Trying to implement a "No internet" notification across alot of screens in react native using react-navigation. I'm trying to avoid adding the component to all screen views render function since it feels like boilerplate.

Is there a simple way to add a component in one place using react native navigation and have it persist in all screens?

like image 456
Cisum Inas Avatar asked Nov 19 '25 11:11

Cisum Inas


1 Answers

I think this notification doesn't have much to do with your navigation and it should be implemented outside of it. In our app we have a similar notification banner that is called outside of our Navigator and handles the display of error messages such as no connectivity.

Our App.js looks something like this:

<Provider store={store}>
        <View>
          <Message /> // message banner
          <AppNavigator /> // this is our navigation
        </View>
  </Provider>

The Message component is out of the navigation and is connected to our redux store. Every time we have an error we dispatch a redux action and display the message without going through the navigation at all.

like image 169
needsleep Avatar answered Nov 21 '25 02:11

needsleep



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!