Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Navigated back to the home screen after granting for Camera permission #47222

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -891,6 +894,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;
Loading