diff --git a/src/CONST/index.ts b/src/CONST/index.ts index 833bc90b5552..1017e912b5ee 100644 --- a/src/CONST/index.ts +++ b/src/CONST/index.ts @@ -2076,6 +2076,8 @@ const CONST = { RHP_DURATION_OUT_WEB: 100, CENTERED_DURATION_IN_WEB: 120, CENTERED_DURATION_OUT_WEB: 80, + NARROW_SLIDE_DURATION_IN_WEB: 300, + NARROW_SLIDE_DURATION_OUT_WEB: 200, }, RHP_ENTER_OFFSET_PX_WEB: 60, }, diff --git a/src/components/Modal/BaseModal.tsx b/src/components/Modal/BaseModal.tsx index 9742850b1b2c..b9bf1acacdc8 100644 --- a/src/components/Modal/BaseModal.tsx +++ b/src/components/Modal/BaseModal.tsx @@ -308,8 +308,10 @@ function BaseModal({ const shouldSuppressRightDockedBackdrop = type === CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED && !isSmallScreenWidth && (isInNarrowPane || isInNarrowPaneModal) && !shouldKeepRightDockedBackdropInNarrowPane; + const isFullWidthNarrowSheet = + (type === CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED || type === CONST.MODAL.MODAL_TYPE.CENTERED_SWIPEABLE_TO_RIGHT) && isSmallScreenWidth && !shouldKeepRightDockedBackdropInNarrowPane; const backdropOpacityAdjusted = - hideBackdrop || shouldSuppressRightDockedBackdrop // right_docked modals shouldn't add backdrops when opened in same-width RHP + hideBackdrop || shouldSuppressRightDockedBackdrop || isFullWidthNarrowSheet // full-width narrow sheets (RHP-like) shouldn't dim a backdrop behind them ? 0 : backdropOpacity; diff --git a/src/components/Modal/index.tsx b/src/components/Modal/index.tsx index fde7f4c35331..16419d53728e 100644 --- a/src/components/Modal/index.tsx +++ b/src/components/Modal/index.tsx @@ -1,4 +1,5 @@ import React, {useCallback, useEffect, useRef, useState} from 'react'; +import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useStyleUtils from '@hooks/useStyleUtils'; import useTheme from '@hooks/useTheme'; import StatusBar from '@libs/StatusBar'; @@ -8,26 +9,54 @@ import {withInternalPopstate} from './internalPopstateGuard'; import type BaseModalProps from './types'; import type {WindowState} from './types'; +type WebModalAnimation = Pick; + +const CENTERED_MODAL_TYPES = new Set([ + CONST.MODAL.MODAL_TYPE.CONFIRM, + CONST.MODAL.MODAL_TYPE.CENTERED, + CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE, + CONST.MODAL.MODAL_TYPE.CENTERED_SMALL, + CONST.MODAL.MODAL_TYPE.CENTERED_SWIPEABLE_TO_RIGHT, +]); + +// Faster timing and slide-and-fade are desktop-only; narrow web keeps the full-slide baseline at the original 300/200 timing. +function getWebModalAnimation(type: BaseModalProps['type'], isSmallScreenWidth: boolean): WebModalAnimation { + const isRightDocked = type === CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED; + const isCentered = CENTERED_MODAL_TYPES.has(type); + if (!isRightDocked && !isCentered) { + return {}; + } + const isFadeOnlyCentered = type === CONST.MODAL.MODAL_TYPE.CONFIRM || type === CONST.MODAL.MODAL_TYPE.CENTERED_SMALL; + if (isSmallScreenWidth && !isFadeOnlyCentered) { + return { + animationInTiming: CONST.MODAL.ANIMATION_TIMING.NARROW_SLIDE_DURATION_IN_WEB, + animationOutTiming: CONST.MODAL.ANIMATION_TIMING.NARROW_SLIDE_DURATION_OUT_WEB, + }; + } + if (isRightDocked) { + return { + animationIn: 'slideAndFadeInRight', + animationOut: 'slideAndFadeOutRight', + animationInTiming: CONST.MODAL.ANIMATION_TIMING.RHP_DURATION_IN_WEB, + animationOutTiming: CONST.MODAL.ANIMATION_TIMING.RHP_DURATION_OUT_WEB, + }; + } + return { + animationInTiming: CONST.MODAL.ANIMATION_TIMING.CENTERED_DURATION_IN_WEB, + animationOutTiming: CONST.MODAL.ANIMATION_TIMING.CENTERED_DURATION_OUT_WEB, + }; +} + function Modal({fullscreen = true, onModalHide = () => {}, type, onModalShow = () => {}, children, shouldHandleNavigationBack, ...rest}: BaseModalProps) { const theme = useTheme(); const StyleUtils = useStyleUtils(); + // We gate the web animation on raw screen width (desktop vs mobile web) rather than shouldUseNarrowLayout, + // because a modal opened on top of an RHP on desktop must keep its desktop animation, not the narrow one. + // eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth + const {isSmallScreenWidth} = useResponsiveLayout(); const [previousStatusBarColor, setPreviousStatusBarColor] = useState(); - const isRightDocked = type === CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED; - const isCentered = - type === CONST.MODAL.MODAL_TYPE.CONFIRM || - type === CONST.MODAL.MODAL_TYPE.CENTERED || - type === CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE || - type === CONST.MODAL.MODAL_TYPE.CENTERED_SMALL || - type === CONST.MODAL.MODAL_TYPE.CENTERED_SWIPEABLE_TO_RIGHT; - const rightDockedInTiming = isRightDocked ? CONST.MODAL.ANIMATION_TIMING.RHP_DURATION_IN_WEB : undefined; - const rightDockedOutTiming = isRightDocked ? CONST.MODAL.ANIMATION_TIMING.RHP_DURATION_OUT_WEB : undefined; - const centeredInTiming = isCentered ? CONST.MODAL.ANIMATION_TIMING.CENTERED_DURATION_IN_WEB : undefined; - const centeredOutTiming = isCentered ? CONST.MODAL.ANIMATION_TIMING.CENTERED_DURATION_OUT_WEB : undefined; - const animationInTiming = rest.animationInTiming ?? rightDockedInTiming ?? centeredInTiming; - const animationOutTiming = rest.animationOutTiming ?? rightDockedOutTiming ?? centeredOutTiming; - const animationIn = rest.animationIn ?? (isRightDocked ? 'slideAndFadeInRight' : undefined); - const animationOut = rest.animationOut ?? (isRightDocked ? 'slideAndFadeOutRight' : undefined); + const webAnimation = getWebModalAnimation(type, isSmallScreenWidth); const setStatusBarColor = (color = theme.appBG) => { if (!fullscreen) { @@ -123,10 +152,10 @@ function Modal({fullscreen = true, onModalHide = () => {}, type, onModalShow = ( return ( }) => PlatformStackNavigationOptions>( ({route}) => { - const baseInterpolator: StackCardStyleInterpolator = (props) => - modalCardStyleInterpolator({props, enter: {kind: 'slide-and-fade', distancePx: CONST.MODAL.RHP_ENTER_OFFSET_PX_WEB}}); + const baseInterpolator: StackCardStyleInterpolator = isSmallScreenWidth + ? CardStyleInterpolators.forHorizontalIOS + : (props) => modalCardStyleInterpolator({props, enter: {kind: 'slide-and-fade', distancePx: CONST.MODAL.RHP_ENTER_OFFSET_PX_WEB}}); let cardStyleInterpolator: StackCardStyleInterpolator = baseInterpolator; @@ -55,10 +58,7 @@ function useWideModalStackScreenOptions() { web: { cardStyle: styles.navigationScreenCardStyle, cardStyleInterpolator, - transitionSpec: { - open: {animation: 'timing', config: {duration: CONST.MODAL.ANIMATION_TIMING.RHP_DURATION_IN_WEB}}, - close: {animation: 'timing', config: {duration: CONST.MODAL.ANIMATION_TIMING.RHP_DURATION_OUT_WEB}}, - }, + transitionSpec: isSmallScreenWidth ? undefined : RHP_WEB_TRANSITION_SPEC, }, }; }, diff --git a/src/libs/Navigation/AppNavigator/Navigators/ExplanationModalNavigator.tsx b/src/libs/Navigation/AppNavigator/Navigators/ExplanationModalNavigator.tsx index 957053714710..98a40316fcce 100644 --- a/src/libs/Navigation/AppNavigator/Navigators/ExplanationModalNavigator.tsx +++ b/src/libs/Navigation/AppNavigator/Navigators/ExplanationModalNavigator.tsx @@ -2,6 +2,8 @@ import React from 'react'; import {View} from 'react-native'; import NoDropZone from '@components/DragAndDrop/NoDropZone'; import ExplanationModal from '@components/ExplanationModal'; +import useResponsiveLayout from '@hooks/useResponsiveLayout'; +import RHP_WEB_TRANSITION_SPEC from '@libs/Navigation/AppNavigator/RHPTransitionSpec'; import createPlatformStackNavigator from '@libs/Navigation/PlatformStackNavigation/createPlatformStackNavigator'; import Animations from '@libs/Navigation/PlatformStackNavigation/navigationOptions/animation'; import type {ExplanationModalNavigatorParamList} from '@libs/Navigation/types'; @@ -10,10 +12,13 @@ import SCREENS from '@src/SCREENS'; const Stack = createPlatformStackNavigator(); function ExplanationModalNavigator() { + const {shouldUseNarrowLayout} = useResponsiveLayout(); return ( - + (); function FeatureTrainingModalNavigator() { + const {shouldUseNarrowLayout} = useResponsiveLayout(); return ( - + modalCardStyleInterpolator({props, enter: {kind: 'slide-from-width'}}), + transitionSpec: shouldUseNarrowLayout ? undefined : RHP_WEB_TRANSITION_SPEC, }, }} > diff --git a/src/libs/Navigation/AppNavigator/Navigators/OnboardingModalNavigator.tsx b/src/libs/Navigation/AppNavigator/Navigators/OnboardingModalNavigator.tsx index bf392b306abb..1b5a5edc8292 100644 --- a/src/libs/Navigation/AppNavigator/Navigators/OnboardingModalNavigator.tsx +++ b/src/libs/Navigation/AppNavigator/Navigators/OnboardingModalNavigator.tsx @@ -11,6 +11,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import {isMobileSafari} from '@libs/Browser'; import GoogleTagManager from '@libs/GoogleTagManager'; +import RHP_WEB_TRANSITION_SPEC from '@libs/Navigation/AppNavigator/RHPTransitionSpec'; import useModalCardStyleInterpolator from '@libs/Navigation/AppNavigator/useModalCardStyleInterpolator'; import createPlatformStackNavigator from '@libs/Navigation/PlatformStackNavigation/createPlatformStackNavigator'; import Animations from '@libs/Navigation/PlatformStackNavigation/navigationOptions/animation'; @@ -40,7 +41,7 @@ let signUpEventPublishedForAccountID: number | undefined; function OnboardingModalNavigator() { const styles = useThemeStyles(); - const {onboardingIsMediumOrLargerScreenWidth} = useResponsiveLayout(); + const {onboardingIsMediumOrLargerScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout(); const outerViewRef = React.useRef(null); const [account, accountMetadata] = useOnyx(ONYXKEYS.ACCOUNT); const isOnPrivateDomainAndHasAccessiblePolicies = !account?.isFromPublicDomain && account?.hasAccessibleDomainPolicies; @@ -93,9 +94,10 @@ function OnboardingModalNavigator() { cardStyle: { height: '100%', }, + transitionSpec: shouldUseNarrowLayout ? undefined : RHP_WEB_TRANSITION_SPEC, }, }; - }, [customInterpolator]); + }, [customInterpolator, shouldUseNarrowLayout]); // If the account data is not loaded yet, we don't want to show the onboarding modal if (isLoadingOnyxValue(accountMetadata)) { diff --git a/src/libs/Navigation/AppNavigator/Navigators/TestDriveModalNavigator.tsx b/src/libs/Navigation/AppNavigator/Navigators/TestDriveModalNavigator.tsx index baee2f09cc90..c652b29bb5c2 100644 --- a/src/libs/Navigation/AppNavigator/Navigators/TestDriveModalNavigator.tsx +++ b/src/libs/Navigation/AppNavigator/Navigators/TestDriveModalNavigator.tsx @@ -2,6 +2,8 @@ import React from 'react'; import {View} from 'react-native'; import NoDropZone from '@components/DragAndDrop/NoDropZone'; import TestDriveModal from '@components/TestDrive/Modal'; +import useResponsiveLayout from '@hooks/useResponsiveLayout'; +import RHP_WEB_TRANSITION_SPEC from '@libs/Navigation/AppNavigator/RHPTransitionSpec'; import createPlatformStackNavigator from '@libs/Navigation/PlatformStackNavigation/createPlatformStackNavigator'; import Animations from '@libs/Navigation/PlatformStackNavigation/navigationOptions/animation'; import type {TestDriveModalNavigatorParamList} from '@libs/Navigation/types'; @@ -10,10 +12,13 @@ import SCREENS from '@src/SCREENS'; const Stack = createPlatformStackNavigator(); function TestDriveModalNavigator() { + const {shouldUseNarrowLayout} = useResponsiveLayout(); return ( - + { cardOverlayEnabled: false, cardStyle: styles.navigationScreenCardStyle, gestureDirection: 'horizontal', + transitionSpec: isSmallScreenWidth ? undefined : RHP_WEB_TRANSITION_SPEC, }, }; - }, [customInterpolator, shouldAdjustInterpolatorProps, styles.navigationScreenCardStyle]); + }, [customInterpolator, shouldAdjustInterpolatorProps, isSmallScreenWidth, styles.navigationScreenCardStyle]); }; export default useRHPScreenOptions; diff --git a/src/libs/Navigation/AppNavigator/useRootNavigatorScreenOptions.ts b/src/libs/Navigation/AppNavigator/useRootNavigatorScreenOptions.ts index 335606bd4793..70717d3fdd4e 100644 --- a/src/libs/Navigation/AppNavigator/useRootNavigatorScreenOptions.ts +++ b/src/libs/Navigation/AppNavigator/useRootNavigatorScreenOptions.ts @@ -7,6 +7,7 @@ import Presentation from '@libs/Navigation/PlatformStackNavigation/navigationOpt import type {PlatformStackNavigationOptions} from '@libs/Navigation/PlatformStackNavigation/types'; import CONST from '@src/CONST'; import hideKeyboardOnSwipe from './hideKeyboardOnSwipe'; +import RHP_WEB_TRANSITION_SPEC from './RHPTransitionSpec'; import useModalCardStyleInterpolator from './useModalCardStyleInterpolator'; import type {EnterAnimation} from './useModalCardStyleInterpolator'; @@ -32,6 +33,7 @@ const useRootNavigatorScreenOptions = () => { const fullScreenEnter: EnterAnimation = shouldUseNarrowLayout ? {kind: 'slide-from-width'} : {kind: 'none'}; const onboardingEnter: EnterAnimation = onboardingIsMediumOrLargerScreenWidth ? {kind: 'fade'} : {kind: 'slide-from-width'}; + const rhpEnter: EnterAnimation = shouldUseNarrowLayout ? {kind: 'slide-from-width'} : {kind: 'slide-and-fade', distancePx: CONST.MODAL.RHP_ENTER_OFFSET_PX_WEB}; return { rightModalNavigator: { @@ -45,9 +47,10 @@ const useRootNavigatorScreenOptions = () => { cardStyleInterpolator: (props: StackCardInterpolationProps) => modalCardStyleInterpolator({ props, - enter: {kind: 'slide-and-fade', distancePx: CONST.MODAL.RHP_ENTER_OFFSET_PX_WEB}, + enter: rhpEnter, applySidePanelOffset: true, }), + transitionSpec: shouldUseNarrowLayout ? undefined : RHP_WEB_TRANSITION_SPEC, }, }, basicModalNavigator: { diff --git a/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/slideFromRight/index.ts b/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/slideFromRight/index.ts index 0f043cf1b722..7439e4c5af14 100644 --- a/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/slideFromRight/index.ts +++ b/src/libs/Navigation/PlatformStackNavigation/navigationOptions/animation/slideFromRight/index.ts @@ -1,15 +1,7 @@ import type {StackNavigationOptions} from '@react-navigation/stack'; import type {PlatformSpecificNavigationOptions} from '@libs/Navigation/PlatformStackNavigation/types'; -import CONST from '@src/CONST'; import {InternalPlatformAnimations} from '..'; -const slideFromRight: PlatformSpecificNavigationOptions = { - animation: InternalPlatformAnimations.SLIDE_FROM_RIGHT, - gestureDirection: 'horizontal', - transitionSpec: { - open: {animation: 'timing', config: {duration: CONST.MODAL.ANIMATION_TIMING.RHP_DURATION_IN_WEB}}, - close: {animation: 'timing', config: {duration: CONST.MODAL.ANIMATION_TIMING.RHP_DURATION_OUT_WEB}}, - }, -} satisfies StackNavigationOptions; +const slideFromRight: PlatformSpecificNavigationOptions = {animation: InternalPlatformAnimations.SLIDE_FROM_RIGHT, gestureDirection: 'horizontal'} satisfies StackNavigationOptions; export default slideFromRight;