Skip to content

Instantly share code, notes, and snippets.

@DeVoresyah
Created April 24, 2019 06:58
Show Gist options
  • Save DeVoresyah/5305249d3e668a15d21a2e7fb50fe60f to your computer and use it in GitHub Desktop.
Save DeVoresyah/5305249d3e668a15d21a2e7fb50fe60f to your computer and use it in GitHub Desktop.
Responsive Width & Height
import { Dimensions } from 'react-native';
const { width, height } = Dimensions.get('window');
const ScaleWidth = (scaleWidth) => {
const DESIGN_WIDTH = 180;
return (scaleWidth * width) / DESIGN_WIDTH
}
const ScaleHeight = (scaleHeight) => {
const DESIGN_HEIGHT = 180;
return (scaleHeight * height) / DESIGN_HEIGHT
}
export {
ScaleWidth,
ScaleHeight
}
@DeVoresyah
Copy link
Author

DeVoresyah commented Apr 24, 2019

Usage

<Image source={...} style={{ width: Scale(100), height: Scale(50) }} />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment