Created
October 30, 2016 23:56
-
-
Save sirgalleto/3d62698f4936769a75116b452ee07f1a to your computer and use it in GitHub Desktop.
react-native responsive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Dimensions } from 'react-native'; | |
export const { height, width } = Dimensions.get('window'); | |
const ratioX = width <= 375 ? (width <= 320 ? 0.75 : 0.875) : 1 ; | |
const ratioY = height <= 568 ? (height <= 480 ? 0.75 : 0.875) : 1 ; | |
const base_unit = 16; | |
const unit = base_unit * ratioX; | |
export const em = (value) => unit * value; | |
export const vh = (value) => (height/100) * value; | |
export const vw = (value) => (width/100) * value; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment