Skip to content

Commit

Permalink
Remove withDrawerState and isDrawerOpen (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
staszekscp authored and adamgrzybowski committed Mar 31, 2023
1 parent f432729 commit 74798c0
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 104 deletions.
42 changes: 0 additions & 42 deletions src/components/withDrawerState.js

This file was deleted.

9 changes: 3 additions & 6 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import compose from '../../libs/compose';
import networkPropTypes from '../../components/networkPropTypes';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../components/withWindowDimensions';
import OfflineWithFeedback from '../../components/OfflineWithFeedback';
import withDrawerState, {withDrawerPropTypes} from '../../components/withDrawerState';
import ReportFooter from './report/ReportFooter';
import Banner from '../../components/Banner';
import withLocalize from '../../components/withLocalize';
Expand All @@ -35,6 +34,7 @@ import ReportHeaderSkeletonView from '../../components/ReportHeaderSkeletonView'
import withViewportOffsetTop, {viewportOffsetTopPropTypes} from '../../components/withViewportOffsetTop';
import * as ReportActionsUtils from '../../libs/ReportActionsUtils';
import personalDetailsPropType from '../personalDetailsPropType';
import withNavigationFocus from '../../components/withNavigationFocus';

const propTypes = {
/** Navigation route context info provided by react navigation */
Expand Down Expand Up @@ -80,7 +80,6 @@ const propTypes = {
personalDetails: PropTypes.objectOf(personalDetailsPropType),

...windowDimensionsPropTypes,
...withDrawerPropTypes,
...viewportOffsetTopPropTypes,
};

Expand Down Expand Up @@ -216,8 +215,7 @@ class ReportScreen extends React.Component {
|| (ReportUtils.isUserCreatedPolicyRoom(this.props.report) && !Permissions.canUsePolicyRooms(this.props.betas));

// When the ReportScreen is not open/in the viewport, we want to "freeze" it for performance reasons
const shouldFreeze = this.props.isSmallScreenWidth && this.props.isDrawerOpen;

const shouldFreeze = this.props.isSmallScreenWidth && !this.props.isFocused;
const isLoading = !reportID || !this.props.isSidebarLoaded || _.isEmpty(this.props.personalDetails);

// the moment the ReportScreen becomes unfrozen we want to start the animation of the placeholder skeleton content
Expand Down Expand Up @@ -297,7 +295,6 @@ class ReportScreen extends React.Component {
reportActions={this.props.reportActions}
report={this.props.report}
isComposerFullSize={this.props.isComposerFullSize}
isDrawerOpen={this.props.isDrawerOpen}
parentViewHeight={this.state.skeletonViewContainerHeight}
/>
<ReportFooter
Expand Down Expand Up @@ -336,7 +333,7 @@ export default compose(
withViewportOffsetTop,
withLocalize,
withWindowDimensions,
withDrawerState,
withNavigationFocus,
withNetwork(),
withOnyx({
isSidebarLoaded: {
Expand Down
14 changes: 1 addition & 13 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import AttachmentModal from '../../../components/AttachmentModal';
import compose from '../../../libs/compose';
import PopoverMenu from '../../../components/PopoverMenu';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import withDrawerState from '../../../components/withDrawerState';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import willBlurTextInputOnTapOutside from '../../../libs/willBlurTextInputOnTapOutside';
import CONST from '../../../CONST';
Expand All @@ -39,7 +38,6 @@ import * as User from '../../../libs/actions/User';
import Tooltip from '../../../components/Tooltip';
import EmojiPickerButton from '../../../components/EmojiPicker/EmojiPickerButton';
import * as DeviceCapabilities from '../../../libs/DeviceCapabilities';
import toggleReportActionComposeView from '../../../libs/toggleReportActionComposeView';
import OfflineIndicator from '../../../components/OfflineIndicator';
import ExceededCommentLength from '../../../components/ExceededCommentLength';
import withNavigationFocus from '../../../components/withNavigationFocus';
Expand Down Expand Up @@ -83,9 +81,6 @@ const propTypes = {
/** Array of report actions for this report */
reportActions: PropTypes.arrayOf(PropTypes.shape(reportActionPropTypes)),

/** Is the report view covered by the drawer */
isDrawerOpen: PropTypes.bool.isRequired,

/** Is the window width narrow, like on a mobile device */
isSmallScreenWidth: PropTypes.bool.isRequired,

Expand Down Expand Up @@ -224,11 +219,6 @@ class ReportActionCompose extends React.Component {
}

componentDidUpdate(prevProps) {
const sidebarOpened = !prevProps.isDrawerOpen && this.props.isDrawerOpen;
if (sidebarOpened) {
toggleReportActionComposeView(true);
}

// We want to focus or refocus the input when a modal has been closed and the underlying screen is focused.
// We avoid doing this on native platforms since the software keyboard popping
// open creates a jarring and broken UX.
Expand Down Expand Up @@ -681,7 +671,6 @@ class ReportActionCompose extends React.Component {
&& !this.props.isComposerFullSize;

// Prevents focusing and showing the keyboard while the drawer is covering the chat.
const isComposeDisabled = this.props.isDrawerOpen && this.props.isSmallScreenWidth;
const isBlockedFromConcierge = ReportUtils.chatIncludesConcierge(this.props.report) && User.isBlockedFromConcierge(this.props.blockedFromConcierge);
const inputPlaceholder = this.getInputPlaceholder();
const shouldUseFocusedColor = !isBlockedFromConcierge && !this.props.disabled && (this.state.isFocused || this.state.isDraggingOver);
Expand Down Expand Up @@ -835,7 +824,7 @@ class ReportActionCompose extends React.Component {
onPasteFile={displayFileInModal}
shouldClear={this.state.textInputShouldClear}
onClear={() => this.setTextInputShouldClear(false)}
isDisabled={isComposeDisabled || isBlockedFromConcierge || this.props.disabled}
isDisabled={isBlockedFromConcierge || this.props.disabled}
selection={this.state.selection}
onSelectionChange={this.onSelectionChange}
isFullComposerAvailable={this.state.isFullComposerAvailable}
Expand Down Expand Up @@ -932,7 +921,6 @@ ReportActionCompose.defaultProps = defaultProps;

export default compose(
withWindowDimensions,
withDrawerState,
withNavigationFocus,
withLocalize,
withNetwork(),
Expand Down
6 changes: 1 addition & 5 deletions src/pages/home/report/ReportActionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React from 'react';
import {Animated} from 'react-native';
import _ from 'underscore';
import InvertedFlatList from '../../../components/InvertedFlatList';
import withDrawerState, {withDrawerPropTypes} from '../../../components/withDrawerState';
import compose from '../../../libs/compose';
import * as ReportScrollManager from '../../../libs/ReportScrollManager';
import styles from '../../../styles/styles';
Expand Down Expand Up @@ -53,7 +52,6 @@ const propTypes = {
/** Information about the network */
network: networkPropTypes.isRequired,

...withDrawerPropTypes,
...windowDimensionsPropTypes,
};

Expand Down Expand Up @@ -146,7 +144,6 @@ class ReportActionsList extends React.Component {
render() {
// Native mobile does not render updates flatlist the changes even though component did update called.
// To notify there something changes we can use extraData prop to flatlist
const extraData = (!this.props.isDrawerOpen && this.props.isSmallScreenWidth) ? this.props.newMarkerReportActionID : undefined;
const shouldShowReportRecipientLocalTime = ReportUtils.canShowReportRecipientLocalTime(this.props.personalDetails, this.props.report);
return (
<Animated.View style={[StyleUtils.fade(this.state.fadeInAnimation), styles.flex1]}>
Expand Down Expand Up @@ -196,7 +193,7 @@ class ReportActionsList extends React.Component {
this.props.onLayout(event);
}}
onScroll={this.props.onScroll}
extraData={extraData}
extraData={this.props.newMarkerReportActionID}
/>
</Animated.View>
);
Expand All @@ -207,7 +204,6 @@ ReportActionsList.propTypes = propTypes;
ReportActionsList.defaultProps = defaultProps;

export default compose(
withDrawerState,
withWindowDimensions,
withLocalize,
withPersonalDetails(),
Expand Down
21 changes: 4 additions & 17 deletions src/pages/home/report/ReportActionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Timing from '../../../libs/actions/Timing';
import CONST from '../../../CONST';
import compose from '../../../libs/compose';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import {withDrawerPropTypes} from '../../../components/withDrawerState';
import * as ReportScrollManager from '../../../libs/ReportScrollManager';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import Performance from '../../../libs/Performance';
Expand All @@ -23,6 +22,7 @@ import EmojiPicker from '../../../components/EmojiPicker/EmojiPicker';
import * as ReportActionsUtils from '../../../libs/ReportActionsUtils';
import * as ReportUtils from '../../../libs/ReportUtils';
import reportPropTypes from '../../reportPropTypes';
import withNavigationFocus from '../../../components/withNavigationFocus';

const propTypes = {
/** The report currently being looked at */
Expand All @@ -38,7 +38,6 @@ const propTypes = {
network: networkPropTypes.isRequired,

...windowDimensionsPropTypes,
...withDrawerPropTypes,
...withLocalizePropTypes,
};

Expand Down Expand Up @@ -154,10 +153,6 @@ class ReportActionsView extends React.Component {
return true;
}

if (this.props.isDrawerOpen !== nextProps.isDrawerOpen) {
return true;
}

if (lodashGet(this.props.report, 'hasOutstandingIOU') !== lodashGet(nextProps.report, 'hasOutstandingIOU')) {
return true;
}
Expand Down Expand Up @@ -186,9 +181,8 @@ class ReportActionsView extends React.Component {

// If the report was previously hidden by the side bar, or the view is expanded from mobile to desktop layout
// we update the new marker position, mark the report as read, and fetch new report actions
const didSidebarClose = prevProps.isDrawerOpen && !this.props.isDrawerOpen;
const didScreenSizeIncrease = prevProps.isSmallScreenWidth && !this.props.isSmallScreenWidth;
const didReportBecomeVisible = isReportFullyVisible && (didSidebarClose || didScreenSizeIncrease);
const didReportBecomeVisible = isReportFullyVisible && didScreenSizeIncrease;
if (didReportBecomeVisible) {
this.setState({
newMarkerReportActionID: ReportUtils.isUnread(this.props.report)
Expand All @@ -206,14 +200,6 @@ class ReportActionsView extends React.Component {
});
}

// When the user navigates to the LHN the ReportActionsView doesn't unmount and just remains hidden.
// The next time we navigate to the same report (e.g. by swiping or tapping the LHN row) we want the new marker to clear.
const didSidebarOpen = !prevProps.isDrawerOpen && this.props.isDrawerOpen;
const didUserNavigateToSidebarAfterReadingReport = didSidebarOpen && !ReportUtils.isUnread(this.props.report);
if (didUserNavigateToSidebarAfterReadingReport) {
this.setState({newMarkerReportActionID: ''});
}

// Checks to see if a report comment has been manually "marked as unread". All other times when the lastReadTime
// changes it will be because we marked the entire report as read.
const didManuallyMarkReportAsUnread = (prevProps.report.lastReadTime !== this.props.report.lastReadTime)
Expand Down Expand Up @@ -250,7 +236,7 @@ class ReportActionsView extends React.Component {
* @returns {Boolean}
*/
getIsReportFullyVisible() {
const isSidebarCoveringReportView = this.props.isSmallScreenWidth && this.props.isDrawerOpen;
const isSidebarCoveringReportView = this.props.isSmallScreenWidth && !this.props.isFocused;
return Visibility.isVisible() && !isSidebarCoveringReportView;
}

Expand Down Expand Up @@ -366,6 +352,7 @@ ReportActionsView.defaultProps = defaultProps;
export default compose(
Performance.withRenderTrace({id: '<ReportActionsView> rendering'}),
withWindowDimensions,
withNavigationFocus,
withLocalize,
withNetwork(),
)(ReportActionsView);
6 changes: 4 additions & 2 deletions src/pages/home/sidebar/SidebarLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import SidebarUtils from '../../../libs/SidebarUtils';
import reportPropTypes from '../../reportPropTypes';
import OfflineWithFeedback from '../../../components/OfflineWithFeedback';
import LHNSkeletonView from '../../../components/LHNSkeletonView';
import withNavigationFocus from '../../../components/withNavigationFocus';

const propTypes = {
/** Toggles the navigation menu open and closed */
Expand Down Expand Up @@ -132,14 +133,14 @@ class SidebarLinks extends React.Component {

render() {
const isLoading = _.isEmpty(this.props.personalDetails) || _.isEmpty(this.props.chatReports);
const shouldFreeze = this.props.isSmallScreenWidth && !this.props.isDrawerOpen && this.isSidebarLoaded;
const shouldFreeze = this.props.isSmallScreenWidth && !this.props.isFocused && this.isSidebarLoaded;
const optionListItems = SidebarUtils.getOrderedReportIDs(this.props.reportIDFromRoute);

const skeletonPlaceholder = <LHNSkeletonView shouldAnimate={!shouldFreeze} />;

return (
<View
accessibilityElementsHidden={this.props.isSmallScreenWidth && !this.props.isDrawerOpen}
accessibilityElementsHidden={this.props.isSmallScreenWidth && !this.props.isFocused}
accessibilityLabel={this.props.translate('sidebarScreen.listOfChats')}
style={[styles.flex1, styles.h100]}
>
Expand Down Expand Up @@ -285,6 +286,7 @@ const policySelector = policy => policy && ({
export default compose(
withLocalize,
withCurrentUserPersonalDetails,
withNavigationFocus,
withWindowDimensions,
withOnyx({
// Note: It is very important that the keys subscribed to here are the same
Expand Down
8 changes: 1 addition & 7 deletions src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import ROUTES from '../../../../ROUTES';
import Timing from '../../../../libs/actions/Timing';
import CONST from '../../../../CONST';
import Performance from '../../../../libs/Performance';
import withDrawerState from '../../../../components/withDrawerState';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../../components/withWindowDimensions';
import compose from '../../../../libs/compose';
import sidebarPropTypes from './sidebarPropTypes';

const propTypes = {
Expand Down Expand Up @@ -60,7 +58,6 @@ class BaseSidebarScreen extends Component {
insets={insets}
onAvatarClick={this.navigateToSettings}
isSmallScreenWidth={this.props.isSmallScreenWidth}
isDrawerOpen={this.props.isDrawerOpen}
reportIDFromRoute={this.props.reportIDFromRoute}
onLayout={this.props.onLayout}
/>
Expand All @@ -75,7 +72,4 @@ class BaseSidebarScreen extends Component {

BaseSidebarScreen.propTypes = propTypes;

export default compose(
withWindowDimensions,
withDrawerState,
)(BaseSidebarScreen);
export default withWindowDimensions(BaseSidebarScreen);
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import ONYXKEYS from '../../../../ONYXKEYS';
import withNavigation from '../../../../components/withNavigation';
import * as Welcome from '../../../../libs/actions/Welcome';
import withNavigationFocus from '../../../../components/withNavigationFocus';
import withDrawerState from '../../../../components/withDrawerState';

/**
* @param {Object} [policy]
Expand Down Expand Up @@ -98,11 +97,6 @@ class FloatingActionButtonAndPopover extends React.Component {
* @return {Boolean}
*/
didScreenBecomeInactive(prevProps) {
// When the Drawer gets closed and ReportScreen is shown
if (!this.props.isDrawerOpen && prevProps.isDrawerOpen) {
return true;
}

// When any other page is opened over LHN
if (!this.props.isFocused && prevProps.isFocused) {
return true;
Expand All @@ -118,11 +112,6 @@ class FloatingActionButtonAndPopover extends React.Component {
* @return {Boolean}
*/
isScreenInactive() {
// When drawer is closed and Report page is open
if (this.props.isSmallScreenWidth && !this.props.isDrawerOpen) {
return true;
}

// When any other page is open
if (!this.props.isFocused) {
return true;
Expand Down Expand Up @@ -241,7 +230,6 @@ export default compose(
withLocalize,
withNavigation,
withNavigationFocus,
withDrawerState,
withWindowDimensions,
withOnyx({
allPolicies: {
Expand Down

0 comments on commit 74798c0

Please sign in to comment.