|
1 | 1 | import HybridAppModule from '@expensify/react-native-hybrid-app'; |
2 | 2 | import {Linking} from 'react-native'; |
3 | | -import {generateReportID} from '@libs/ReportUtils'; |
4 | 3 | 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 | | -} |
23 | 4 |
|
24 | 5 | if (CONFIG.IS_HYBRID_APP) { |
25 | 6 | // On HybridApp we need to shadow official implementation of Linking.getInitialURL on NewDot side with our custom implementation. |
26 | 7 | // Main benefit from this approach is that our deeplink-related code can be implemented the same way for both standalone NewDot and HybridApp. |
27 | 8 | // 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(); |
43 | 10 | } |
0 commit comments