Skip to content

Commit

Permalink
Merge pull request #47222 from ravindra-encoresky/fix-46422-camera-pe…
Browse files Browse the repository at this point in the history
…rmission
  • Loading branch information
roryabraham authored Aug 27, 2024
2 parents 5a29fc1 + 9031f44 commit d5cfecf
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Expensify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_',
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/libs/actions/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -513,5 +517,6 @@ export {
savePolicyDraftByNewWorkspace,
createWorkspaceWithPolicyDraftAndNavigateToIt,
updateLastVisitedPath,
updateLastRoute,
KEYS_TO_PRESERVE,
};
4 changes: 4 additions & 0 deletions src/libs/fileDownload/FileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
},
},
],
Expand Down
6 changes: 6 additions & 0 deletions src/libs/saveLastRoute/index.ios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {updateLastRoute} from '@libs/actions/App';
import Navigation from '@libs/Navigation/Navigation';

export default function saveLastRoute() {
updateLastRoute(Navigation.getActiveRoute());
}
3 changes: 3 additions & 0 deletions src/libs/saveLastRoute/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const saveLastRoute = () => {};

export default saveLastRoute;

0 comments on commit d5cfecf

Please sign in to comment.