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

[No QA] Replace usages of useWindowDimensions with useResponsiveLayout hook in pages folder #43961

Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
81f0653
Replace usages of useWindowDimensions with useResponsiveLayout hook
rayane-djouah Jun 18, 2024
bca35cf
Merge branch 'main' into Replace-usages-of-is-useWindowDimensions-wit…
rayane-djouah Jun 18, 2024
cbbb79a
replace useIsReportOpenInRHP with useResponsiveLayout
rayane-djouah Jun 18, 2024
38cc6b0
Fix type error
rayane-djouah Jun 18, 2024
0f21ec8
Fix type error
rayane-djouah Jun 18, 2024
9ad5d26
Merge branch 'main' into Replace-usages-of-is-useWindowDimensions-wit…
rayane-djouah Jun 21, 2024
62171c5
Merge branch 'main' into Replace-usages-of-is-useWindowDimensions-wit…
rayane-djouah Jun 21, 2024
962dab5
Merge branch 'main' into Replace-usages-of-is-useWindowDimensions-wit…
rayane-djouah Jun 26, 2024
54b1250
fix lint errors
rayane-djouah Jun 26, 2024
defc32a
prettier
rayane-djouah Jun 26, 2024
67e6c56
Merge branch 'main' into Replace-usages-of-is-useWindowDimensions-wit…
rayane-djouah Jul 8, 2024
3704ee1
Merge branch 'main' into Replace-usages-of-is-useWindowDimensions-wit…
rayane-djouah Jul 8, 2024
9c7df68
fix lint error
rayane-djouah Jul 8, 2024
72bd5fa
Merge branch 'main' into Replace-usages-of-is-useWindowDimensions-wit…
rayane-djouah Jul 10, 2024
dd4661c
prettier
rayane-djouah Jul 10, 2024
978e4cd
lint
rayane-djouah Jul 10, 2024
a2c3940
Merge branch 'main' into Replace-usages-of-is-useWindowDimensions-wit…
rayane-djouah Jul 12, 2024
2917872
use isSmallScreenWidth instead of shouldUseNarrowLayout for offline i…
rayane-djouah Jul 18, 2024
8a557ce
use isSmallScreenWidth instead of shouldUseNarrowLayout
rayane-djouah Jul 18, 2024
bb36755
Merge branch 'main' into Replace-usages-of-is-useWindowDimensions-wit…
rayane-djouah Jul 18, 2024
4aed441
Update variable name in useOnboardingLayout to improve clarity
rayane-djouah Jul 18, 2024
db1635e
Merge branch 'main' into Replace-usages-of-is-useWindowDimensions-wit…
rayane-djouah Jul 22, 2024
c69339d
Merge branch 'main' into Replace-usages-of-is-useWindowDimensions-wit…
rayane-djouah Jul 23, 2024
030bc47
Merge branch 'main' into Replace-usages-of-is-useWindowDimensions-wit…
rayane-djouah Jul 24, 2024
50657ea
fix type error after merging main
rayane-djouah Jul 24, 2024
9590046
Merge branch 'main' into Replace-usages-of-is-useWindowDimensions-wit…
rayane-djouah Jul 25, 2024
c267426
Merge branch 'main' into Replace-usages-of-is-useWindowDimensions-wit…
rayane-djouah Jul 25, 2024
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
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 @@ -199,14 +199,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();
rayane-djouah marked this conversation as resolved.
Show resolved Hide resolved
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
Loading