Skip to content

Commit

Permalink
Merge pull request #43961 from rayane-djouah/Replace-usages-of-is-use…
Browse files Browse the repository at this point in the history
…WindowDimensions-with-useResponsiveLayout-in-pages-folder

[No QA] Replace usages of useWindowDimensions with useResponsiveLayout hook in pages folder
  • Loading branch information
roryabraham authored Jul 25, 2024
2 parents 266d4cb + c267426 commit 9d8f5d6
Show file tree
Hide file tree
Showing 71 changed files with 325 additions and 326 deletions.
22 changes: 11 additions & 11 deletions src/components/FeatureTrainingModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {GestureHandlerRootView} from 'react-native-gesture-handler';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnboardingLayout from '@hooks/useOnboardingLayout';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import Navigation from '@libs/Navigation/Navigation';
import variables from '@styles/variables';
import * as User from '@userActions/User';
Expand Down Expand Up @@ -85,13 +85,13 @@ function FeatureTrainingModal({
}: FeatureTrainingModalProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {shouldUseNarrowLayout} = useOnboardingLayout();
const {isMediumOrLargerScreenWidth} = useOnboardingLayout();
const [isModalVisible, setIsModalVisible] = useState(true);
const [willShowAgain, setWillShowAgain] = useState(true);
const [videoStatus, setVideoStatus] = useState<VideoStatus>('video');
const [isVideoStatusLocked, setIsVideoStatusLocked] = useState(false);
const [videoAspectRatio, setVideoAspectRatio] = useState(videoAspectRatioProp ?? VIDEO_ASPECT_RATIO);
const {isSmallScreenWidth} = useWindowDimensions();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const {isOffline} = useNetwork();

useEffect(() => {
Expand Down Expand Up @@ -148,15 +148,15 @@ function FeatureTrainingModal({
<Lottie
source={animation ?? LottieAnimations.Hands}
style={styles.h100}
webStyle={isSmallScreenWidth ? styles.h100 : undefined}
webStyle={shouldUseNarrowLayout ? styles.h100 : undefined}
autoPlay
loop
/>
</View>
)}
</View>
);
}, [animation, videoURL, videoAspectRatio, videoStatus, isSmallScreenWidth, styles]);
}, [animation, videoURL, videoAspectRatio, videoStatus, shouldUseNarrowLayout, styles]);

const toggleWillShowAgain = useCallback(() => setWillShowAgain((prevWillShowAgain) => !prevWillShowAgain), []);

