Skip to content

Instantly share code, notes, and snippets.

@sirgalleto
Created October 30, 2016 23:56
Show Gist options
  • Save sirgalleto/3d62698f4936769a75116b452ee07f1a to your computer and use it in GitHub Desktop.
Save sirgalleto/3d62698f4936769a75116b452ee07f1a to your computer and use it in GitHub Desktop.
react-native responsive
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