Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 13 additions & 6 deletions src/components/Modal/BaseModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,27 @@ import Navigation from '@libs/Navigation/Navigation';
import variables from '@styles/variables';
import {areAllModalsHidden, closeTop, onModalDidClose, setCloseModal, setModalVisibility, willAlertModalBecomeVisible} from '@userActions/Modal';
import CONST from '@src/CONST';
import BottomDockedModal from './BottomDockedModal';
import type ModalProps from './BottomDockedModal/types';
import ModalContent from './ModalContent';
import ModalContext from './ModalContext';
import ReanimatedModal from './ReanimatedModal';
import type ReanimatedModalProps from './ReanimatedModal/types';
import type BaseModalProps from './types';

type ModalComponentProps = (ReactNativeModalProps | ModalProps) & {
const REANIMATED_MODAL_TYPES: Array<ValueOf<typeof CONST.MODAL.MODAL_TYPE>> = [CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED, CONST.MODAL.MODAL_TYPE.FULLSCREEN];

type ModalComponentProps = (ReactNativeModalProps | ReanimatedModalProps) & {
type?: ValueOf<typeof CONST.MODAL.MODAL_TYPE>;
};

function ModalComponent({type, ...props}: ModalComponentProps) {
if (type === CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED) {
// eslint-disable-next-line react/jsx-props-no-spreading
return <BottomDockedModal {...(props as ModalProps)} />;
if (type && REANIMATED_MODAL_TYPES.includes(type)) {
return (
<ReanimatedModal
// eslint-disable-next-line react/jsx-props-no-spreading
{...(props as ReanimatedModalProps)}
type={type}
/>
);
}
// eslint-disable-next-line react/jsx-props-no-spreading
return <ReactNativeModal {...(props as ReactNativeModalProps)} />;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {useMemo} from 'react';
import Animated, {Easing, Keyframe} from 'react-native-reanimated';
import type {BackdropProps} from '@components/Modal/BottomDockedModal/types';
import type {BackdropProps} from '@components/Modal/ReanimatedModal/types';
import {PressableWithoutFeedback} from '@components/Pressable';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useMemo} from 'react';
import {View} from 'react-native';
import Animated, {Easing, Keyframe} from 'react-native-reanimated';
import type {BackdropProps} from '@components/Modal/BottomDockedModal/types';
import type {BackdropProps} from '@components/Modal/ReanimatedModal/types';
import {PressableWithoutFeedback} from '@components/Pressable';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React, {useMemo} from 'react';
import {View} from 'react-native';
import Animated, {Easing, Keyframe, runOnJS} from 'react-native-reanimated';
import type ModalProps from '@components/Modal/BottomDockedModal/types';
import type {ContainerProps} from '@components/Modal/BottomDockedModal/types';
import type ReanimatedModalProps from '@components/Modal/ReanimatedModal/types';
import type {ContainerProps} from '@components/Modal/ReanimatedModal/types';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';

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

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

const Entering = useMemo(() => {
Expand Down Expand Up @@ -49,7 +50,7 @@ function Container({style, animationInTiming = 300, animationOutTiming = 300, on
{...props}
>
<Animated.View
style={styles.modalAnimatedContainer}
style={[styles.modalAnimatedContainer, type !== CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED && styles.flex1]}
entering={Entering}
exiting={Exiting}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, {useEffect, useMemo, useRef} from 'react';
import Animated, {Easing, Keyframe, useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated';
import type ModalProps from '@components/Modal/BottomDockedModal/types';
import type {ContainerProps} from '@components/Modal/BottomDockedModal/types';
import type ReanimatedModalProps from '@components/Modal/ReanimatedModal/types';
import type {ContainerProps} from '@components/Modal/ReanimatedModal/types';
import useThemeStyles from '@hooks/useThemeStyles';

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

function Container({style, animationInTiming = 300, animationOutTiming = 300, onOpenCallBack, onCloseCallBack, ...props}: ModalProps & ContainerProps) {
function Container({style, animationInTiming = 300, animationOutTiming = 300, onOpenCallBack, onCloseCallBack, ...props}: ReanimatedModalProps & ContainerProps) {
const styles = useThemeStyles();
const onCloseCallbackRef = useRef(onCloseCallBack);
const opacity = useSharedValue(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import getPlatform from '@libs/getPlatform';
import CONST from '@src/CONST';
import Backdrop from './Backdrop';
import Container from './Container';
import type ModalProps from './types';
import type ReanimatedModalProps from './types';

function BottomDockedModal({
function ReanimatedModal({
testID,
animationInDelay,
animationInTiming = 300,
Expand All @@ -32,9 +32,10 @@ function BottomDockedModal({
onBackdropPress = noop,
onBackButtonPress = noop,
style,
type,
statusBarTranslucent = false,
...props
}: ModalProps) {
}: ReanimatedModalProps) {
const [isVisibleState, setIsVisibleState] = useState(isVisible);
const [isContainerOpen, setIsContainerOpen] = useState(false);
const [isTransitioning, setIsTransitioning] = useState(false);
Expand Down Expand Up @@ -141,6 +142,7 @@ function BottomDockedModal({
onOpenCallBack={onOpenCallBack}
onCloseCallBack={onCloseCallBack}
style={style}
type={type}
>
{children}
</Container>
Expand Down Expand Up @@ -207,6 +209,6 @@ function BottomDockedModal({
);
}

BottomDockedModal.displayName = 'BottomDockedModal';
ReanimatedModal.displayName = 'ReanimatedModal';

export default BottomDockedModal;
export default ReanimatedModal;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {NativeSyntheticEvent, StyleProp, ViewProps, ViewStyle} from 'react-
import type {ModalProps as ReactNativeModalProps} from 'react-native-modal';
import type {SharedValue} from 'react-native-reanimated';
import type {ValueOf} from 'type-fest';
import type CONST from '@src/CONST';

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

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

type ModalProps = ViewProps &
type ReanimatedModalProps = ViewProps &
GestureProps & {
/** Content inside the modal */
children: ReactNode;
Expand Down Expand Up @@ -115,6 +116,9 @@ type ModalProps = ViewProps &
supportedOrientations?: Array<'portrait' | 'portrait-upside-down' | 'landscape' | 'landscape-left' | 'landscape-right'>;

navigationBarTranslucent?: boolean;

/** Modal type */
type?: ValueOf<typeof CONST.MODAL.MODAL_TYPE>;
};

type BackdropProps = {
Expand Down Expand Up @@ -154,5 +158,5 @@ type ContainerProps = {
panPosition?: {translateX: SharedValue<number>; translateY: SharedValue<number>};
};

export default ModalProps;
export default ReanimatedModalProps;
export type {BackdropProps, ContainerProps, AnimationOut};
4 changes: 2 additions & 2 deletions src/components/Modal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {GestureResponderEvent, PanResponderGestureState, ViewStyle} from 'r
import type {Direction, ModalProps as ReactNativeModalProps} from 'react-native-modal';
import type {ValueOf} from 'type-fest';
import type CONST from '@src/CONST';
import type BottomDockedModalProps from './BottomDockedModal/types';
import type ReanimatedModalProps from './ReanimatedModal/types';

type FocusTrapOptions = Exclude<FocusTrapProps['focusTrapOptions'], undefined>;

Expand All @@ -19,7 +19,7 @@ type WindowState = {
};

type BaseModalProps = Partial<ReactNativeModalProps> &
Partial<BottomDockedModalProps> & {
Partial<ReanimatedModalProps> & {
/** Decides whether the modal should cover fullscreen. FullScreen modal has backdrop */
fullscreen?: boolean;

Expand Down
4 changes: 2 additions & 2 deletions src/components/PopoverMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import FocusTrapForModal from './FocusTrap/FocusTrapForModal';
import * as Expensicons from './Icon/Expensicons';
import type {MenuItemProps} from './MenuItem';
import MenuItem from './MenuItem';
import type BottomDockedModalProps from './Modal/BottomDockedModal/types';
import type ReanimatedModalProps from './Modal/ReanimatedModal/types';
import type BaseModalProps from './Modal/types';
import OfflineWithFeedback from './OfflineWithFeedback';
import PopoverWithMeasuredContent from './PopoverWithMeasuredContent';
Expand Down Expand Up @@ -69,7 +69,7 @@ type PopoverMenuItem = MenuItemProps & {
testID?: string;
};

type PopoverModalProps = Pick<ModalProps, 'animationIn' | 'animationOut' | 'animationInTiming' | 'animationOutTiming'> & Pick<BottomDockedModalProps, 'animationInDelay'>;
type PopoverModalProps = Pick<ModalProps, 'animationIn' | 'animationOut' | 'animationInTiming' | 'animationOutTiming'> & Pick<ReanimatedModalProps, 'animationInDelay'>;

type PopoverMenuProps = Partial<PopoverModalProps> & {
/** Callback method fired when the user requests to close the modal */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {useEffect, useState} from 'react';
import {View} from 'react-native';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import Modal from '@components/Modal';
import type {AnimationOut} from '@components/Modal/BottomDockedModal/types';
import type {AnimationOut} from '@components/Modal/ReanimatedModal/types';
import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
import TextLink from '@components/TextLink';
Expand Down
1 change: 1 addition & 0 deletions src/styles/utils/generators/ModalStyleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const createModalStyleUtils: StyleUtilGenerator<GetModalStylesStyleUtil> = ({the

switch (type) {
case CONST.MODAL.MODAL_TYPE.FULLSCREEN:
modalStyle = {...modalStyle, height: '100%'};
modalContainerStyle = {};
swipeDirection = 'down';
animationIn = 'slideInUp';
Expand Down