Guest User

Untitled

a guest
Apr 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. # Formula for % Base calculation of width and height of a view in react native
  2.  
  3. `import {Dimensions, PixelRatio} from 'react-native'; const widthPercentageToDP = widthPercent => { const screenWidth = Dimensions.get('window').width; // Convert string input to decimal number const elemWidth = parseFloat(widthPercent); return PixelRatio.roundToNearestPixel(screenWidth * elemWidth / 100); }; const heightPercentageToDP = heightPercent => { const screenHeight = Dimensions.get('window').height; // Convert string input to decimal number const elemHeight = parseFloat(heightPercent); return PixelRatio.roundToNearestPixel(screenHeight * elemHeight / 100); }; export { widthPercentageToDP, heightPercentageToDP };`
Add Comment
Please, Sign In to add comment