From bbe656f1b8f9098518bb32e43795a927b8e15519 Mon Sep 17 00:00:00 2001 From: truph01 Date: Sat, 25 Jan 2025 11:42:19 +0700 Subject: [PATCH] fix: you've been switched to focus mode modal after open an expense on the Reports page --- src/libs/Navigation/AppNavigator/AuthScreens.tsx | 10 +++++++++- src/libs/actions/PriorityMode.ts | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index 82211eabe00f..0e2ac8746dd3 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -1,4 +1,4 @@ -import {findFocusedRoute} from '@react-navigation/native'; +import {findFocusedRoute, useNavigation} from '@react-navigation/native'; import React, {memo, useEffect, useMemo, useRef, useState} from 'react'; import {NativeModules, View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; @@ -248,6 +248,14 @@ function AuthScreens() { const isInitialLastUpdateIDAppliedToClientLoading = isLoadingOnyxValue(initialLastUpdateIDAppliedToClientStatus); const isLastOpenedPublicRoomIDLoadedRef = useRef(false); const isInitialLastUpdateIDAppliedToClientLoadedRef = useRef(false); + const navigation = useNavigation(); + + useEffect(() => { + const unsubscribe = navigation.addListener('state', () => { + PriorityMode.autoSwitchToFocusMode(); + }); + return () => unsubscribe(); + }, [navigation]); // On HybridApp we need to prevent flickering during transition to OldDot const shouldRenderOnboardingExclusivelyOnHybridApp = useMemo(() => { diff --git a/src/libs/actions/PriorityMode.ts b/src/libs/actions/PriorityMode.ts index 95042697c911..619783420be2 100644 --- a/src/libs/actions/PriorityMode.ts +++ b/src/libs/actions/PriorityMode.ts @@ -1,10 +1,13 @@ import debounce from 'lodash/debounce'; import Onyx from 'react-native-onyx'; import type {OnyxCollection} from 'react-native-onyx'; +import getIsNarrowLayout from '@libs/getIsNarrowLayout'; import Log from '@libs/Log'; +import navigationRef from '@libs/Navigation/navigationRef'; import {isReportParticipant, isValidReport} from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import SCREENS from '@src/SCREENS'; import type {Report} from '@src/types/onyx'; /** @@ -101,6 +104,15 @@ function tryFocusModeUpdate() { return; } + const currentRoute = navigationRef.getCurrentRoute(); + if (getIsNarrowLayout()) { + if (currentRoute?.name !== SCREENS.HOME) { + return; + } + } else if (currentRoute?.name !== SCREENS.REPORT) { + return; + } + // Check to see if the user is using #focus mode, has tried it before, or we have already switched them over automatically. if ((isInFocusMode ?? false) || hasTriedFocusMode) { Log.info('Not switching user to optimized focus mode.', false, {isInFocusMode, hasTriedFocusMode});