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: Navigate to last chat after closing the app #30055

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ const ONYXKEYS = {
// Max width supported for HTML <canvas> element
MAX_CANVAS_WIDTH: 'maxCanvasWidth',

LAST_ON_REPORT_SCREEN: 'lastOnReportScreen',

/** Collection Keys */
COLLECTION: {
DOWNLOAD: 'download_',
Expand Down
8 changes: 8 additions & 0 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -2402,6 +2402,13 @@ function searchInServer(searchInput) {
debouncedSearchInServer(searchInput);
}

/**
* @param {boolean} isLastOnReportScreen
*/
function lastOnReportScreen(isLastOnReportScreen) {
Onyx.merge(ONYXKEYS.LAST_ON_REPORT_SCREEN, isLastOnReportScreen);
}

export {
searchInServer,
addComment,
Expand Down Expand Up @@ -2462,4 +2469,5 @@ export {
openRoomMembersPage,
savePrivateNotesDraft,
getDraftPrivateNote,
lastOnReportScreen,
};
7 changes: 6 additions & 1 deletion src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {useRef, useState, useEffect, useMemo, useCallback} from 'react';
import {withOnyx} from 'react-native-onyx';
import {useFocusEffect} from '@react-navigation/native';
import {useFocusEffect, useIsFocused} from '@react-navigation/native';
import PropTypes from 'prop-types';
import {View} from 'react-native';
import lodashGet from 'lodash/get';
Expand Down Expand Up @@ -178,6 +178,7 @@ function ReportScreen({

const isTopMostReportId = currentReportID === getReportID(route);
const didSubscribeToReportLeavingEvents = useRef(false);
const isFocused = useIsFocused();

let headerView = (
<HeaderView
Expand Down Expand Up @@ -358,6 +359,10 @@ function ReportScreen({
}
}, [report, didSubscribeToReportLeavingEvents, reportID]);

useEffect(() => {
Report.lastOnReportScreen(isFocused);
}, [isFocused]);

const onListLayout = useCallback((e) => {
setListHeight((prev) => lodashGet(e, 'nativeEvent.layout.height', prev));
if (!markReadyForHydration) {
Expand Down
14 changes: 12 additions & 2 deletions src/pages/home/sidebar/SidebarLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {useEffect, useRef, useCallback} from 'react';
import {View, InteractionManager} from 'react-native';
import _ from 'underscore';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import styles from '../../../styles/styles';
import * as StyleUtils from '../../../styles/StyleUtils';
import ONYXKEYS from '../../../ONYXKEYS';
Expand Down Expand Up @@ -45,7 +46,7 @@ const propTypes = {
isActiveReport: PropTypes.func.isRequired,
};

function SidebarLinks({onLinkClick, insets, optionListItems, isLoading, priorityMode = CONST.PRIORITY_MODE.DEFAULT, isActiveReport, isCreateMenuOpen}) {
function SidebarLinks({onLinkClick, insets, optionListItems, isLoading, priorityMode = CONST.PRIORITY_MODE.DEFAULT, isActiveReport, isCreateMenuOpen, lastOnReportScreen}) {
const modal = useRef({});
const {translate, updateLocale} = useLocalize();
const {isSmallScreenWidth} = useWindowDimensions();
Expand All @@ -54,7 +55,12 @@ function SidebarLinks({onLinkClick, insets, optionListItems, isLoading, priority
if (!isSmallScreenWidth) {
return;
}
if (lastOnReportScreen) {
Navigation.navigate(ROUTES.REPORT);
return;
}
App.confirmReadyToOpenApp();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isSmallScreenWidth]);

useEffect(() => {
Expand Down Expand Up @@ -179,5 +185,9 @@ function SidebarLinks({onLinkClick, insets, optionListItems, isLoading, priority
SidebarLinks.propTypes = propTypes;
SidebarLinks.displayName = 'SidebarLinks';

export default SidebarLinks;
export default withOnyx({
lastOnReportScreen: {
key: ONYXKEYS.LAST_ON_REPORT_SCREEN,
},
})(SidebarLinks);
export {basePropTypes};
Loading