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 Drawer #5745

Merged
merged 18 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from 15 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
1 change: 1 addition & 0 deletions config/webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const includeModules = [

const webpackConfig = {
entry: {
polyfill: 'babel-polyfill',
app: './index.js',
},
output: {
Expand Down
111 changes: 60 additions & 51 deletions package-lock.json

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

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@
"@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",
"babel-polyfill": "^6.26.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, what needed babel-polyfill?

Copy link
Member Author

Choose a reason for hiding this comment

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

I followed https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/web-support. I don't know the consequences of removing this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I followed https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/web-support. I don't know the consequences of removing this.

"dotenv": "^8.2.0",
"electron-context-menu": "^2.3.0",
"electron-log": "^4.3.5",
Expand Down Expand Up @@ -92,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-beta.3",
Comment on lines -95 to +96
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @Beamanator @parasharrajat this change here seems to have broken the Attachment Picker for me on iOS: https://expensify.slack.com/archives/C01GTK53T8Q/p1635874753343600

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey, @kidroca this is PR is reverted now. Thanks for notifying me.

"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
Original file line number Diff line number Diff line change
@@ -1,43 +1,21 @@
import React from 'react';
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 Navigation from '../Navigation';
import styles, {getNavigationDrawerStyle, getNavigationDrawerType} from '../../../../styles/styles';
import Navigation from '../../Navigation';
import {propTypes, defaultProps} from './drawerNavigatorPropTypes';

const propTypes = {
/** Screens to be passed in the Drawer */
screens: PropTypes.arrayOf(PropTypes.shape({
/** Name of the Screen */
name: PropTypes.string.isRequired,

/** Component for the Screen */
component: PropTypes.elementType.isRequired,

/** Optional params to be passed to the Screen */
// eslint-disable-next-line react/forbid-prop-types
initialParams: PropTypes.object,
})).isRequired,

/** Drawer content Component */
drawerContent: PropTypes.elementType.isRequired,

/** If it's the main screen, don't wrap the content even if it's a full screen modal. */
isMainScreen: PropTypes.bool,

/** Window Dimensions props */
...windowDimensionsPropTypes,
};
const Drawer = createDrawerNavigator();

const BaseDrawerNavigator = (props) => {
const content = (
<Drawer.Navigator
backBehavior="none"
defaultStatus={Navigation.getDefaultDrawerState(props.isSmallScreenWidth)}
sceneContainerStyle={styles.navigationSceneContainer}
drawerContent={props.drawerContent}
useLegacyImplementation={props.useLegacyImplementation}
screenOptions={{
cardStyle: styles.navigationScreenCardStyle,
headerShown: false,
Expand Down Expand Up @@ -71,5 +49,6 @@ const BaseDrawerNavigator = (props) => {
};

BaseDrawerNavigator.propTypes = propTypes;
BaseDrawerNavigator.defaultProps = defaultProps;
BaseDrawerNavigator.displayName = 'BaseDrawerNavigator';
export default withWindowDimensions(BaseDrawerNavigator);
export default BaseDrawerNavigator;
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import PropTypes from 'prop-types';
import {windowDimensionsPropTypes} from '../../../../components/withWindowDimensions';

const propTypes = {
/** Screens to be passed in the Drawer */
screens: PropTypes.arrayOf(PropTypes.shape({
/** Name of the Screen */
name: PropTypes.string.isRequired,

/** Component for the Screen */
component: PropTypes.elementType.isRequired,

/** Optional params to be passed to the Screen */
// eslint-disable-next-line react/forbid-prop-types
initialParams: PropTypes.object,
})).isRequired,

/** Drawer content Component */
drawerContent: PropTypes.elementType.isRequired,

/** Whether use the legacy implementation of Drawer */
useLegacyImplementation: PropTypes.bool,

/** If it's the main screen, don't wrap the content even if it's a full screen modal. */
isMainScreen: PropTypes.bool,

/** Window Dimensions props */
...windowDimensionsPropTypes,
};

const defaultProps = {
useLegacyImplementation: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe make this required? Looks like it is being passed to all the drawers (or should be if not).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. Required is fine. I will update.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's just fine this way, otherwise, we will get the Prop validation warning and to remove that we have to manipluate the propsType definition (extra overhead).

Copy link
Contributor

Choose a reason for hiding this comment

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

Prop validation warning

Do you mean the linter?

manipluate the propsType definition (extra overhead)

What does this mean? Why does it create extra overhead?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not an overhead. I was just being lazy. Updated

};

export {
propTypes,
defaultProps,
};
22 changes: 22 additions & 0 deletions src/libs/Navigation/AppNavigator/DrawerNavigator/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import withWindowDimensions from '../../../../components/withWindowDimensions';
import BaseDrawerNavigator from './BaseDrawerNavigator';
import {propTypes, defaultProps} from './drawerNavigatorPropTypes';

const DrawerNavigator = props => (
<BaseDrawerNavigator
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}

// Drawer's implementaion is buggy. Modern implementaion does not work on mobile web and legacy breaks the layout on Desktop while resizing.
// For some reason, drawer never closes when opening the Drawer screen on mobile web.
// So we will switch between implementations based on the device width.
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
// Drawer's implementaion is buggy. Modern implementaion does not work on mobile web and legacy breaks the layout on Desktop while resizing.
// For some reason, drawer never closes when opening the Drawer screen on mobile web.
// So we will switch between implementations based on the device width.
// On mobile web, the non legacy version of the DrawerNavigator breaks the layout on Desktop while resizing
// and the drawer gets stuck in an open state when navigating

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any issue we are tracking for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. I will create one.

Copy link
Member Author

Choose a reason for hiding this comment

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

No yet, I will create one in our repo.

// eslint-disable-next-line react/jsx-props-no-multi-spaces
useLegacyImplementation={props.isSmallScreenWidth}
/>
);

DrawerNavigator.propTypes = propTypes;
DrawerNavigator.defaultProps = defaultProps;
DrawerNavigator.displayName = 'DrawerNavigator';
export default withWindowDimensions(DrawerNavigator);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import withWindowDimensions from '../../../../components/withWindowDimensions';
import BaseDrawerNavigator from './BaseDrawerNavigator';
import {propTypes, defaultProps} from './drawerNavigatorPropTypes';

const DrawerNavigator = props => (
<BaseDrawerNavigator
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
useLegacyImplementation={false}
/>
);

DrawerNavigator.propTypes = propTypes;
DrawerNavigator.defaultProps = defaultProps;
DrawerNavigator.displayName = 'DrawerNavigator';
export default withWindowDimensions(DrawerNavigator);
4 changes: 2 additions & 2 deletions src/libs/Navigation/AppNavigator/MainDrawerNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Permissions from '../../Permissions';
// Screens
import ReportScreen from '../../../pages/home/ReportScreen';
import SidebarScreen from '../../../pages/home/sidebar/SidebarScreen';
import BaseDrawerNavigator from './BaseDrawerNavigator';
import DrawerNavigator from './DrawerNavigator';
import {findLastAccessedReport} from '../../reportUtils';

const propTypes = {
Expand Down Expand Up @@ -56,7 +56,7 @@ const MainDrawerNavigator = (props) => {
// This way routing information is updated (if needed) based on the initial report ID resolved.
// This is usually needed after login/create account and re-launches
return (
<BaseDrawerNavigator
<DrawerNavigator
drawerContent={() => <SidebarScreen />}
screens={[
{
Expand Down
9 changes: 7 additions & 2 deletions src/libs/Navigation/CustomActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@ function pushDrawerRoute(screenName, params, navigationRef) {
}

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