Skip to content

Commit 86e5505

Browse files
authored
Merge pull request Expensify#65409 from software-mansion-labs/feat/use-reanimated-modal-in-help-modal
Use reanimated modal in Help modal
2 parents 886acde + 7d2ec50 commit 86e5505

7 files changed

Lines changed: 35 additions & 26 deletions

File tree

src/components/AvatarCropModal/AvatarCropModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ function AvatarCropModal({imageUri = '', imageName = '', imageType = '', onClose
352352
shouldUseCustomBackdrop
353353
shouldHandleNavigationBack
354354
enableEdgeToEdgeBottomSafeAreaPadding
355+
shouldUseReanimatedModal
355356
>
356357
<ScreenWrapper
357358
style={[styles.pb0]}

src/components/Modal/BaseModal.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React, {forwardRef, useCallback, useContext, useEffect, useMemo, useRef} from 'react';
2-
import {View} from 'react-native';
2+
// Animated required for side panel navigation
3+
// eslint-disable-next-line no-restricted-imports
4+
import {Animated, View} from 'react-native';
35
import type {ModalProps as ReactNativeModalProps} from 'react-native-modal';
46
import ReactNativeModal from 'react-native-modal';
57
import type {ValueOf} from 'type-fest';
@@ -106,9 +108,11 @@ function BaseModal(
106108
const {windowWidth, windowHeight} = useWindowDimensions();
107109
// We need to use isSmallScreenWidth instead of shouldUseNarrowLayout to apply correct modal width
108110
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
109-
const {isSmallScreenWidth} = useResponsiveLayout();
111+
const {isSmallScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout();
110112
const {sidePanelOffset} = useSidePanel();
111-
const sidePanelStyle = shouldApplySidePanelOffset && !isSmallScreenWidth ? {paddingRight: sidePanelOffset.current} : undefined;
113+
const sidePanelStyle = !shouldUseReanimatedModal && shouldApplySidePanelOffset && !isSmallScreenWidth ? {paddingRight: sidePanelOffset.current} : undefined;
114+
const sidePanelReanimatedStyle =
115+
shouldUseReanimatedModal && shouldApplySidePanelOffset && !isSmallScreenWidth ? {transform: [{translateX: Animated.multiply(sidePanelOffset.current, -1)}]} : undefined;
112116
const keyboardStateContextValue = useKeyboardState();
113117

114118
const insets = useSafeAreaInsets();
@@ -222,14 +226,27 @@ function BaseModal(
222226
windowWidth,
223227
windowHeight,
224228
isSmallScreenWidth,
229+
shouldUseNarrowLayout,
225230
},
226231
popoverAnchorPosition,
227232
innerContainerStyle,
228233
outerStyle,
229234
shouldUseModalPaddingStyle,
230235
shouldUseReanimatedModal,
231236
),
232-
[StyleUtils, type, windowWidth, windowHeight, isSmallScreenWidth, popoverAnchorPosition, innerContainerStyle, outerStyle, shouldUseModalPaddingStyle, shouldUseReanimatedModal],
237+
[
238+
StyleUtils,
239+
type,
240+
windowWidth,
241+
windowHeight,
242+
isSmallScreenWidth,
243+
shouldUseNarrowLayout,
244+
popoverAnchorPosition,
245+
innerContainerStyle,
246+
outerStyle,
247+
shouldUseModalPaddingStyle,
248+
shouldUseReanimatedModal,
249+
],
233250
);
234251

235252
const modalPaddingStyles = useMemo(() => {
@@ -351,12 +368,12 @@ function BaseModal(
351368
initialFocus={initialFocus}
352369
shouldPreventScroll={shouldPreventScrollOnFocus}
353370
>
354-
<View
355-
style={[styles.defaultModalContainer, modalContainerStyle, modalPaddingStyles, !isVisible && styles.pointerEventsNone]}
371+
<Animated.View
372+
style={[styles.defaultModalContainer, modalContainerStyle, modalPaddingStyles, !isVisible && styles.pointerEventsNone, sidePanelReanimatedStyle]}
356373
ref={ref}
357374
>
358375
<ColorSchemeWrapper>{children}</ColorSchemeWrapper>
359-
</View>
376+
</Animated.View>
360377
</FocusTrapForModal>
361378
</ModalContent>
362379
{!keyboardStateContextValue?.isKeyboardActive && <NavigationBar />}

src/components/SidePanel/HelpComponents/HelpOverlay.tsx

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import React from 'react';
2-
import Animated, {Easing, Keyframe} from 'react-native-reanimated';
1+
import React, {useMemo} from 'react';
2+
import Animated, {Keyframe} from 'react-native-reanimated';
3+
import {getModalInAnimation, getModalOutAnimation} from '@components/Modal/ReanimatedModal/utils';
34
import {PressableWithoutFeedback} from '@components/Pressable';
45
import useLocalize from '@hooks/useLocalize';
56
import useThemeStyles from '@hooks/useThemeStyles';
@@ -13,27 +14,13 @@ type HelpOverlayProps = {
1314
onBackdropPress: () => void;
1415
};
1516

16-
const easing = Easing.bezier(0.76, 0.0, 0.24, 1.0).factory();
17-
1817
function HelpOverlay({isRHPVisible, onBackdropPress}: HelpOverlayProps) {
1918
const styles = useThemeStyles();
2019
const {translate} = useLocalize();
2120

22-
const CustomFadeIn = new Keyframe({
23-
from: {opacity: 0},
24-
to: {
25-
opacity: 0.72,
26-
easing,
27-
},
28-
}).duration(CONST.MODAL.ANIMATION_TIMING.DEFAULT_IN);
29-
30-
const CustomFadeOut = new Keyframe({
31-
from: {opacity: 0.72},
32-
to: {
33-
opacity: 0,
34-
easing,
35-
},
36-
}).duration(CONST.MODAL.ANIMATION_TIMING.DEFAULT_OUT);
21+
const CustomFadeIn = useMemo(() => new Keyframe(getModalInAnimation('fadeIn')).duration(CONST.MODAL.ANIMATION_TIMING.DEFAULT_IN), []);
22+
23+
const CustomFadeOut = useMemo(() => new Keyframe(getModalOutAnimation('fadeOut')).duration(CONST.MODAL.ANIMATION_TIMING.DEFAULT_OUT), []);
3724

3825
return (
3926
<Animated.View

src/components/SidePanel/HelpModal/index.android.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function Help({shouldHideSidePanel, closeSidePanel}: HelpProps) {
2626
isVisible={!shouldHideSidePanel}
2727
type={CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED}
2828
shouldHandleNavigationBack
29+
shouldUseReanimatedModal
2930
>
3031
<HelpContent closeSidePanel={closeSidePanel} />
3132
</Modal>

src/components/SidePanel/HelpModal/index.ios.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function Help({shouldHideSidePanel, closeSidePanel}: HelpProps) {
1313
shouldHandleNavigationBack
1414
propagateSwipe
1515
swipeDirection={CONST.SWIPE_DIRECTION.RIGHT}
16+
shouldUseReanimatedModal
1617
>
1718
<HelpContent closeSidePanel={closeSidePanel} />
1819
</Modal>

src/hooks/useSidePanel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ function useSidePanel() {
7171
const shouldApplySidePanelOffset = isExtraLargeScreenWidth && !shouldHideSidePanel;
7272
const sidePanelOffset = useRef(new Animated.Value(shouldApplySidePanelOffset ? variables.sideBarWidth : 0));
7373
const sidePanelTranslateX = useRef(new Animated.Value(shouldHideSidePanel ? sidePanelWidth : 0));
74+
7475
useEffect(() => {
7576
setIsSidePanelTransitionEnded(false);
7677
Animated.parallel([

src/styles/utils/generators/ModalStyleUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type WindowDimensions = {
1919
windowWidth: number;
2020
windowHeight: number;
2121
isSmallScreenWidth: boolean;
22+
shouldUseNarrowLayout?: boolean;
2223
};
2324

2425
type GetModalStyles = {

0 commit comments

Comments
 (0)