15 lines
549 B
TypeScript
15 lines
549 B
TypeScript
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))
|
||
}
|