Skip to content

Commit

Permalink
Merge pull request #8353 from Expensify/andrew-ios-push
Browse files Browse the repository at this point in the history
  • Loading branch information
roryabraham committed Apr 5, 2022
2 parents 0609796 + 2ef1277 commit 4829517
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
23 changes: 14 additions & 9 deletions src/libs/Navigation/Navigation.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import _ from 'underscore';
import React from 'react';
import {Keyboard} from 'react-native';
import {
StackActions,
DrawerActions,
getPathFromState,
} from '@react-navigation/native';
import {DrawerActions, getPathFromState, StackActions} from '@react-navigation/native';
import PropTypes from 'prop-types';
import Onyx from 'react-native-onyx';
import Log from '../Log';
Expand Down Expand Up @@ -168,6 +164,16 @@ function dismissModal(shouldOpenDrawer = false) {
}
}

/**
* Returns the current active route
* @returns {String}
*/
function getActiveRoute() {
return navigationRef.current && navigationRef.current.getCurrentRoute().name
? getPathFromState(navigationRef.current.getState(), linkingConfig.config)
: '';
}

/**
* Check whether the passed route is currently Active or not.
*
Expand All @@ -179,10 +185,7 @@ function dismissModal(shouldOpenDrawer = false) {
*/
function isActiveRoute(routePath) {
// We remove First forward slash from the URL before matching
const path = navigationRef.current && navigationRef.current.getCurrentRoute().name
? getPathFromState(navigationRef.current.getState(), linkingConfig.config).substring(1)
: '';
return path === routePath;
return getActiveRoute().substring(1) === routePath;
}

/**
Expand Down Expand Up @@ -214,9 +217,11 @@ DismissModal.defaultProps = {
};

export default {
canNavigate,
navigate,
dismissModal,
isActiveRoute,
getActiveRoute,
goBack,
DismissModal,
closeDrawer,
Expand Down
13 changes: 11 additions & 2 deletions src/libs/actions/Report.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,17 @@ function subscribeToReportCommentPushNotifications() {

// Open correct report when push notification is clicked
PushNotification.onSelected(PushNotification.TYPE.REPORT_COMMENT, ({reportID}) => {
Navigation.setDidTapNotification();
Linking.openURL(`${CONST.DEEPLINK_BASE_URL}${ROUTES.getReportRoute(reportID)}`);
if (Navigation.canNavigate('navigate')) {
// If a chat is visible other than the one we are trying to navigate to, then we need to navigate back
if (Navigation.getActiveRoute().slice(1, 2) === ROUTES.REPORT && !Navigation.isActiveRoute(`r/${reportID}`)) {
Navigation.goBack();
}
Navigation.navigate(ROUTES.getReportRoute(reportID));
} else {
// Navigation container is not yet ready, use deeplinking to open to correct report instead
Navigation.setDidTapNotification();
Linking.openURL(`${CONST.DEEPLINK_BASE_URL}${ROUTES.getReportRoute(reportID)}`);
}
});
}

Expand Down

0 comments on commit 4829517

Please sign in to comment.