Skip to content

Commit

Permalink
Adjust designs for medium sized screens
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuuszzzzz committed Feb 12, 2024
1 parent 30b7411 commit 1895d18
Show file tree
Hide file tree
Showing 18 changed files with 225 additions and 66 deletions.
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ const CONST = {
BOTTOM_DOCKED: 'bottom_docked',
POPOVER: 'popover',
RIGHT_DOCKED: 'right_docked',
ONBOARDING: 'onboarding',
},
ANCHOR_ORIGIN_VERTICAL: {
TOP: 'top',
Expand Down
4 changes: 1 addition & 3 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,8 @@ const ROUTES = {
getRoute: (contentType: string) => `referral/${contentType}` as const,
},
PROCESS_MONEY_REQUEST_HOLD: 'hold-request-educational',
ONBOARDING_WELCOME: 'onboarding/welcome',
ONBOARDING_PERSONAL_DETAILS: 'onboarding/personal-details',
ONBOARDING_PURPOSE: 'onboarding/purpose',
WELCOME: 'welcome',
PURPOSE: 'purpose',
} as const;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ const SCREENS = {
},

ONBOARDING: {
WELCOME: 'Onboarding_Welcome',
PERSONAL_DETAILS: 'Onboarding_Personal_Details',
PURPOSE: 'Onboarding_Purpose',
},

