Browse Source

navigation state fix

Viktoriia 13 hours ago
parent
commit
6ba4da2254

+ 22 - 11
Route.tsx

@@ -166,7 +166,7 @@ const Route = () => {
     }
   };
 
-  function UnmountOnBlur({ children }) {
+  function UnmountOnBlur({ children }: { children: any }) {
     const isFocused = useIsFocused();
 
     if (!isFocused) {
@@ -256,11 +256,7 @@ const Route = () => {
   }) => ({
     headerShown: false,
     tabBarButton: (props: any) => (
-      <TabBarButton
-        {...props}
-        label={route.name}
-        navigation={navigation}
-      />
+      <TabBarButton {...props} label={route.name} navigation={navigation} />
     ),
     tabBarStyle: {
       ...Platform.select({
@@ -286,7 +282,10 @@ const Route = () => {
 
   const BottomTabNavigator = () => (
     <BottomTab.Navigator screenOptions={screenOptions}>
-      <BottomTab.Screen name={NAVIGATION_PAGES.IN_APP_MAP_TAB}>
+      <BottomTab.Screen
+        name={NAVIGATION_PAGES.IN_APP_MAP_TAB}
+        layout={({ children }) => <UnmountOnBlur>{children}</UnmountOnBlur>}
+      >
         {() => (
           <ScreenStack.Navigator screenOptions={screenOptions}>
             <ScreenStack.Screen name={NAVIGATION_PAGES.MAP_TAB} component={MapScreen} />
@@ -332,7 +331,10 @@ const Route = () => {
           </ScreenStack.Navigator>
         )}
       </BottomTab.Screen>
-      <BottomTab.Screen name={NAVIGATION_PAGES.IN_APP_TRAVELS_TAB}>
+      <BottomTab.Screen
+        name={NAVIGATION_PAGES.IN_APP_TRAVELS_TAB}
+        layout={({ children }) => <UnmountOnBlur>{children}</UnmountOnBlur>}
+      >
         {() => (
           <ScreenStack.Navigator screenOptions={screenOptions}>
             <ScreenStack.Screen name={NAVIGATION_PAGES.TRAVELS_TAB} component={TravelsScreen} />
@@ -395,7 +397,10 @@ const Route = () => {
           </ScreenStack.Navigator>
         )}
       </BottomTab.Screen>
-      <BottomTab.Screen name={NAVIGATION_PAGES.IN_APP_TRAVELLERS_TAB}>
+      <BottomTab.Screen
+        name={NAVIGATION_PAGES.IN_APP_TRAVELLERS_TAB}
+        layout={({ children }) => <UnmountOnBlur>{children}</UnmountOnBlur>}
+      >
         {() => (
           <ScreenStack.Navigator screenOptions={screenOptions}>
             <ScreenStack.Screen
@@ -458,7 +463,10 @@ const Route = () => {
           </ScreenStack.Navigator>
         )}
       </BottomTab.Screen>
-      <BottomTab.Screen name={NAVIGATION_PAGES.IN_APP_EVENTS_TAB}>
+      <BottomTab.Screen
+        name={NAVIGATION_PAGES.IN_APP_EVENTS_TAB}
+        layout={({ children }) => <UnmountOnBlur>{children}</UnmountOnBlur>}
+      >
         {() => (
           <ScreenStack.Navigator screenOptions={screenOptions}>
             <ScreenStack.Screen name={NAVIGATION_PAGES.EVENTS} component={EventsScreen} />
@@ -497,7 +505,10 @@ const Route = () => {
           </ScreenStack.Navigator>
         )}
       </BottomTab.Screen>
-      <BottomTab.Screen name={NAVIGATION_PAGES.IN_APP_MESSAGES_TAB}>
+      <BottomTab.Screen
+        name={NAVIGATION_PAGES.IN_APP_MESSAGES_TAB}
+        layout={({ children }) => <UnmountOnBlur>{children}</UnmountOnBlur>}
+      >
         {() => (
           <ScreenStack.Navigator screenOptions={screenOptions}>
             <ScreenStack.Screen name={NAVIGATION_PAGES.CHATS_LIST} component={MessagesScreen} />

+ 2 - 0
src/contexts/PushNotificationContext.tsx

@@ -170,6 +170,8 @@ export const PushNotificationProvider = ({ children }: { children: React.ReactNo
       Notifications.setNotificationHandler({
         handleNotification: async () => ({
           shouldShowAlert: true,
+          shouldShowBanner: true,
+          shouldShowList: true,
           shouldPlaySound: false,
           shouldSetBadge: false
         })

+ 7 - 1
src/screens/InAppScreens/MessagesScreen/utils.ts

@@ -53,7 +53,7 @@ export const dismissChatNotifications = async (
       const data = notification.request.content.data;
       if (data?.params) {
         try {
-          return JSON.parse(data.params) ?? {};
+          return JSON.parse(data?.params) ?? {};
         } catch (error) {
           console.error('Error parsing params:', error);
           return {};
@@ -98,6 +98,8 @@ export const dismissChatNotifications = async (
       if (conversation_with_user === chatWithUserId) {
         return {
           shouldShowAlert: false,
+          shouldShowBanner: false,
+          shouldShowList: false,
           shouldPlaySound: false,
           shouldSetBadge: false
         };
@@ -105,6 +107,8 @@ export const dismissChatNotifications = async (
 
       return {
         shouldShowAlert: true,
+        shouldShowBanner: true,
+        shouldShowList: true,
         shouldPlaySound: false,
         shouldSetBadge: false
       };
@@ -115,6 +119,8 @@ export const dismissChatNotifications = async (
     Notifications.setNotificationHandler({
       handleNotification: async () => ({
         shouldShowAlert: true,
+        shouldShowBanner: true,
+        shouldShowList: true,
         shouldPlaySound: false,
         shouldSetBadge: false
       })