Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kosmydel committed Dec 11, 2023
1 parent f5e5090 commit 295d1cc
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ const propTypes = {

/** Whether we should navigate to report page when the route have a topMostReport */
shouldNavigateToTopMostReport: PropTypes.bool,

/** Whether we should show the back button only on mobile */
shouldUseCentralPaneView: PropTypes.bool,
};

export default propTypes;
17 changes: 13 additions & 4 deletions src/components/HeaderWithBackButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function HeaderWithBackButton({
shouldShowPinButton = false,
shouldShowThreeDotsButton = false,
shouldDisableThreeDotsButton = false,
shouldShowBackButtonOnlyOnMobile = false,
shouldUseCentralPaneView = false,
stepCounter = null,
subtitle = '',
title = '',
Expand All @@ -65,16 +65,25 @@ function HeaderWithBackButton({
const {isKeyboardShown} = useKeyboardState();
const waitForNavigate = useWaitForNavigation();
const {isSmallScreenWidth} = useWindowDimensions();

const shouldFinalShowBackButton = shouldShowBackButton && (!shouldShowBackButtonOnlyOnMobile || isSmallScreenWidth);
const shouldFinalShowBackButton = shouldShowBackButton && (!shouldUseCentralPaneView || isSmallScreenWidth);
return (
<View
// Hover on some part of close icons will not work on Electron if dragArea is true
// https://github.com/Expensify/App/issues/29598
dataSet={{dragArea: false}}
style={[styles.headerBar, shouldShowBorderBottom && styles.borderBottom, shouldShowBackButton && styles.pl2]}
>
<View style={[styles.dFlex, styles.flexRow, styles.alignItemsCenter, styles.flexGrow1, styles.justifyContentBetween, styles.overflowHidden]}>
<View
style={[
styles.dFlex,
styles.flexRow,
styles.alignItemsCenter,
styles.flexGrow1,
styles.justifyContentBetween,
styles.overflowHidden,
!shouldFinalShowBackButton && styles.pl5,
]}
>
{shouldFinalShowBackButton && (
<Tooltip text={translate('common.back')}>
<PressableWithoutFeedback
Expand Down
11 changes: 3 additions & 8 deletions src/components/IllustratedHeaderPageLayout.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import PropTypes from 'prop-types';
import React from 'react';
import useWindowDimensions from '@hooks/useWindowDimensions';
import useTheme from '@styles/themes/useTheme';
import useThemeStyles from '@styles/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import CONST from '@src/CONST';
import HeaderPageLayout from './HeaderPageLayout';
import headerWithBackButtonPropTypes from './HeaderWithBackButton/headerWithBackButtonPropTypes';
Expand All @@ -25,25 +25,20 @@ const propTypes = {

/** Overlay content to display on top of animation */
overlayContent: PropTypes.func,

/** When a screen is in the central pane, we have to use max height, to make it look good. */
// TODO: Merge this prop with shouldShowBackButtonOnlyOnMobile from HeaderWithBackButton. Can name it like isCentralPaneScreen
shouldUseMaxHeight: PropTypes.bool,
};

const defaultProps = {
backgroundColor: undefined,
footer: null,
overlayContent: null,
shouldUseMaxHeight: false,
};

function IllustratedHeaderPageLayout({backgroundColor, children, illustration, footer, overlayContent, ...propsToPassToHeader}) {
const theme = useTheme();
const styles = useThemeStyles();
const {isSmallScreenWidth} = useWindowDimensions();

const shouldUseMaxHeight = propsToPassToHeader.shouldUseMaxHeight && !isSmallScreenWidth;
const shouldUseMaxHeight = propsToPassToHeader.shouldUseCentralPaneView && !isSmallScreenWidth;

return (
<HeaderPageLayout
Expand All @@ -62,7 +57,7 @@ function IllustratedHeaderPageLayout({backgroundColor, children, illustration, f
</>
}
// TODO: move to variables
headerContainerStyles={[styles.justifyContentCenter, styles.w100, shouldUseMaxHeight && {height: CONST.CENTRAL_PANE_ANIMATION_HEIGHT}]}
headerContainerStyles={[styles.justifyContentCenter, styles.w100, shouldUseMaxHeight && styles.centralPaneAnimation]}
footer={footer}
// eslint-disable-next-line react/jsx-props-no-spreading
{...propsToPassToHeader}
Expand Down
11 changes: 9 additions & 2 deletions src/components/QRShare/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import withThemeStyles, {withThemeStylesPropTypes} from '@components/withThemeSt
import withWindowDimensions, {windowDimensionsPropTypes} from '@components/withWindowDimensions';
import compose from '@libs/compose';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import {qrShareDefaultProps, qrSharePropTypes} from './propTypes';

const propTypes = {
Expand All @@ -35,9 +36,15 @@ class QRShare extends Component {
onLayout(event) {
const containerWidth = event.nativeEvent.layout.width - variables.qrShareHorizontalPadding * 2 || 0;

if (this.props.isSmallScreenWidth) {
this.setState({
qrCodeSize: Math.max(1, containerWidth),
});
return;
}

this.setState({
// TODO: Check on mobile devices
qrCodeSize: Math.max(1, Math.min(containerWidth, 200)),
qrCodeSize: Math.max(1, Math.min(containerWidth, CONST.CENTRAL_PANE_ANIMATION_HEIGHT)),
});
}

Expand Down
3 changes: 1 addition & 2 deletions src/pages/ShareCodePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ShareCodePage extends React.Component {
<HeaderWithBackButton
title={this.props.translate('common.shareCode')}
onBackButtonPress={() => Navigation.goBack(isReport ? ROUTES.REPORT_WITH_ID_DETAILS.getRoute(this.props.report.reportID) : ROUTES.SETTINGS_HOME)}
shouldShowBackButtonOnlyOnMobile
shouldUseCentralPaneView
/>

<ScrollView style={[this.props.themeStyles.flex1, this.props.themeStyles.mt3]}>
Expand All @@ -95,7 +95,6 @@ class ShareCodePage extends React.Component {
logo={isReport ? expensifyLogo : UserUtils.getAvatarUrl(this.props.currentUserPersonalDetails.avatar, this.props.currentUserPersonalDetails.accountID)}
logoRatio={isReport ? CONST.QR.EXPENSIFY_LOGO_SIZE_RATIO : CONST.QR.DEFAULT_LOGO_SIZE_RATIO}
logoMarginRatio={isReport ? CONST.QR.EXPENSIFY_LOGO_MARGIN_RATIO : CONST.QR.DEFAULT_LOGO_MARGIN_RATIO}
shareCodeContainer={[{height: 100}]}
/>
</View>

Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/AboutPage/AboutPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function AboutPage(props) {
<HeaderWithBackButton
title={props.translate('initialSettingsPage.about')}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_HOME)}
shouldShowBackButtonOnlyOnMobile
shouldUseCentralPaneView
/>
<ScrollView contentContainerStyle={[styles.flexGrow1, styles.flexColumn, styles.justifyContentBetween, safeAreaPaddingBottomStyle]}>
<View style={[styles.flex1]}>
Expand Down
3 changes: 1 addition & 2 deletions src/pages/settings/Preferences/PreferencesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ function PreferencesPage(props) {
// onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS)}
backgroundColor={theme.PAGE_THEMES[SCREENS.SETTINGS.PREFERENCES].backgroundColor}
illustration={LottieAnimations.PreferencesDJ}
shouldUseMaxHeight
shouldShowBackButtonOnlyOnMobile
shouldUseCentralPaneView
>
<View style={styles.mb6}>
<Text
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/Profile/ProfilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function ProfilePage(props) {
<HeaderWithBackButton
title={props.translate('common.profile')}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_HOME)}
shouldShowBackButtonOnlyOnMobile
shouldUseCentralPaneView
/>
<ScrollView>
<AvatarWithImagePicker
Expand Down
3 changes: 1 addition & 2 deletions src/pages/settings/Security/SecuritySettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ function SecuritySettingsPage(props) {
shouldShowBackButton
illustration={LottieAnimations.Safe}
backgroundColor={theme.PAGE_THEMES[SCREENS.SETTINGS.SECURITY].backgroundColor}
shouldShowBackButtonOnlyOnMobile
shouldUseMaxHeight
shouldUseCentralPaneView
>
<ScrollView contentContainerStyle={[styles.flexGrow1, styles.flexColumn, styles.justifyContentBetween]}>
<View style={[styles.flex1]}>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/Wallet/WalletPage/WalletPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ function WalletPage({bankAccountList, cardList, fundList, isLoadingPaymentMethod
<HeaderWithBackButton
title={translate('common.wallet')}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_HOME)}
shouldShowBackButtonOnlyOnMobile
shouldUseCentralPaneView
/>
<View style={[styles.flex1, styles.mb4]}>
<ScrollView>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspacesListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function WorkspacesListPage({policies, allPolicyMembers, reimbursementAccount, u
illustration={LottieAnimations.WorkspacePlanet}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_HOME)}
title={translate('common.workspaces')}
shouldShowBackButtonOnlyOnMobile
shouldUseCentralPaneView
footer={
<Button
accessibilityLabel={translate('workspace.new.newWorkspace')}
Expand Down
4 changes: 4 additions & 0 deletions src/styles/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2448,6 +2448,10 @@ const styles = (theme: ThemeColors) =>
...spacing.pt0,
},

centralPaneAnimation: {
height: CONST.CENTRAL_PANE_ANIMATION_HEIGHT,
},

sectionTitle: {
...spacing.pt2,
...spacing.pr3,
Expand Down

0 comments on commit 295d1cc

Please sign in to comment.