Skip to content

Commit

Permalink
Merge pull request #48780 from software-mansion-labs/feat/shortcut-su…
Browse files Browse the repository at this point in the history
…pport-for-hybrid-app

[HybridApp] Add shortcut support in HybridApp
  • Loading branch information
Julesssss authored Sep 10, 2024
2 parents 545f897 + 8ee9f53 commit 286b945
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
4 changes: 3 additions & 1 deletion src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,9 @@ const ROUTES = {
*/
const HYBRID_APP_ROUTES = {
MONEY_REQUEST_CREATE: '/request/new/scan',
MONEY_REQUEST_SUBMIT_CREATE: '/submit/new/scan',
MONEY_REQUEST_CREATE_TAB_SCAN: '/submit/new/scan',
MONEY_REQUEST_CREATE_TAB_MANUAL: '/submit/new/manual',
MONEY_REQUEST_CREATE_TAB_DISTANCE: '/submit/new/distance',
} as const;

export {HYBRID_APP_ROUTES, getUrlWithBackToParam, PUBLIC_SCREENS_ROUTES};
Expand Down
7 changes: 4 additions & 3 deletions src/libs/Navigation/AppNavigator/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ type AppNavigatorProps = {
};

function AppNavigator({authenticated}: AppNavigatorProps) {
const {initialURL} = useContext(InitialURLContext);
const {initialURL, setInitialURL} = useContext(InitialURLContext);

useEffect(() => {
if (!NativeModules.HybridAppModule || !initialURL) {
return;
}

Navigation.isNavigationReady().then(() => {
Navigation.navigate(initialURL);
Navigation.navigate(Navigation.parseHybridAppUrl(initialURL));
setInitialURL(undefined);
});
}, [initialURL]);
}, [initialURL, setInitialURL]);

if (authenticated) {
const AuthScreens = require<ReactComponentModule>('./AuthScreens').default;
Expand Down
18 changes: 1 addition & 17 deletions src/libs/Navigation/AppNavigator/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import React, {lazy, memo, Suspense, useContext, useEffect} from 'react';
import {NativeModules} from 'react-native';
import {InitialURLContext} from '@components/InitialURLContextProvider';
import Navigation from '@libs/Navigation/Navigation';
import ROUTES from '@src/ROUTES';
import React, {lazy, memo, Suspense} from 'react';
import lazyRetry from '@src/utils/lazyRetry';

const AuthScreens = lazy(() => lazyRetry(() => import('./AuthScreens')));
Expand All @@ -14,18 +10,6 @@ type AppNavigatorProps = {
};

function AppNavigator({authenticated}: AppNavigatorProps) {
const {initialURL} = useContext(InitialURLContext);

useEffect(() => {
if (!NativeModules.HybridAppModule || !initialURL || !initialURL.includes(ROUTES.TRANSITION_BETWEEN_APPS)) {
return;
}

Navigation.isNavigationReady().then(() => {
Navigation.navigate(initialURL);
});
}, [initialURL]);

if (authenticated) {
// These are the protected screens and only accessible when an authToken is present
return (
Expand Down
8 changes: 6 additions & 2 deletions src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@ function getActiveRouteIndex(stateOrRoute: StateOrRoute, index?: number): number
*/
function parseHybridAppUrl(url: HybridAppRoute | Route): Route {
switch (url) {
case HYBRID_APP_ROUTES.MONEY_REQUEST_CREATE_TAB_MANUAL:
return ROUTES.MONEY_REQUEST_CREATE_TAB_MANUAL.getRoute(CONST.IOU.ACTION.CREATE, CONST.IOU.TYPE.SUBMIT, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, ReportUtils.generateReportID());
case HYBRID_APP_ROUTES.MONEY_REQUEST_CREATE_TAB_DISTANCE:
return ROUTES.MONEY_REQUEST_CREATE_TAB_DISTANCE.getRoute(CONST.IOU.ACTION.CREATE, CONST.IOU.TYPE.SUBMIT, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, ReportUtils.generateReportID());
case HYBRID_APP_ROUTES.MONEY_REQUEST_CREATE:
case HYBRID_APP_ROUTES.MONEY_REQUEST_SUBMIT_CREATE:
return ROUTES.MONEY_REQUEST_CREATE.getRoute(CONST.IOU.ACTION.CREATE, CONST.IOU.TYPE.SUBMIT, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, ReportUtils.generateReportID());
case HYBRID_APP_ROUTES.MONEY_REQUEST_CREATE_TAB_SCAN:
return ROUTES.MONEY_REQUEST_CREATE_TAB_SCAN.getRoute(CONST.IOU.ACTION.CREATE, CONST.IOU.TYPE.SUBMIT, CONST.IOU.OPTIMISTIC_TRANSACTION_ID, ReportUtils.generateReportID());
default:
return url;
}
Expand Down

0 comments on commit 286b945

Please sign in to comment.