UNPKG

react-native-core-responsive-screen

Version:

react-native-core-responsive-screen is a small library that provides 2 simple methods so that React Native developers can code their UI elements fully responsive. No media queries needed. It also provides an optional third method for screen orientation de

23 lines (18 loc) 830 B
import { Dimensions } from "react-native"; const { width, height } = Dimensions.get("window"); const [shortDimension, longDimension] = width < height ? [width, height] : [height, width]; // Default guideline sizes are based on standard ~5" screen mobile device const guidelineBaseWidth = 350; const guidelineBaseHeight = 680; export const scale = (size) => (shortDimension / guidelineBaseWidth) * size; export const verticalScale = (size) => (longDimension / guidelineBaseHeight) * size; export const moderateScale = (size, factor = 0.5) => size + (scale(size) - size) * factor; export const moderateVerticalScale = (size, factor = 0.5) => size + (verticalScale(size) - size) * factor; export const s = scale; export const vs = verticalScale; export const ms = moderateScale; export const mvs = moderateVerticalScale;