UNPKG

rn-toastify

Version:

A customizable and performant toast notification library for React Native, featuring smooth animations, swipe gestures, and flexible styling options.

29 lines (22 loc) 922 B
import {Dimensions, PixelRatio} from 'react-native'; let {width, height} = Dimensions.get('window'); const widthPercentageToDP = widthPercent => { const elemWidth = widthPercent === 'number' ? widthPercent : parseFloat(widthPercent); return PixelRatio.roundToNearestPixel((width * elemWidth) / 100); }; const heightPercentageToDP = heightPercent => { const elemHeight = heightPercent === 'number' ? heightPercent : parseFloat(heightPercent); return PixelRatio.roundToNearestPixel((height * elemHeight) / 100); }; const listenOrientationChange = that => { Dimensions.addEventListener('change', newDimensions => { width = newDimensions.window.width; height = newDimensions.window.height; that.setState({ orientation: width < height ? 'portrait' : 'landscape', }); }); }; export {widthPercentageToDP, heightPercentageToDP, listenOrientationChange};