template_0205
This commit is contained in:
14
RN_TEMPLATE/app/utils/responsive.ts
Normal file
14
RN_TEMPLATE/app/utils/responsive.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
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))
|
||||
}
|
||||
Reference in New Issue
Block a user