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 13 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
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',

/** screen to open after reloading app after changing app permission from settings */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** screen to open after reloading app after changing app permission from settings */
/** Stores the route to open after changing app permission from settings */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

LAST_SCREEN: 'last_screen',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LAST_SCREEN: 'last_screen',
LAST_ROUTE: 'lastRoute',

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anh also update other places to use route instead of screen

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


/** 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_SCREEN]: 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 updateLastScreen(screen: string) {
Onyx.set(ONYXKEYS.LAST_SCREEN, screen);
}

export {
setLocale,
setLocaleAndNavigate,
Expand All @@ -513,5 +517,6 @@ export {
savePolicyDraftByNewWorkspace,
createWorkspaceWithPolicyDraftAndNavigateToIt,
updateLastVisitedPath,
updateLastScreen,
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 saveLastScreen from '@libs/saveLastScreen';
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 case of ios, app reload when we enable camera permission from settings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// In case of ios, app reload when we enable camera permission from settings
// In the case of ios, the App reloads when we update camera permission from settings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// we are saving last screen so we can navigate to it after app reload
saveLastScreen();
},
},
],
Expand Down
6 changes: 6 additions & 0 deletions src/libs/saveLastScreen/index.ios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {updateLastScreen} from '@libs/actions/App';
import Navigation from '@libs/Navigation/Navigation';

export default function saveLastScreen() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export default function saveLastScreen() {
export default function saveLastRoute() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

updateLastScreen(Navigation.getActiveRoute());
}
3 changes: 3 additions & 0 deletions src/libs/saveLastScreen/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/** we are only saving last screen in case of ios */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** we are only saving last screen in case of ios */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export default function saveLastScreen() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export default function saveLastScreen() {}
const saveLastRoute: GetPlaidDesktopMessage = () => {};
export default saveLastRoute;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DylanDylann There is a issue of type mismatch for return (Type 'void' is not assignable to type 'TranslationPaths | undefined)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ravindra-encoresky ahh my bad, please remove GetPlaidDesktopMessage

36 changes: 33 additions & 3 deletions src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, {useEffect} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import {useOnyx, withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import ScreenWrapper from '@components/ScreenWrapper';
import useActiveWorkspaceFromNavigationState from '@hooks/useActiveWorkspaceFromNavigationState';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import {updateLastScreen} from '@libs/actions/App';
import {updateLastAccessedWorkspace} from '@libs/actions/Policy/Policy';
import * as Browser from '@libs/Browser';
import TopBar from '@libs/Navigation/AppNavigator/createCustomBottomTabNavigator/TopBar';
Expand All @@ -14,6 +16,7 @@ import SidebarLinksData from '@pages/home/sidebar/SidebarLinksData';
import Timing from '@userActions/Timing';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Route} from '@src/ROUTES';

/**
* Function called when a pinned chat is selected.
Expand All @@ -23,7 +26,14 @@ const startTimer = () => {
Performance.markStart(CONST.TIMING.SWITCH_REPORT);
};

function BaseSidebarScreen() {
type BaseSidebarScreenOnyxProps = {
/** last visited screen */
lastScreen: OnyxEntry<string>;
};

type BaseSidebarScreenProps = BaseSidebarScreenOnyxProps;

function BaseSidebarScreen({lastScreen}: BaseSidebarScreenProps) {
const styles = useThemeStyles();
const activeWorkspaceID = useActiveWorkspaceFromNavigationState();
const {translate} = useLocalize();
Expand All @@ -43,6 +53,22 @@ function BaseSidebarScreen() {
updateLastAccessedWorkspace(undefined);
}, [activeWorkspace, activeWorkspaceID]);

/**
* Navigate to scan receipt screen after it enabling camera permission from setting
* This will only works for ios application because we are saving last screen only for ios
*/
useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you put this useEffect into this file?

Copy link
Contributor Author

@ravindra-encoresky ravindra-encoresky Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find any other file for navigating to the Receipt Scan screen when the app opens. btw I looking to optimise it by using activeRoute instead of hardcoding last screen.

Copy link
Contributor Author

@ravindra-encoresky ravindra-encoresky Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DylanDylann Another screen where I could place this useEffect is SidebarScreen.tsx. Please let me know if I’m missing any part of the flow for this.

Copy link
Contributor

@DylanDylann DylanDylann Aug 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ravindra-encoresky Let's try in Expensify.tsx file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!lastScreen) {
return;
}

updateLastScreen('');
const route = lastScreen as Route;
Navigation.navigate(route);
// disabling this rule, as we want this to run only on the first render
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, []);

return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
Expand Down Expand Up @@ -71,4 +97,8 @@ function BaseSidebarScreen() {

BaseSidebarScreen.displayName = 'BaseSidebarScreen';

export default BaseSidebarScreen;
export default withOnyx<BaseSidebarScreenProps, BaseSidebarScreenOnyxProps>({
lastScreen: {
key: ONYXKEYS.LAST_SCREEN,
},
})(BaseSidebarScreen);
Loading