Skip to content

Commit 9a7101f

Browse files
committed
refactor fullscreen modal for native
1 parent 0135627 commit 9a7101f

5 files changed

Lines changed: 25 additions & 13 deletions

File tree

src/components/Modal/BaseModal.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,24 @@ import CONST from '@src/CONST';
2626
import ModalContent from './ModalContent';
2727
import ModalContext from './ModalContext';
2828
import ReanimatedModal from './ReanimatedModal';
29-
import type ModalProps from './ReanimatedModal/types';
29+
import type ReanimatedModalProps from './ReanimatedModal/types';
3030
import type BaseModalProps from './types';
3131

3232
const REANIMATED_MODAL_TYPES: Array<ValueOf<typeof CONST.MODAL.MODAL_TYPE>> = [CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED, CONST.MODAL.MODAL_TYPE.FULLSCREEN];
3333

34-
type ModalComponentProps = (ReactNativeModalProps | ModalProps) & {
34+
type ModalComponentProps = (ReactNativeModalProps | ReanimatedModalProps) & {
3535
type?: ValueOf<typeof CONST.MODAL.MODAL_TYPE>;
3636
};
3737

3838
function ModalComponent({type, ...props}: ModalComponentProps) {
3939
if (type && REANIMATED_MODAL_TYPES.includes(type)) {
40-
// eslint-disable-next-line react/jsx-props-no-spreading
41-
return <ReanimatedModal {...(props as ModalProps)} />;
40+
return (
41+
<ReanimatedModal
42+
// eslint-disable-next-line react/jsx-props-no-spreading
43+
{...(props as ReanimatedModalProps)}
44+
type={type}
45+
/>
46+
);
4247
}
4348
// eslint-disable-next-line react/jsx-props-no-spreading
4449
return <ReactNativeModal {...(props as ReactNativeModalProps)} />;

src/components/Modal/ReanimatedModal/Container/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import React, {useMemo} from 'react';
22
import {View} from 'react-native';
33
import Animated, {Easing, Keyframe, runOnJS} from 'react-native-reanimated';
4-
import type ModalProps from '@components/Modal/ReanimatedModal/types';
4+
import type ReanimatedModalProps from '@components/Modal/ReanimatedModal/types';
55
import type {ContainerProps} from '@components/Modal/ReanimatedModal/types';
66
import useThemeStyles from '@hooks/useThemeStyles';
7+
import CONST from '@src/CONST';
78

89
const easing = Easing.bezier(0.76, 0.0, 0.24, 1.0).factory();
910

10-
function Container({style, animationInTiming = 300, animationOutTiming = 300, onCloseCallBack, onOpenCallBack, ...props}: Partial<ModalProps> & ContainerProps) {
11+
function Container({style, animationInTiming = 300, animationOutTiming = 300, onCloseCallBack, onOpenCallBack, type, ...props}: Partial<ReanimatedModalProps> & ContainerProps) {
1112
const styles = useThemeStyles();
1213

1314
const Entering = useMemo(() => {
@@ -49,7 +50,7 @@ function Container({style, animationInTiming = 300, animationOutTiming = 300, on
4950
{...props}
5051
>
5152
<Animated.View
52-
style={[style, styles.modalAnimatedContainer]}
53+
style={[styles.modalAnimatedContainer, type !== CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED && styles.flex1]}
5354
entering={Entering}
5455
exiting={Exiting}
5556
>

src/components/Modal/ReanimatedModal/Container/index.web.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React, {useEffect, useMemo, useRef} from 'react';
22
import Animated, {Easing, Keyframe, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated';
3-
import type ModalProps from '@components/Modal/ReanimatedModal/types';
3+
import type ReanimatedModalProps from '@components/Modal/ReanimatedModal/types';
44
import type {ContainerProps} from '@components/Modal/ReanimatedModal/types';
55
import useThemeStyles from '@hooks/useThemeStyles';
66

77
const easing = Easing.bezier(0.76, 0.0, 0.24, 1.0).factory();
88

9-
function Container({style, animationInTiming = 300, animationOutTiming = 300, onOpenCallBack, onCloseCallBack, ...props}: ModalProps & ContainerProps) {
9+
function Container({style, animationInTiming = 300, animationOutTiming = 300, onOpenCallBack, onCloseCallBack, ...props}: ReanimatedModalProps & ContainerProps) {
1010
const styles = useThemeStyles();
1111
const onCloseCallbackRef = useRef(onCloseCallBack);
1212
const opacity = useSharedValue(0);

src/components/Modal/ReanimatedModal/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import getPlatform from '@libs/getPlatform';
99
import CONST from '@src/CONST';
1010
import Backdrop from './Backdrop';
1111
import Container from './Container';
12-
import type ModalProps from './types';
12+
import type ReanimatedModalProps from './types';
1313

1414
function ReanimatedModal({
1515
testID,
@@ -32,9 +32,10 @@ function ReanimatedModal({
3232
onBackdropPress = noop,
3333
onBackButtonPress = noop,
3434
style,
35+
type,
3536
statusBarTranslucent = false,
3637
...props
37-
}: ModalProps) {
38+
}: ReanimatedModalProps) {
3839
const [isVisibleState, setIsVisibleState] = useState(isVisible);
3940
const [isContainerOpen, setIsContainerOpen] = useState(false);
4041
const [isTransitioning, setIsTransitioning] = useState(false);
@@ -141,6 +142,7 @@ function ReanimatedModal({
141142
onOpenCallBack={onOpenCallBack}
142143
onCloseCallBack={onCloseCallBack}
143144
style={style}
145+
type={type}
144146
>
145147
{children}
146148
</Container>

src/components/Modal/ReanimatedModal/types.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type {NativeSyntheticEvent, StyleProp, ViewProps, ViewStyle} from 'react-
33
import type {ModalProps as ReactNativeModalProps} from 'react-native-modal';
44
import type {SharedValue} from 'react-native-reanimated';
55
import type {ValueOf} from 'type-fest';
6+
import type CONST from '@src/CONST';
67

78
type GestureProps = {
89
/** Height of the device (used for positioning) */
@@ -14,7 +15,7 @@ type GestureProps = {
1415

1516
type AnimationOut = ValueOf<Pick<ReactNativeModalProps, 'animationOut'>>;
1617

17-
type ModalProps = ViewProps &
18+
type ReanimatedModalProps = ViewProps &
1819
GestureProps & {
1920
/** Content inside the modal */
2021
children: ReactNode;
@@ -115,6 +116,9 @@ type ModalProps = ViewProps &
115116
supportedOrientations?: Array<'portrait' | 'portrait-upside-down' | 'landscape' | 'landscape-left' | 'landscape-right'>;
116117

117118
navigationBarTranslucent?: boolean;
119+
120+
/** Modal type */
121+
type?: ValueOf<typeof CONST.MODAL.MODAL_TYPE>;
118122
};
119123

120124
type BackdropProps = {
@@ -154,5 +158,5 @@ type ContainerProps = {
154158
panPosition?: {translateX: SharedValue<number>; translateY: SharedValue<number>};
155159
};
156160

157-
export default ModalProps;
161+
export default ReanimatedModalProps;
158162
export type {BackdropProps, ContainerProps, AnimationOut};

0 commit comments

Comments
 (0)