From 71100264f2c0edc5cac18c2f22406ab4229a2506 Mon Sep 17 00:00:00 2001 From: kdn0325 Date: Sun, 10 Mar 2024 01:56:54 +0900 Subject: [PATCH] chore: source index.tsx=> index.ts --- package.json | 4 ++-- src/index.ts | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/index.ts diff --git a/package.json b/package.json index 6e1afe4..f5e75e3 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "main": "lib/commonjs/index.js", "module": "lib/module/index.js", "types": "lib/typescript/src/index.d.ts", - "react-native": "src/index.tsx", - "source": "src/index.tsx", + "react-native": "src/index.ts", + "source": "src/index.ts", "files": [ "src", "lib", diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..c250186 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,51 @@ +import { Dimensions } from 'react-native'; + +const { width, height } = Dimensions.get('window'); + +const isSmall = width <= 375; + +const guidelineBaseWidth = () => { + if (isSmall) { + return 330; + } + return 350; +}; + +const guidelineBaseHeight = () => { + if (isSmall) { + return 550; + } else if (width > 410) { + return 620; + } + return 680; +}; + +const percentBaseWidth = (val: number) => { + return width * (val / 100); +}; + +const percentBaseHeight = (val: number) => { + return height * (val / 100); +}; + +const guidelineBaseFonts = () => { + if (width > 410) { + return 430; + } + return 400; +}; + +const horizontalScale = (size: number) => (width / guidelineBaseWidth()) * size; + +const verticalScale = (size: number) => (height / guidelineBaseHeight()) * size; + +const fontSizeScale = (size: number) => + Math.round((size * width) / guidelineBaseFonts()); + +export { + horizontalScale, + verticalScale, + fontSizeScale, + percentBaseWidth, + percentBaseHeight, +};