diff --git a/src/Expensify.tsx b/src/Expensify.tsx index 8a2ef4a2b2f4..10389f69a44c 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -16,6 +16,7 @@ import UpdateAppModal from './components/UpdateAppModal'; import * as CONFIG from './CONFIG'; import CONST from './CONST'; import useLocalize from './hooks/useLocalize'; +import {updateLastRoute} from './libs/actions/App'; import * as EmojiPickerAction from './libs/actions/EmojiPickerAction'; import * as Report from './libs/actions/Report'; import * as User from './libs/actions/User'; @@ -103,6 +104,7 @@ function Expensify({ const {translate} = useLocalize(); const [account] = useOnyx(ONYXKEYS.ACCOUNT); const [session] = useOnyx(ONYXKEYS.SESSION); + const [lastRoute] = useOnyx(ONYXKEYS.LAST_ROUTE); const [shouldShowRequire2FAModal, setShouldShowRequire2FAModal] = useState(false); useEffect(() => { @@ -236,6 +238,16 @@ function Expensify({ Audio.setAudioModeAsync({playsInSilentModeIOS: true}); }, []); + useLayoutEffect(() => { + if (!isNavigationReady || !lastRoute) { + return; + } + updateLastRoute(''); + Navigation.navigate(lastRoute as Route); + // Disabling this rule because we only want it to run on the first render. + // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps + }, [isNavigationReady]); + useEffect(() => { if (!isAuthenticated) { return; diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 03fcd2aba3d3..101656ae1ea1 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -400,6 +400,9 @@ const ONYXKEYS = { /** Stores the information about currently edited advanced approval workflow */ APPROVAL_WORKFLOW: 'approvalWorkflow', + /** Stores the route to open after changing app permission from settings */ + LAST_ROUTE: 'lastRoute', + /** Collection Keys */ COLLECTION: { DOWNLOAD: 'download_', @@ -902,6 +905,7 @@ type OnyxValuesMapping = { [ONYXKEYS.NVP_WORKSPACE_TOOLTIP]: OnyxTypes.WorkspaceTooltip; [ONYXKEYS.NVP_PRIVATE_CANCELLATION_DETAILS]: OnyxTypes.CancellationDetails[]; [ONYXKEYS.APPROVAL_WORKFLOW]: OnyxTypes.ApprovalWorkflowOnyx; + [ONYXKEYS.LAST_ROUTE]: string; }; type OnyxValues = OnyxValuesMapping & OnyxCollectionValuesMapping & OnyxFormValuesMapping & OnyxFormDraftValuesMapping; diff --git a/src/libs/actions/App.ts b/src/libs/actions/App.ts index 24e554af111a..fcbfc73b3dbd 100644 --- a/src/libs/actions/App.ts +++ b/src/libs/actions/App.ts @@ -496,6 +496,10 @@ function updateLastVisitedPath(path: string) { Onyx.merge(ONYXKEYS.LAST_VISITED_PATH, path); } +function updateLastRoute(screen: string) { + Onyx.set(ONYXKEYS.LAST_ROUTE, screen); +} + export { setLocale, setLocaleAndNavigate, @@ -513,5 +517,6 @@ export { savePolicyDraftByNewWorkspace, createWorkspaceWithPolicyDraftAndNavigateToIt, updateLastVisitedPath, + updateLastRoute, KEYS_TO_PRESERVE, }; diff --git a/src/libs/fileDownload/FileUtils.ts b/src/libs/fileDownload/FileUtils.ts index c8520f3c66cd..05f29390ca14 100644 --- a/src/libs/fileDownload/FileUtils.ts +++ b/src/libs/fileDownload/FileUtils.ts @@ -5,6 +5,7 @@ import type {FileObject} from '@components/AttachmentModal'; import DateUtils from '@libs/DateUtils'; import * as Localize from '@libs/Localize'; import Log from '@libs/Log'; +import saveLastRoute from '@libs/saveLastRoute'; import CONST from '@src/CONST'; import getImageManipulator from './getImageManipulator'; import getImageResolution from './getImageResolution'; @@ -76,6 +77,9 @@ function showCameraPermissionsAlert() { text: Localize.translateLocal('common.settings'), onPress: () => { Linking.openSettings(); + // In the case of ios, the App reloads when we update camera permission from settings + // we are saving last route so we can navigate to it after app reload + saveLastRoute(); }, }, ], diff --git a/src/libs/saveLastRoute/index.ios.ts b/src/libs/saveLastRoute/index.ios.ts new file mode 100644 index 000000000000..12107937800b --- /dev/null +++ b/src/libs/saveLastRoute/index.ios.ts @@ -0,0 +1,6 @@ +import {updateLastRoute} from '@libs/actions/App'; +import Navigation from '@libs/Navigation/Navigation'; + +export default function saveLastRoute() { + updateLastRoute(Navigation.getActiveRoute()); +} diff --git a/src/libs/saveLastRoute/index.ts b/src/libs/saveLastRoute/index.ts new file mode 100644 index 000000000000..4b532cf6ee75 --- /dev/null +++ b/src/libs/saveLastRoute/index.ts @@ -0,0 +1,3 @@ +const saveLastRoute = () => {}; + +export default saveLastRoute;