Skip to content

Instantly share code, notes, and snippets.

@olanipekunife
Created February 12, 2021 10:12
Show Gist options
  • Save olanipekunife/de8b5cb18413718a6d86b0bddbc17e7e to your computer and use it in GitHub Desktop.
Save olanipekunife/de8b5cb18413718a6d86b0bddbc17e7e to your computer and use it in GitHub Desktop.
import {Dimensions} from 'react-native';
const baseWidth = 412;
const baseHeight = 896;
const maxHeightScale = 1.1;
let heightScale = Dimensions.get('window').height / baseHeight;
let fontScale = Dimensions.get('window').height / 800;
if (heightScale > maxHeightScale) {
heightScale = maxHeightScale;
}
const widthScale = Dimensions.get('window').width / baseWidth;
export const getResponsiveHeight = (height) => height * heightScale;
export const getResponsiveWidth = (width) => width * widthScale;
export const getResponsiveFont = (fontSize) => fontSize * fontScale;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment