Skip to content

Commit

Permalink
chore: create utils folder
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremybarbet committed Feb 5, 2020
1 parent 8b0f59f commit 81aae87
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
4 changes: 3 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
7 changes: 7 additions & 0 deletions src/utils/devices.ts
Original file line number Diff line number Diff line change
@@ -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);
24 changes: 1 addition & 23 deletions src/utils.ts → src/utils/get-spring-config.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<any> = Component && StyleSheet.flatten(element.props.style);

return style && style.position === 'absolute';
};
14 changes: 14 additions & 0 deletions src/utils/has-absolute-style.ts
Original file line number Diff line number Diff line change
@@ -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<any> = Component && StyleSheet.flatten(element.props.style);

return style && style.position === 'absolute';
};

0 comments on commit 81aae87

Please sign in to comment.