Skip to content

Commit

Permalink
[TS migration] Migrate 'getModalStyles' style to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
blazejkustra committed Aug 28, 2023
1 parent dfb7e23 commit 92d252d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,60 @@
import CONST from '../../CONST';
import variables from '../variables';
import themeColors from '../themes/default';
import styles from '../styles';
import {CSSProperties} from 'react';
import {ViewStyle} from 'react-native';
import {ValueOf} from 'type-fest';
import {ModalProps} from 'react-native-modal';
import CONST from '../CONST';
import variables from './variables';
import themeColors from './themes/default';
import styles from './styles';

const getCenteredModalStyles = (windowWidth, isSmallScreenWidth, isFullScreenWhenSmall = false) => ({
borderWidth: styles.centeredModalStyles(isSmallScreenWidth, isFullScreenWhenSmall).borderWidth,
width: isSmallScreenWidth ? '100%' : windowWidth - styles.centeredModalStyles(isSmallScreenWidth, isFullScreenWhenSmall).marginHorizontal * 2,
});
function getCenteredModalStyles(windowWidth: number, isSmallScreenWidth: boolean, isFullScreenWhenSmall = false): ViewStyle {
return {
borderWidth: styles.centeredModalStyles(isSmallScreenWidth, isFullScreenWhenSmall).borderWidth,
width: isSmallScreenWidth ? '100%' : windowWidth - styles.centeredModalStyles(isSmallScreenWidth, isFullScreenWhenSmall).marginHorizontal * 2,
};
}

type ModalType = ValueOf<typeof CONST.MODAL.MODAL_TYPE>;

type WindowDimensions = {
windowWidth: number;
windowHeight: number;
isSmallScreenWidth: boolean;
isMediumScreenWidth: boolean;
isLargeScreenWidth: boolean;
};

type GetModalStyles = {
modalStyle: ViewStyle;
modalContainerStyle: ViewStyle | Pick<CSSProperties, 'boxShadow'>;
swipeDirection: ModalProps['swipeDirection'];
animationIn: ModalProps['animationIn'];
animationOut: ModalProps['animationOut'];
hideBackdrop: boolean;
shouldAddTopSafeAreaMargin: boolean;
shouldAddBottomSafeAreaMargin: boolean;
shouldAddBottomSafeAreaPadding: boolean;
shouldAddTopSafeAreaPadding: boolean;
};

export default (type, windowDimensions, popoverAnchorPosition = {}, innerContainerStyle = {}, outerStyle = {}) => {
export default function getModalStyles(
type: ModalType,
windowDimensions: WindowDimensions,
popoverAnchorPosition: ViewStyle = {},
innerContainerStyle: ViewStyle = {},
outerStyle: ViewStyle = {},
): GetModalStyles {
const {isSmallScreenWidth, windowWidth} = windowDimensions;

let modalStyle = {
let modalStyle: GetModalStyles['modalStyle'] = {
margin: 0,
...outerStyle,
};

let modalContainerStyle;
let swipeDirection;
let animationIn;
let animationOut;
let modalContainerStyle: GetModalStyles['modalContainerStyle'];
let swipeDirection: GetModalStyles['swipeDirection'];
let animationIn: GetModalStyles['animationIn'];
let animationOut: GetModalStyles['animationOut'];
let hideBackdrop = false;
let shouldAddBottomSafeAreaMargin = false;
let shouldAddTopSafeAreaMargin = false;
Expand Down Expand Up @@ -264,4 +299,4 @@ export default (type, windowDimensions, popoverAnchorPosition = {}, innerContain
shouldAddBottomSafeAreaPadding,
shouldAddTopSafeAreaPadding,
};
};
}
3 changes: 0 additions & 3 deletions src/styles/getModalStyles/index.js

This file was deleted.

0 comments on commit 92d252d

Please sign in to comment.