Files
RN_Template/RN_TEMPLATE/app/utils/responsive.ts
2026-02-05 13:16:05 +08:00

15 lines
549 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Dimensions, PixelRatio } from "react-native"
const DESIGN_WIDTH = 400
const { width: SCREEN_WIDTH } = Dimensions.get("window")
/** 布局尺寸缩放padding、margin、width、height、borderRadius 等) */
export function s(size: number): number {
return PixelRatio.roundToNearestPixel(size * (SCREEN_WIDTH / DESIGN_WIDTH))
}
/** 字体缩放(平方根阻尼,避免大屏字体过大) */
export function fs(size: number): number {
return PixelRatio.roundToNearestPixel(size * Math.pow(SCREEN_WIDTH / DESIGN_WIDTH, 0.5))
}