From 81aae874e2d9c165348f40a2bc42b2fa75821b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Barbet?= Date: Wed, 5 Feb 2020 18:37:52 +0000 Subject: [PATCH] chore: create utils folder --- src/index.tsx | 4 +++- src/utils/devices.ts | 7 ++++++ src/{utils.ts => utils/get-spring-config.ts} | 24 +------------------- src/utils/has-absolute-style.ts | 14 ++++++++++++ 4 files changed, 25 insertions(+), 24 deletions(-) create mode 100644 src/utils/devices.ts rename src/{utils.ts => utils/get-spring-config.ts} (52%) create mode 100644 src/utils/has-absolute-style.ts diff --git a/src/index.tsx b/src/index.tsx index 89e6dec9..747abe19 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -27,7 +27,9 @@ import { } from 'react-native-gesture-handler'; import { IProps, IState } from './options'; -import { getSpringConfig, isIphoneX, isIos, hasAbsoluteStyle } from './utils'; +import { getSpringConfig } from './utils/get-spring-config'; +import { isIphoneX, isIos } from './utils/devices'; +import { hasAbsoluteStyle } from './utils/has-absolute-style'; import s from './styles'; const { height: screenHeight } = Dimensions.get('window'); diff --git a/src/utils/devices.ts b/src/utils/devices.ts new file mode 100644 index 00000000..041f2b26 --- /dev/null +++ b/src/utils/devices.ts @@ -0,0 +1,7 @@ +import { Platform, Dimensions } from 'react-native'; + +const { width, height } = Dimensions.get('window'); + +export const isIos = Platform.OS === 'ios'; +export const isIphoneX = + isIos && (height === 812 || width === 812 || height === 896 || width === 896); diff --git a/src/utils.ts b/src/utils/get-spring-config.ts similarity index 52% rename from src/utils.ts rename to src/utils/get-spring-config.ts index fcf9ca1a..6488628d 100644 --- a/src/utils.ts +++ b/src/utils/get-spring-config.ts @@ -1,9 +1,4 @@ -import * as React from 'react'; -import { Platform, Dimensions, StyleProp, StyleSheet } from 'react-native'; - -import { ISpringProps } from './options'; - -const { width: screenWidth, height: screenHeight } = Dimensions.get('window'); +import { ISpringProps } from '../options'; export const getSpringConfig = (config: ISpringProps) => { const { friction, tension, speed, bounciness, stiffness, damping, mass } = config; @@ -40,20 +35,3 @@ export const getSpringConfig = (config: ISpringProps) => { friction, }; }; - -export const isIos = Platform.OS === 'ios'; -export const isIphoneX = - isIos && - (screenHeight === 812 || screenWidth === 812 || screenHeight === 896 || screenWidth === 896); - -export const hasAbsoluteStyle = (Component: React.ReactNode): boolean => { - if (!React.isValidElement(Component)) { - return false; - } - - // @ts-ignore - const element = typeof Component === 'object' ? Component : Component(); - const style: StyleProp = Component && StyleSheet.flatten(element.props.style); - - return style && style.position === 'absolute'; -}; diff --git a/src/utils/has-absolute-style.ts b/src/utils/has-absolute-style.ts new file mode 100644 index 00000000..8afbd295 --- /dev/null +++ b/src/utils/has-absolute-style.ts @@ -0,0 +1,14 @@ +import * as React from 'react'; +import { StyleProp, StyleSheet } from 'react-native'; + +export const hasAbsoluteStyle = (Component: React.ReactNode): boolean => { + if (!React.isValidElement(Component)) { + return false; + } + + // @ts-ignore + const element = typeof Component === 'object' ? Component : Component(); + const style: StyleProp = Component && StyleSheet.flatten(element.props.style); + + return style && style.position === 'absolute'; +};