react-native-modern-elements
Version:
A modern, customizable UI component library for React Native
26 lines (20 loc) • 709 B
text/typescript
import { Dimensions, PixelRatio } from "react-native";
const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get("window");
const [shortDimension, longDimension] =
SCREEN_WIDTH < SCREEN_HEIGHT
? [SCREEN_WIDTH, SCREEN_HEIGHT]
: [SCREEN_HEIGHT, SCREEN_WIDTH];
const guidelineBaseWidth = 375;
const guidelineBaseHeight = 812;
export const scale = (size: number) =>
Math.round(
PixelRatio.roundToNearestPixel(
(shortDimension / guidelineBaseWidth) * (size as number)
)
);
export const verticalScale = (size: number) =>
Math.round(
PixelRatio.roundToNearestPixel(
(longDimension / guidelineBaseHeight) * (size as number)
)
);