Skip to content

Commit 1fe610e

Browse files
committed
Merge branch 'implement-hybrid-version-of-get-initial-url' into fix-reload-on-new-sign-in-page
# Conflicts: # src/Expensify.tsx # src/components/ScreenWrapper/index.tsx
2 parents bdf8365 + b7a719a commit 1fe610e

6 files changed

Lines changed: 15 additions & 58 deletions

File tree

src/ROUTES.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,18 +2585,6 @@ const ROUTES = {
25852585
TEST_TOOLS_MODAL: 'test-tools',
25862586
} as const;
25872587

2588-
/**
2589-
* Proxy routes can be used to generate a correct url with dynamic values
2590-
*
2591-
* It will be used by HybridApp, that has no access to methods generating dynamic routes in NewDot
2592-
*/
2593-
const HYBRID_APP_ROUTES = {
2594-
MONEY_REQUEST_CREATE: '/request/new/scan',
2595-
MONEY_REQUEST_CREATE_TAB_SCAN: '/submit/new/scan',
2596-
MONEY_REQUEST_CREATE_TAB_MANUAL: '/submit/new/manual',
2597-
MONEY_REQUEST_CREATE_TAB_DISTANCE: '/submit/new/distance',
2598-
} as const;
2599-
26002588
/**
26012589
* Configuration for shared parameters that can be passed between routes.
26022590
* These parameters are commonly used across multiple screens and are preserved
@@ -2610,7 +2598,7 @@ const SHARED_ROUTE_PARAMS: Partial<Record<Screen, string[]>> = {
26102598
[SCREENS.WORKSPACE.INITIAL]: ['backTo'],
26112599
} as const;
26122600

2613-
export {HYBRID_APP_ROUTES, getUrlWithBackToParam, PUBLIC_SCREENS_ROUTES, SHARED_ROUTE_PARAMS};
2601+
export {getUrlWithBackToParam, PUBLIC_SCREENS_ROUTES, SHARED_ROUTE_PARAMS};
26142602
export default ROUTES;
26152603

26162604
type AttachmentsRoute = typeof ROUTES.ATTACHMENTS.route;
@@ -2658,6 +2646,4 @@ type RoutesValidationError = 'Error: One or more routes defined within `ROUTES`
26582646
// eslint-disable-next-line @typescript-eslint/no-unused-vars
26592647
type RouteIsPlainString = AssertTypesNotEqual<string, Route, RoutesValidationError>;
26602648

2661-
type HybridAppRoute = (typeof HYBRID_APP_ROUTES)[keyof typeof HYBRID_APP_ROUTES];
2662-
2663-
export type {HybridAppRoute, Route};
2649+
export type {Route};

src/components/ScreenWrapper/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function ScreenWrapper(
171171
const {initialURL} = useContext(InitialURLContext);
172172
const [hybridApp] = useOnyx(ONYXKEYS.HYBRID_APP, {canBeMissing: true});
173173

174-
usePreventRemove((hybridApp?.isSingleNewDotEntry ?? false) && initialURL === Navigation.getActiveRouteWithoutParams(), () => {
174+
usePreventRemove((hybridApp?.isSingleNewDotEntry ?? false) && !!initialURL?.endsWith(Navigation.getActiveRouteWithoutParams()), () => {
175175
if (!CONFIG.IS_HYBRID_APP) {
176176
return;
177177
}

src/libs/Navigation/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import type {AttachmentModalScreenParams} from '@pages/media/AttachmentModalScre
1919
import type CONST from '@src/CONST';
2020
import type {Country, IOUAction, IOUType} from '@src/CONST';
2121
import type NAVIGATORS from '@src/NAVIGATORS';
22-
import type {Route as ExpensifyRoute, HybridAppRoute, Route as Routes} from '@src/ROUTES';
22+
import type {Route as ExpensifyRoute, Route as Routes} from '@src/ROUTES';
2323
import type SCREENS from '@src/SCREENS';
2424
import type EXIT_SURVEY_REASON_FORM_INPUT_IDS from '@src/types/form/ExitSurveyReasonForm';
2525
import type {CompanyCardFeed} from '@src/types/onyx';
@@ -1978,7 +1978,7 @@ type SharedScreensParamList = {
19781978
shortLivedToken?: string;
19791979
authTokenType?: ValueOf<typeof CONST.AUTH_TOKEN_TYPES>;
19801980
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
1981-
exitTo?: Routes | HybridAppRoute;
1981+
exitTo?: Routes;
19821982
shouldForceLogin: string;
19831983
domain?: Routes;
19841984
delegatorEmail?: string;
@@ -1987,7 +1987,7 @@ type SharedScreensParamList = {
19871987
accountID: string;
19881988
validateCode: string;
19891989
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
1990-
exitTo?: Routes | HybridAppRoute;
1990+
exitTo?: Routes;
19911991
};
19921992
};
19931993

src/libs/actions/Report.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3429,6 +3429,10 @@ function openReportFromDeepLink(url: string) {
34293429
return;
34303430
}
34313431

3432+
if (isAuthenticated) {
3433+
return;
3434+
}
3435+
34323436
// Check if the report exists in the collection
34333437
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
34343438
// If the report does not exist, navigate to the last accessed report or Concierge chat

src/libs/actions/Session/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import * as Welcome from '@userActions/Welcome';
5757
import CONFIG from '@src/CONFIG';
5858
import CONST from '@src/CONST';
5959
import ONYXKEYS from '@src/ONYXKEYS';
60-
import type {HybridAppRoute, Route} from '@src/ROUTES';
60+
import type {Route} from '@src/ROUTES';
6161
import ROUTES from '@src/ROUTES';
6262
import SCREENS from '@src/SCREENS';
6363
import type {TryNewDot} from '@src/types/onyx';
@@ -1182,18 +1182,18 @@ function waitForUserSignIn(): Promise<boolean> {
11821182
});
11831183
}
11841184

1185-
function handleExitToNavigation(exitTo: Route | HybridAppRoute) {
1185+
function handleExitToNavigation(exitTo: Route) {
11861186
InteractionManager.runAfterInteractions(() => {
11871187
waitForUserSignIn().then(() => {
11881188
Navigation.waitForProtectedRoutes().then(() => {
11891189
Navigation.goBack();
1190-
Navigation.navigate(exitTo as Route);
1190+
Navigation.navigate(exitTo);
11911191
});
11921192
});
11931193
});
11941194
}
11951195

1196-
function signInWithValidateCodeAndNavigate(accountID: number, validateCode: string, twoFactorAuthCode = '', exitTo?: Route | HybridAppRoute) {
1196+
function signInWithValidateCodeAndNavigate(accountID: number, validateCode: string, twoFactorAuthCode = '', exitTo?: Route) {
11971197
signInWithValidateCode(accountID, validateCode, twoFactorAuthCode);
11981198
if (exitTo) {
11991199
handleExitToNavigation(exitTo);
Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,10 @@
11
import HybridAppModule from '@expensify/react-native-hybrid-app';
22
import {Linking} from 'react-native';
3-
import {generateReportID} from '@libs/ReportUtils';
43
import CONFIG from '@src/CONFIG';
5-
import CONST from '@src/CONST';
6-
import type {HybridAppRoute, Route} from '@src/ROUTES';
7-
import ROUTES, {HYBRID_APP_ROUTES} from '@src/ROUTES';
8-
9-
// In HybridApp, URLs might come from OldDot in an unsupported format, so we transform them into a format that is supported by NewDot.
10-
function parseHybridAppUrl(url: HybridAppRoute | Route): Route {
11-
switch (url) {
12-
case HYBRID_APP_ROUTES.MONEY_REQUEST_CREATE_TAB_MANUAL:
13-
return ROUTES.MONEY_REQUEST_CREATE_TAB_MANUAL.getRoute(CONST.IOU.ACTION.CREATE, CONST.IOU.TYPE.SUBMIT, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, generateReportID());
14-
case HYBRID_APP_ROUTES.MONEY_REQUEST_CREATE_TAB_DISTANCE:
15-
return ROUTES.MONEY_REQUEST_CREATE_TAB_DISTANCE.getRoute(CONST.IOU.ACTION.CREATE, CONST.IOU.TYPE.SUBMIT, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, generateReportID());
16-
case HYBRID_APP_ROUTES.MONEY_REQUEST_CREATE:
17-
case HYBRID_APP_ROUTES.MONEY_REQUEST_CREATE_TAB_SCAN:
18-
return ROUTES.MONEY_REQUEST_CREATE_TAB_SCAN.getRoute(CONST.IOU.ACTION.CREATE, CONST.IOU.TYPE.SUBMIT, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, generateReportID());
19-
default:
20-
return url;
21-
}
22-
}
234

245
if (CONFIG.IS_HYBRID_APP) {
256
// On HybridApp we need to shadow official implementation of Linking.getInitialURL on NewDot side with our custom implementation.
267
// Main benefit from this approach is that our deeplink-related code can be implemented the same way for both standalone NewDot and HybridApp.
278
// It's not possible to use the official implementation from the Linking module because the way OldDot handles deeplinks is significantly different from a standard React Native app.
28-
Linking.getInitialURL = () => HybridAppModule.getInitialURL().then((url) => parseHybridAppUrl(url as HybridAppRoute | Route));
29-
30-
// eslint-disable-next-line @typescript-eslint/unbound-method
31-
const originalAddEventListener = Linking.addEventListener;
32-
33-
// We wrap the original addEventListener to parse the URL before passing it to the handler.
34-
// This simplifies usage of the Linking module all over the app.
35-
Linking.addEventListener = (type: 'url', handler: (event: {url: string}) => void) => {
36-
const handlerWithParsedHybridAppUrl = (event: {url: string}) => {
37-
const transformedUrl = parseHybridAppUrl(event.url as HybridAppRoute | Route);
38-
handler({url: transformedUrl});
39-
};
40-
41-
return originalAddEventListener.call(Linking, type, handlerWithParsedHybridAppUrl);
42-
};
9+
Linking.getInitialURL = () => HybridAppModule.getInitialURL();
4310
}

0 commit comments

Comments
 (0)