Skip to content

Commit 275688e

Browse files
authored
Merge pull request Expensify#88237 from Expensify/jules-fixHybridGpsSwitchWarning
Fix silent Switch-to-Classic when GPS trip is in progress
2 parents 45d6ada + 38ea9c0 commit 275688e

3 files changed

Lines changed: 57 additions & 5 deletions

File tree

src/components/GPSInProgressModal/index.native.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function GPSInProgressModal() {
1515
const stopGpsAndSwitchToOD = async () => {
1616
setIsGPSInProgressModalOpen(false);
1717
await stopGpsTrip(isOffline);
18-
closeReactNativeApp({shouldSetNVP: true, isTrackingGPS: false});
18+
closeReactNativeApp({shouldSetNVP: true, isTrackingGPS: false, shouldIgnoreTryNewDotLoading: true});
1919
};
2020

2121
return (

src/libs/actions/HybridApp/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import HybridAppModule from '@expensify/react-native-hybrid-app';
22
import Onyx from 'react-native-onyx';
33
import type {OnyxEntry} from 'react-native-onyx';
44
import Navigation from '@libs/Navigation/Navigation';
5-
import {shouldBlockOldAppExit} from '@libs/TryNewDotUtils';
5+
import {isLockedToNewApp, shouldBlockOldAppExit} from '@libs/TryNewDotUtils';
66
import {setIsGPSInProgressModalOpen} from '@userActions/isGPSInProgressModalOpen';
77
import CONFIG from '@src/CONFIG';
88
import ONYXKEYS from '@src/ONYXKEYS';
@@ -83,8 +83,14 @@ function getHybridAppSettings(): Promise<HybridAppSettings | null> {
8383
});
8484
}
8585

86-
function closeReactNativeApp({shouldSetNVP, isTrackingGPS}: {shouldSetNVP: boolean; isTrackingGPS: boolean}) {
87-
if (shouldBlockOldAppExit(currentTryNewDot, isLoadingTryNewDot, shouldSetNVP)) {
86+
type CloseReactNativeAppParams = {
87+
shouldSetNVP: boolean;
88+
isTrackingGPS: boolean;
89+
shouldIgnoreTryNewDotLoading?: boolean;
90+
};
91+
92+
function closeReactNativeApp({shouldSetNVP, isTrackingGPS, shouldIgnoreTryNewDotLoading = false}: CloseReactNativeAppParams) {
93+
if (isLockedToNewApp(currentTryNewDot)) {
8894
return;
8995
}
9096

@@ -93,6 +99,10 @@ function closeReactNativeApp({shouldSetNVP, isTrackingGPS}: {shouldSetNVP: boole
9399
return;
94100
}
95101

102+
if (!shouldIgnoreTryNewDotLoading && shouldBlockOldAppExit(currentTryNewDot, isLoadingTryNewDot, shouldSetNVP)) {
103+
return;
104+
}
105+
96106
Navigation.clearPreloadedRoutes();
97107
if (CONFIG.IS_HYBRID_APP) {
98108
Onyx.merge(ONYXKEYS.HYBRID_APP, {closingReactNativeApp: true});

tests/unit/HybridAppActionsTest.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type HybridAppModuleWithClose = {
1919
};
2020

2121
type HybridAppActionsModule = {
22-
closeReactNativeApp: (params: {shouldSetNVP: boolean; isTrackingGPS: boolean}) => void;
22+
closeReactNativeApp: (params: {shouldSetNVP: boolean; isTrackingGPS: boolean; shouldIgnoreTryNewDotLoading?: boolean}) => void;
2323
};
2424

2525
describe('HybridApp actions', () => {
@@ -62,6 +62,26 @@ describe('HybridApp actions', () => {
6262
expect(closeNativeAppSpy).not.toHaveBeenCalled();
6363
});
6464

65+
it('opens the GPS OldApp handoff modal while tryNewDot is loading', async () => {
66+
await Onyx.set(ONYXKEYS.IS_LOADING_APP, true);
67+
await waitForBatchedUpdatesWithAct();
68+
69+
closeReactNativeApp({shouldSetNVP: true, isTrackingGPS: true});
70+
71+
expect(setIsGPSInProgressModalOpen).toHaveBeenCalledWith(true);
72+
expect(closeNativeAppSpy).not.toHaveBeenCalled();
73+
});
74+
75+
it('opens the GPS OldApp handoff modal once switching to OldApp is allowed', async () => {
76+
await Onyx.set(ONYXKEYS.IS_LOADING_APP, false);
77+
await waitForBatchedUpdatesWithAct();
78+
79+
closeReactNativeApp({shouldSetNVP: true, isTrackingGPS: true});
80+
81+
expect(setIsGPSInProgressModalOpen).toHaveBeenCalledWith(true);
82+
expect(closeNativeAppSpy).not.toHaveBeenCalled();
83+
});
84+
6585
it('allows shouldSetNVP exits once tryNewDot resolves without a mobile lock', async () => {
6686
await Onyx.set(ONYXKEYS.IS_LOADING_APP, false);
6787
await waitForBatchedUpdatesWithAct();
@@ -72,6 +92,28 @@ describe('HybridApp actions', () => {
7292
expect(closeNativeAppSpy).toHaveBeenCalledWith({shouldSetNVP: true});
7393
});
7494

95+
it('allows the GPS modal confirmation to switch after tryNewDot loading blocked the original action', async () => {
96+
await Onyx.set(ONYXKEYS.IS_LOADING_APP, true);
97+
await waitForBatchedUpdatesWithAct();
98+
99+
closeReactNativeApp({shouldSetNVP: true, isTrackingGPS: false, shouldIgnoreTryNewDotLoading: true});
100+
101+
expect(Navigation.clearPreloadedRoutes).toHaveBeenCalled();
102+
expect(closeNativeAppSpy).toHaveBeenCalledWith({shouldSetNVP: true});
103+
});
104+
105+
it('keeps the GPS modal confirmation blocked when the user is locked to NewApp', async () => {
106+
await Onyx.set(ONYXKEYS.NVP_TRY_NEW_DOT, {
107+
isLockedToNewApp: true,
108+
});
109+
await waitForBatchedUpdatesWithAct();
110+
111+
closeReactNativeApp({shouldSetNVP: true, isTrackingGPS: false, shouldIgnoreTryNewDotLoading: true});
112+
113+
expect(Navigation.clearPreloadedRoutes).not.toHaveBeenCalled();
114+
expect(closeNativeAppSpy).not.toHaveBeenCalled();
115+
});
116+
75117
it('blocks shouldSetNVP false exits when the user is locked to NewApp', async () => {
76118
await Onyx.set(ONYXKEYS.NVP_TRY_NEW_DOT, {
77119
isLockedToNewApp: true,

0 commit comments

Comments
 (0)