Expand Down
10 changes: 7 additions & 3 deletions src/components/Modal/BaseModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {View} from 'react-native';
import ReactNativeModal from 'react-native-modal';
import ColorSchemeWrapper from '@components/ColorSchemeWrapper';
import useKeyboardState from '@hooks/useKeyboardState';
import useOnboardingLayout from '@hooks/useOnboardingLayout';
import usePrevious from '@hooks/usePrevious';
import useSafeAreaInsets from '@hooks/useSafeAreaInsets';
import useStyleUtils from '@hooks/useStyleUtils';
Expand All @@ -22,6 +23,7 @@ function BaseModal(
isVisible,
onClose,
shouldSetModalVisibility = true,
shouldForceHideBackdrop = false,
onModalHide = () => {},
type,
popoverAnchorPosition = {},
Expand All @@ -48,6 +50,7 @@ function BaseModal(
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {windowWidth, windowHeight, isSmallScreenWidth} = useWindowDimensions();
const {shouldUseNarrowLayout} = useOnboardingLayout();
const keyboardStateContextValue = useKeyboardState();

const safeAreaInsets = useSafeAreaInsets();
Expand Down Expand Up @@ -147,8 +150,9 @@ function BaseModal(
popoverAnchorPosition,
innerContainerStyle,
outerStyle,
shouldUseNarrowLayout,
),
[StyleUtils, type, windowWidth, windowHeight, isSmallScreenWidth, popoverAnchorPosition, innerContainerStyle, outerStyle],
[StyleUtils, type, windowWidth, windowHeight, isSmallScreenWidth, popoverAnchorPosition, innerContainerStyle, outerStyle, shouldUseNarrowLayout],
);

const {
Expand Down Expand Up @@ -189,9 +193,9 @@ function BaseModal(
swipeDirection={swipeDirection}
isVisible={isVisible}
backdropColor={theme.overlay}
backdropOpacity={!shouldUseCustomBackdrop && hideBackdrop ? 0 : variables.overlayOpacity}
backdropOpacity={(!shouldUseCustomBackdrop && hideBackdrop) || shouldForceHideBackdrop ? 0 : variables.overlayOpacity}
backdropTransitionOutTiming={0}
hasBackdrop={false}
hasBackdrop={fullscreen}
coverScreen={fullscreen}
style={modalStyle}
deviceHeight={windowHeight}
Expand Down
3 changes: 3 additions & 0 deletions src/components/Modal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type BaseModalProps = Partial<ModalProps> & {
/** Should we announce the Modal visibility changes? */
shouldSetModalVisibility?: boolean;

/** Should we hide backdrop no matter what value is set in modal styles */
shouldForceHideBackdrop?: boolean;

/** Callback method fired when the user requests to close the modal */
onClose: () => void;

Expand Down
16 changes: 16 additions & 0 deletions src/hooks/useOnboardingLayout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// eslint-disable-next-line no-restricted-imports
import {useWindowDimensions} from 'react-native';
import variables from '@styles/variables';

type OnboardingLayout = {
shouldUseNarrowLayout: boolean;
};

/**
* Onboarding layout for medium screen width is narrowed similarly as on web/desktop.
*/
export default function useOnboardingLayout(): OnboardingLayout {
const {width: windowWidth} = useWindowDimensions();

return {shouldUseNarrowLayout: windowWidth > variables.mobileResponsiveWidthBreakpoint};
}
3 changes: 3 additions & 0 deletions src/hooks/useWindowDimensions/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// eslint-disable-next-line no-restricted-imports
import {Dimensions, useWindowDimensions} from 'react-native';
import Log from '@libs/Log';
import variables from '@styles/variables';
import type WindowDimensions from './types';

Expand All @@ -15,6 +16,8 @@ export default function (): WindowDimensions {
const isMediumScreenWidth = windowWidth > variables.mobileResponsiveWidthBreakpoint && windowWidth <= variables.tabletResponsiveWidthBreakpoint;
const isLargeScreenWidth = windowWidth > variables.tabletResponsiveWidthBreakpoint;

Log.info(`WINDOW WIDTH ${windowWidth}`);

return {
windowWidth,
windowHeight,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import BottomTabNavigator from './Navigators/BottomTabNavigator';
import CentralPaneNavigator from './Navigators/CentralPaneNavigator';
import FullScreenNavigator from './Navigators/FullScreenNavigator';
import LeftModalNavigator from './Navigators/LeftModalNavigator';
import RightModalNavigator from './Navigators/RightModalNavigator';
import OnboardingModalNavigator from './Navigators/OnboardingModalNavigator';
import RightModalNavigator from './Navigators/RightModalNavigator';

type AuthScreensProps = {
/** Session of currently logged in user */
Expand Down
4 changes: 2 additions & 2 deletions src/libs/Navigation/AppNavigator/ModalStackNavigators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ const ProcessMoneyRequestHoldStackNavigator = createModalStackNavigator({
});

const OnboardingModalStackNavigator = createModalStackNavigator({
[SCREENS.ONBOARDING.WELCOME]: () => require('../../../../src/components/PurposeForUsingExpensifyModal').default as React.ComponentType,
[SCREENS.ONBOARDING.PERSONAL_DETAILS]: () => require('../../../../src/components/PurposeForUsingExpensifyModal').default as React.ComponentType,
[SCREENS.ONBOARDING.PURPOSE]: () => require('../../../../src/components/PurposeForUsingExpensifyModal').default as React.ComponentType,
})
});

export {
AccountSettingsModalStackNavigator,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,38 @@
import React, { useMemo } from 'react';
import {createStackNavigator} from '@react-navigation/stack';
import React, {useMemo} from 'react';
import {View} from 'react-native';
import NoDropZone from "@components/DragAndDrop/NoDropZone";
import type { OnboardingModalNavigatorParamList } from "@libs/Navigation/types";
import { createStackNavigator } from "@react-navigation/stack";
import SCREENS from "@src/SCREENS";
import ModalNavigatorScreenOptions from '@libs/Navigation/AppNavigator/ModalNavigatorScreenOptions';
import NoDropZone from '@components/DragAndDrop/NoDropZone';
import useThemeStyles from '@hooks/useThemeStyles';
// import * as ModalStackNavigators from '@libs/Navigation/AppNavigator/ModalStackNavigators';
import PurposeForUsingExpensifyModal from '@components/PurposeForUsingExpensifyModal';
import useWindowDimensions from '@hooks/useWindowDimensions';
import Overlay from './Overlay';
import ModalNavigatorScreenOptions from '@libs/Navigation/AppNavigator/ModalNavigatorScreenOptions';
import type {OnboardingModalNavigatorParamList} from '@libs/Navigation/types';
import OnboardingPersonalDetails from '@pages/OnboardingPersonalDetails';
import OnboardingPurpose from '@pages/OnboardingPurpose';
import SCREENS from '@src/SCREENS';

const Stack = createStackNavigator<OnboardingModalNavigatorParamList>();

function OnboardingModalNavigator() {

const styles = useThemeStyles();
const screenOptions = useMemo(() => ModalNavigatorScreenOptions(styles), [styles]);
const {isSmallScreenWidth} = useWindowDimensions();

return <NoDropZone>
<View>
{!isSmallScreenWidth && <Overlay onPress={() => {}}/>}
<Stack.Navigator screenOptions={{...screenOptions, cardStyle: {backgroundColor: 'transparent'}}}>
{/* <Stack.Screen
name={SCREENS.ONBOARDING_MODAL.ONBOARDING}
component={ModalStackNavigators.OnboardingModalStackNavigator}
/> */}
<Stack.Screen
name={SCREENS.ONBOARDING.WELCOME}
component={PurposeForUsingExpensifyModal}
/>
<Stack.Screen
name={SCREENS.ONBOARDING.PURPOSE}
component={PurposeForUsingExpensifyModal}
/>
</Stack.Navigator>
</View>
</NoDropZone>
return (
<NoDropZone>
<View>
<Stack.Navigator screenOptions={{...screenOptions}}>
<Stack.Screen
name={SCREENS.ONBOARDING.PERSONAL_DETAILS}
component={OnboardingPersonalDetails}
/>
<Stack.Screen
name={SCREENS.ONBOARDING.PURPOSE}
component={OnboardingPurpose}
/>
</Stack.Navigator>
</View>
</NoDropZone>
);
}

OnboardingModalNavigator.displayName = 'OnboardingModalNavigator';

export default OnboardingModalNavigator;
export default OnboardingModalNavigator;
18 changes: 15 additions & 3 deletions src/libs/Navigation/AppNavigator/Navigators/Overlay.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import {useCardAnimation} from '@react-navigation/stack';
import React from 'react';
import React, {useMemo} from 'react';
import {Animated, View} from 'react-native';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
import useLocalize from '@hooks/useLocalize';
import useOnboardingLayout from '@hooks/useOnboardingLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import getOperatingSystem from '@libs/getOperatingSystem';
import CONST from '@src/CONST';

type OverlayProps = {
/* Callback to close the modal */
onPress: () => void;
onPress?: () => void;

/* Returns whether a modal is displayed on the left side of the screen. By default, the modal is displayed on the right */
isModalOnTheLeft?: boolean;
Expand All @@ -18,9 +20,19 @@ function Overlay({onPress, isModalOnTheLeft = false}: OverlayProps) {
const styles = useThemeStyles();
const {current} = useCardAnimation();
const {translate} = useLocalize();
const {shouldUseNarrowLayout} = useOnboardingLayout();

// non-native styling uses fixed positioning not supported on native platforms
const shouldUseNativeStyles = useMemo(() => {
const os = getOperatingSystem();
if ((os === CONST.OS.ANDROID || os === CONST.OS.IOS || os === CONST.OS.NATIVE) && shouldUseNarrowLayout) {
return true;
}
return false;
}, [shouldUseNarrowLayout]);

return (
<Animated.View style={styles.overlayStyles(current, isModalOnTheLeft)}>
<Animated.View style={shouldUseNativeStyles ? styles.nativeOverlayStyles(current) : styles.overlayStyles(current, isModalOnTheLeft)}>
<View style={[styles.flex1, styles.flexColumn]}>
{/* In the latest Electron version buttons can't be both clickable and draggable.
That's why we added this workaround. Because of two Pressable components on the desktop app
Expand Down
6 changes: 5 additions & 1 deletion src/libs/Navigation/NavigationRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ function parseAndLogRoute(state: NavigationState) {
return;
}

Log.info(`Current state ${JSON.stringify(state)}`);

const currentPath = customGetPathFromState(state, linkingConfig.config);

const focusedRoute = findFocusedRoute(state);
Expand Down Expand Up @@ -74,6 +76,8 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N
return undefined;
}

return undefined;

const path = initialUrl ? getPathFromURL(initialUrl) : null;

Check failure on line 81 in src/libs/Navigation/NavigationRoot.tsx

View workflow job for this annotation

GitHub Actions / typecheck

Argument of type 'string | null' is not assignable to parameter of type 'string'.

// For non-nullable paths we don't want to set initial state
Expand Down Expand Up @@ -118,7 +122,7 @@ function NavigationRoot({authenticated, lastVisitedPath, initialUrl, onReady}: N
if (!state) {
return;
}
Log.info("STATE");
Log.info('STATE');
Log.info(JSON.stringify(state));
const activeWorkspaceID = getPolicyIDFromState(state as NavigationState<RootStackParamList>);
// Performance optimization to avoid context consumers to delay first render
Expand Down
22 changes: 5 additions & 17 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,15 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
},
[NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR]: {
screens: {
// [SCREENS.ONBOARDING_MODAL.ONBOARDING]: {
// screens: {
// [SCREENS.ONBOARDING.WELCOME]: {
// path: ROUTES.ONBOARDING_WELCOME,
// exact: true,
// },
// [SCREENS.ONBOARDING.PURPOSE]: {
// path: ROUTES.ONBOARDING_PURPOSE,
// exact: true,
// },
// }
// },
[SCREENS.ONBOARDING.WELCOME]: {
path: ROUTES.WELCOME,
[SCREENS.ONBOARDING.PERSONAL_DETAILS]: {
path: ROUTES.ONBOARDING_PERSONAL_DETAILS,
exact: true,
},
[SCREENS.ONBOARDING.PURPOSE]: {
path: ROUTES.PURPOSE,
path: ROUTES.ONBOARDING_PURPOSE,
exact: true,
}
}
},
},
},
[NAVIGATORS.RIGHT_MODAL_NAVIGATOR]: {
screens: {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ type FullScreenNavigatorParamList = {

type OnboardingModalNavigatorParamList = {
[SCREENS.ONBOARDING_MODAL.ONBOARDING]: undefined;
[SCREENS.ONBOARDING.WELCOME]: undefined;
[SCREENS.ONBOARDING.PERSONAL_DETAILS]: undefined;
[SCREENS.ONBOARDING.PURPOSE]: undefined;
};

Expand Down
46 changes: 46 additions & 0 deletions src/pages/OnboardingPersonalDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, {useCallback, useState} from 'react';
import {View} from 'react-native';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import Modal from '@components/Modal';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import Navigation from '@libs/Navigation/Navigation';
import * as Report from '@userActions/Report';
import CONST from '@src/CONST';

function OnboardingPersonalDetails() {
const styles = useThemeStyles();
const {windowHeight} = useWindowDimensions();
const [isModalOpen, setIsModalOpen] = useState(true);
const theme = useTheme();

const closeModal = useCallback(() => {
Report.dismissEngagementModal();
Navigation.goBack();
setIsModalOpen(false);
}, []);

return (
<Modal
type={CONST.MODAL.MODAL_TYPE.ONBOARDING}
isVisible={isModalOpen}
onClose={closeModal}
innerContainerStyle={styles.pt0}
shouldUseCustomBackdrop
>
<View style={{maxHeight: windowHeight}}>
<HeaderWithBackButton
shouldShowCloseButton
shouldShowBackButton={false}
onCloseButtonPress={closeModal}
shouldOverlay
iconFill={theme.iconColorfulBackground}
/>
</View>
</Modal>
);
}

OnboardingPersonalDetails.displayName = 'OnboardingPersonalDetails';
export default OnboardingPersonalDetails;
Loading

0 comments on commit 1895d18

Please sign in to comment.