Use native em and rem on web

This commit is contained in:
Zoe Roux
2022-12-11 13:22:58 +09:00
parent 8b566c4f34
commit b481f94f68
2 changed files with 5 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "yoshiki",
"version": "0.2.7",
"version": "0.2.8",
"author": "Zoe Roux <zoe.roux@sdg.moe> (https://github.com/AnonymusRaccoon)",
"license": "MIT",
"keywords": [

View File

@@ -3,9 +3,10 @@
// Licensed under the MIT license. See LICENSE file in the project root for details.
//
import { PixelRatio } from "react-native";
import { PixelRatio, Platform } from "react-native";
export const px = (value: number) => value;
export const percent = (value: number) => `${value}%`;
export const em = (value: number) => PixelRatio.getFontScale() * 16 * value;
export const rem = em;
export const em = (value: number) =>
Platform.OS === "web" ? `${value}em` : PixelRatio.getFontScale() * 16 * value;
export const rem = Platform.OS === "web" ? (value: number) => `${value}rem` : em;