Expand All @@ -178,14 +178,14 @@ function FeatureTrainingModal({
{({safeAreaPaddingBottomStyle}) => (
<Modal
isVisible={isModalVisible}
type={shouldUseNarrowLayout ? CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE : CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED}
type={isMediumOrLargerScreenWidth ? CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE : CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED}
onClose={closeModal}
innerContainerStyle={{
boxShadow: 'none',
borderRadius: 16,
paddingBottom: 20,
paddingTop: shouldUseNarrowLayout ? undefined : MODAL_PADDING,
...(shouldUseNarrowLayout
paddingTop: isMediumOrLargerScreenWidth ? undefined : MODAL_PADDING,
...(isMediumOrLargerScreenWidth
? // Override styles defined by MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE
// To make it take as little space as possible.
{
Expand All @@ -196,11 +196,11 @@ function FeatureTrainingModal({
}}
>
<GestureHandlerRootView>
<View style={[styles.mh100, shouldUseNarrowLayout && styles.welcomeVideoNarrowLayout, safeAreaPaddingBottomStyle]}>
<View style={shouldUseNarrowLayout ? {padding: MODAL_PADDING} : {paddingHorizontal: MODAL_PADDING}}>{renderIllustration()}</View>
<View style={[styles.mh100, isMediumOrLargerScreenWidth && styles.welcomeVideoNarrowLayout, safeAreaPaddingBottomStyle]}>
<View style={isMediumOrLargerScreenWidth ? {padding: MODAL_PADDING} : {paddingHorizontal: MODAL_PADDING}}>{renderIllustration()}</View>
<View style={[styles.mt5, styles.mh5]}>
{title && description && (
<View style={[shouldUseNarrowLayout ? [styles.gap1, styles.mb8] : [styles.mb10]]}>
<View style={[isMediumOrLargerScreenWidth ? [styles.gap1, styles.mb8] : [styles.mb10]]}>
<Text style={[styles.textHeadlineH1]}>{title}</Text>
<Text style={styles.textSupporting}>{description}</Text>
{secondaryDescription.length > 0 && <Text style={[styles.textSupporting, styles.mt4]}>{secondaryDescription}</Text>}
Expand Down
9 changes: 0 additions & 9 deletions src/hooks/useIsReportOpenInRHP.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/hooks/useOnboardingLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {useWindowDimensions} from 'react-native';
import variables from '@styles/variables';

type OnboardingLayout = {
shouldUseNarrowLayout: boolean;
isMediumOrLargerScreenWidth: boolean;
};

/**
Expand All @@ -15,5 +15,5 @@ type OnboardingLayout = {
export default function useOnboardingLayout(): OnboardingLayout {
const {width: windowWidth} = useWindowDimensions();

return {shouldUseNarrowLayout: windowWidth > variables.mobileResponsiveWidthBreakpoint};
return {isMediumOrLargerScreenWidth: windowWidth > variables.mobileResponsiveWidthBreakpoint};
}
6 changes: 3 additions & 3 deletions src/hooks/useThumbnailDimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {useMemo} from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import type {DimensionValue} from 'react-native/Libraries/StyleSheet/StyleSheetTypes';
import CONST from '@src/CONST';
import useIsReportOpenInRHP from './useIsReportOpenInRHP';
import useResponsiveLayout from './useResponsiveLayout';
import useWindowDimensions from './useWindowDimensions';

type ThumbnailDimensions = {
Expand All @@ -14,9 +14,9 @@ type ThumbnailDimensions = {
};

export default function useThumbnailDimensions(width: number, height: number): ThumbnailDimensions {
const isReportOpenInRHP = useIsReportOpenInRHP();
const {isInNarrowPaneModal} = useResponsiveLayout();
const {isSmallScreenWidth} = useWindowDimensions();
const shouldUseNarrowLayout = isSmallScreenWidth || isReportOpenInRHP;
const shouldUseNarrowLayout = isSmallScreenWidth || isInNarrowPaneModal;
const fixedDimension = shouldUseNarrowLayout ? CONST.THUMBNAIL_IMAGE.SMALL_SCREEN.SIZE : CONST.THUMBNAIL_IMAGE.WIDE_SCREEN.SIZE;
const thumbnailDimensionsStyles = useMemo(() => {
if (!width || !height) {
Expand Down
8 changes: 4 additions & 4 deletions src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,14 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {isSmallScreenWidth} = useWindowDimensions();
const {shouldUseNarrowLayout} = useOnboardingLayout();
const {isMediumOrLargerScreenWidth} = useOnboardingLayout();
const screenOptions = getRootNavigatorScreenOptions(isSmallScreenWidth, styles, StyleUtils);
const {canUseDefaultRooms} = usePermissions();
const {activeWorkspaceID} = useActiveWorkspace();
const onboardingModalScreenOptions = useMemo(() => screenOptions.onboardingModalNavigator(shouldUseNarrowLayout), [screenOptions, shouldUseNarrowLayout]);
const onboardingModalScreenOptions = useMemo(() => screenOptions.onboardingModalNavigator(isMediumOrLargerScreenWidth), [screenOptions, isMediumOrLargerScreenWidth]);
const onboardingScreenOptions = useMemo(
() => getOnboardingModalScreenOptions(isSmallScreenWidth, styles, StyleUtils, shouldUseNarrowLayout),
[StyleUtils, isSmallScreenWidth, shouldUseNarrowLayout, styles],
() => getOnboardingModalScreenOptions(isSmallScreenWidth, styles, StyleUtils, isMediumOrLargerScreenWidth),
[StyleUtils, isSmallScreenWidth, isMediumOrLargerScreenWidth, styles],
);

let initialReportID: string | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Stack = createStackNavigator<OnboardingModalNavigatorParamList>();

function OnboardingModalNavigator() {
const styles = useThemeStyles();
const {shouldUseNarrowLayout} = useOnboardingLayout();
const {isMediumOrLargerScreenWidth} = useOnboardingLayout();
const [hasCompletedGuidedSetupFlow] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {
selector: hasCompletedGuidedSetupFlowSelector,
});
Expand Down Expand Up @@ -67,7 +67,7 @@ function OnboardingModalNavigator() {
<FocusTrapForScreens>
<View
onClick={(e) => e.stopPropagation()}
style={styles.OnboardingNavigatorInnerView(shouldUseNarrowLayout)}
style={styles.OnboardingNavigatorInnerView(isMediumOrLargerScreenWidth)}
>
<Stack.Navigator screenOptions={OnboardingModalNavigatorScreenOptions()}>
<Stack.Screen
Expand Down
10 changes: 5 additions & 5 deletions src/pages/ErrorPage/UpdateRequiredView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ import Lottie from '@components/Lottie';
import LottieAnimations from '@components/LottieAnimations';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useSafeAreaInsets from '@hooks/useSafeAreaInsets';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as AppUpdate from '@libs/actions/AppUpdate';

function UpdateRequiredView() {
const insets = useSafeAreaInsets();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
const {isSmallScreenWidth} = useWindowDimensions();
const {shouldUseNarrowLayout} = useResponsiveLayout();
return (
<View style={[styles.appBG, styles.h100, StyleUtils.getSafeAreaPadding(insets)]}>
<HeaderGap />
<View style={[styles.pt5, styles.ph5, styles.updateRequiredViewHeader]}>
<Header title={translate('updateRequiredView.updateRequired')} />
</View>
<View style={[styles.flex1, StyleUtils.getUpdateRequiredViewStyles(isSmallScreenWidth)]}>
<View style={[styles.flex1, StyleUtils.getUpdateRequiredViewStyles(shouldUseNarrowLayout)]}>
<Lottie
source={LottieAnimations.Update}
// For small screens it looks better to have the arms from the animation come in from the edges of the screen.
style={isSmallScreenWidth ? styles.w100 : styles.updateAnimation}
webStyle={isSmallScreenWidth ? styles.w100 : styles.updateAnimation}
style={shouldUseNarrowLayout ? styles.w100 : styles.updateAnimation}
webStyle={shouldUseNarrowLayout ? styles.w100 : styles.updateAnimation}
autoPlay
loop
/>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/GetAssistancePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import ScrollView from '@components/ScrollView';
import Section from '@components/Section';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import Navigation from '@libs/Navigation/Navigation';
import type {SettingsNavigatorParamList} from '@libs/Navigation/types';
import * as Link from '@userActions/Link';
Expand All @@ -35,7 +35,7 @@ function GetAssistancePage({route, account}: GetAssistancePageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const navigateBackTo = route?.params.backTo || ROUTES.SETTINGS_CONTACT_METHODS.getRoute();
const {isLargeScreenWidth} = useWindowDimensions();
const {isLargeScreenWidth} = useResponsiveLayout();
const menuItems: MenuItemWithLink[] = [
{
title: translate('getAssistancePage.chatWithConcierge'),
Expand Down
4 changes: 2 additions & 2 deletions src/pages/NewChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'
import useDebouncedState from '@hooks/useDebouncedState';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useScreenWrapperTranstionStatus from '@hooks/useScreenWrapperTransitionStatus';
import useStyledSafeAreaInsets from '@hooks/useStyledSafeAreaInsets';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -147,7 +147,7 @@ function useOptions({isGroupChat}: NewChatPageProps) {
function NewChatPage({isGroupChat}: NewChatPageProps) {
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const {isSmallScreenWidth} = useWindowDimensions();
const {isSmallScreenWidth} = useResponsiveLayout();
const styles = useThemeStyles();
const personalData = useCurrentUserPersonalDetails();
const {insets} = useStyledSafeAreaInsets();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function BaseOnboardingPersonalDetails({
const styles = useThemeStyles();
const {translate} = useLocalize();
const {isSmallScreenWidth} = useWindowDimensions();
const {shouldUseNarrowLayout} = useOnboardingLayout();
const {isMediumOrLargerScreenWidth} = useOnboardingLayout();
const {inputCallbackRef} = useAutoFocusInput();
const [shouldValidateOnChange, setShouldValidateOnChange] = useState(false);
const {accountID} = useSession();
Expand Down Expand Up @@ -143,7 +143,7 @@ function BaseOnboardingPersonalDetails({
onBackButtonPress={Navigation.goBack}
/>
<FormProvider
style={[styles.flexGrow1, shouldUseNarrowLayout && styles.mt5, shouldUseNarrowLayout ? styles.mh8 : styles.mh5]}
style={[styles.flexGrow1, isMediumOrLargerScreenWidth && styles.mt5, isMediumOrLargerScreenWidth ? styles.mh8 : styles.mh5]}
formID={ONYXKEYS.FORMS.ONBOARDING_PERSONAL_DETAILS_FORM}
footerContent={isSmallScreenWidth && PersonalDetailsFooterInstance}
validate={validate}
Expand All @@ -155,7 +155,7 @@ function BaseOnboardingPersonalDetails({
shouldValidateOnChange={shouldValidateOnChange}
shouldTrimValues={false}
>
<View style={[shouldUseNarrowLayout ? styles.flexRow : styles.flexColumn, styles.mb5]}>
<View style={[isMediumOrLargerScreenWidth ? styles.flexRow : styles.flexColumn, styles.mb5]}>
<Text style={styles.textHeadlineH1}>{translate('onboarding.whatsYourName')}</Text>
</View>
<View style={styles.mb4}>
Expand Down
15 changes: 9 additions & 6 deletions src/pages/OnboardingPurpose/BaseOnboardingPurpose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import SafeAreaConsumer from '@components/SafeAreaConsumer';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useOnboardingLayout from '@hooks/useOnboardingLayout';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
Expand All @@ -41,9 +42,11 @@ const menuIcons = {
function BaseOnboardingPurpose({shouldUseNativeStyles, shouldEnableMaxHeight}: BaseOnboardingPurposeProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {shouldUseNarrowLayout} = useOnboardingLayout();
const {isMediumOrLargerScreenWidth} = useOnboardingLayout();
const [selectedPurpose, setSelectedPurpose] = useState<OnboardingPurposeType | undefined>(undefined);
const {isSmallScreenWidth, windowHeight} = useWindowDimensions();
const {windowHeight} = useWindowDimensions();
const {isSmallScreenWidth} = useResponsiveLayout();

const theme = useTheme();
const [onboardingPurposeSelected, onboardingPurposeSelectedResult] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED);
const [onboardingErrorMessage, onboardingErrorMessageResult] = useOnyx(ONYXKEYS.ONBOARDING_ERROR_MESSAGE);
Expand All @@ -56,7 +59,7 @@ function BaseOnboardingPurpose({shouldUseNativeStyles, shouldEnableMaxHeight}: B

const maxHeight = shouldEnableMaxHeight ? windowHeight : undefined;

const paddingHorizontal = shouldUseNarrowLayout ? styles.ph8 : styles.ph5;
const paddingHorizontal = isMediumOrLargerScreenWidth ? styles.ph8 : styles.ph5;

const selectedCheckboxIcon = useMemo(
() => (
Expand Down Expand Up @@ -126,16 +129,16 @@ function BaseOnboardingPurpose({shouldUseNativeStyles, shouldEnableMaxHeight}: B
<SafeAreaConsumer>
{({safeAreaPaddingBottomStyle}) => (
<View style={[{maxHeight}, styles.h100, styles.defaultModalContainer, shouldUseNativeStyles && styles.pt8, safeAreaPaddingBottomStyle]}>
<View style={shouldUseNarrowLayout && styles.mh3}>
<View style={isMediumOrLargerScreenWidth && styles.mh3}>
<HeaderWithBackButton
shouldShowBackButton={false}
iconFill={theme.iconColorfulBackground}
progressBarPercentage={25}
/>
</View>
<ScrollView style={[styles.flex1, styles.flexGrow1, shouldUseNarrowLayout && styles.mt5, paddingHorizontal]}>
<ScrollView style={[styles.flex1, styles.flexGrow1, isMediumOrLargerScreenWidth && styles.mt5, paddingHorizontal]}>
<View style={styles.flex1}>
<View style={[shouldUseNarrowLayout ? styles.flexRow : styles.flexColumn, styles.mb5]}>
<View style={[isMediumOrLargerScreenWidth ? styles.flexRow : styles.flexColumn, styles.mb5]}>
<Text style={styles.textHeadlineH1}>{translate('onboarding.purpose.title')} </Text>
</View>
<MenuItemList
Expand Down
Loading

0 comments on commit 9d8f5d6

Please sign in to comment.