#StackBounty: #react-native #redux #react-redux #expo #expo-notifications Handle incomming notification with expo-notifications

Bounty: 50

I have a problem regarding the following code sample:

Notifications.setNotificationHandler({//makes sure notification is displayed even when app is open, nothing else
    handleNotification: async (notification) => {
        //const value = await AsyncStorage.getItem('presetlanguage');
        //console.log("ASYNC STORAGE LANGUAGE FROM OUTSIDEEEE: ", value)
        //if(notification.request.content.body == "You received a new letter from a PigeonBuddy!"){
        //    console.log("hat geklappt")
        //}
        return{
            shouldShowAlert: true
        };
    }
});

const MainScreen = props => {
    const dispatch = useDispatch();
    var chosenLanguage = useSelector(state => state.myLanguage.myLanguage); ...........

The setNotificationHandler is responsible for handling incoming notifications and therefore I want to filter my incoming notifications. For example, depending on which screen I am on, I want to either display the notification or not display it. The problem however is, I have neither access to my navigation state nor to my redux states because this handling of the notifications happens outside the default screen main function which covers all variables and which also uses props through navigations. It is forbidden to call redux hooks there and also I have no access to my navigation state because I have no access to my props variable which I get through navigation.

How can I display my notifications then depending on which screen I am on? How are companies like Facebook doing it? If you’re on a chat screen you don’t get notifications but if you are outside a notification "New message received from …" is displayed.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.