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 back handler for Android #6295

Merged
merged 6 commits into from
Nov 22, 2021
Merged
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
63 changes: 34 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
"@react-native-masked-view/masked-view": "^0.2.4",
"@react-native-picker/picker": "^1.9.11",
"@react-navigation/compat": "^5.3.15",
"@react-navigation/drawer": "6.1.4",
"@react-navigation/native": "6.0.2",
"@react-navigation/stack": "6.0.7",
"@react-navigation/drawer": "6.1.7",
"@react-navigation/native": "6.0.5",
"@react-navigation/stack": "6.0.10",
"babel-plugin-transform-remove-console": "^6.9.4",
"dotenv": "^8.2.0",
"electron-context-menu": "^2.3.0",
Expand Down Expand Up @@ -93,7 +93,7 @@
"react-native-permissions": "^3.0.1",
"react-native-picker-select": "8.0.4",
"react-native-plaid-link-sdk": "^7.1.0",
"react-native-reanimated": "^2.3.0-alpha.1",
"react-native-reanimated": "2.3.0-alpha.1",
"react-native-render-html": "6.0.0-beta.8",
"react-native-safe-area-context": "^3.1.4",
"react-native-screens": "^3.0.0",
Expand Down
3 changes: 2 additions & 1 deletion src/libs/Navigation/AppNavigator/BaseDrawerNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import _ from 'underscore';
import PropTypes from 'prop-types';
import {createDrawerNavigator} from '@react-navigation/drawer';
import {View} from 'react-native';
import styles, {getNavigationDrawerStyle, getNavigationDrawerType} from '../../../styles/styles';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import styles, {getNavigationDrawerStyle, getNavigationDrawerType} from '../../../styles/styles';
Copy link
Contributor

Choose a reason for hiding this comment

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

Why move this down here? I kinda like it better above withWindowDimensions to make imports slightly more alphabetical

Copy link
Contributor

Choose a reason for hiding this comment

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

Not a big deal, I'd rather get this merged haha

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, what I am 9 minutes late.... 🐼

Copy link
Contributor

Choose a reason for hiding this comment

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

lol it's fine - i thought you would be later :D

import Navigation from '../Navigation';

const propTypes = {
Expand Down Expand Up @@ -35,6 +35,7 @@ const Drawer = createDrawerNavigator();
const BaseDrawerNavigator = (props) => {
const content = (
<Drawer.Navigator
backBehavior="none"
key={`BaseDrawerNavigator${props.isSmallScreenWidth}`}
defaultStatus={Navigation.getDefaultDrawerState(props.isSmallScreenWidth)}
sceneContainerStyle={styles.navigationSceneContainer}
Expand Down
25 changes: 14 additions & 11 deletions src/libs/Navigation/CustomActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,26 @@ function pushDrawerRoute(screenName, params, navigationRef) {
const rootState = navigationRef.current.getRootState();
const activeReportID = lodashGet(rootState, 'routes[0].state.routes[0].params.reportID', '');

if (activeReportID === params.reportID) {
if (state.type !== 'drawer') {
if (state.type !== 'drawer') {
if (activeReportID === params.reportID) {
navigateBackToRootDrawer(navigationRef);
} else {
// Non Drawer navigators have routes and not history so we'll fallback to navigate() in the case where we are
// unable to push a new screen onto the history stack e.g. navigating to a ReportScreen via a modal screen.
// Note: One downside of this is that the history will be reset.
navigationRef.current.dispatch(() => CommonActions.navigate(screenName, params));
}
return DrawerActions.closeDrawer();
}

// Non Drawer navigators have routes and not history so we'll fallback to navigate() in the case where we are
// unable to push a new screen onto the history stack e.g. navigating to a ReportScreen via a modal screen.
// Note: One downside of this is that the history will be reset.
if (state.type !== 'drawer') {
return CommonActions.navigate(screenName, params);
}

const screenRoute = {type: 'route', name: screenName};
const history = _.map([...(state.history || [])], () => screenRoute);
history.push(screenRoute);
const history = _.map([...(state.history || [screenRoute])], () => screenRoute);

// Force drawer to close and show the report screen
history.push({
type: 'drawer',
status: 'closed',
});
return CommonActions.reset({
...state,
routes: [{
Expand Down