UNPKG

rn-toastify

Version:

A professional, production-ready toast notification library for React Native. Featuring smooth spring animations, swipe-to-dismiss gestures, progress bars, queue management, and a beautiful design system with light/dark themes.

29 lines (23 loc) 999 B
import { Dimensions, PixelRatio } from 'react-native'; let { width, height } = Dimensions.get('window'); const widthPercentageToDP = (widthPercent) => { const elemWidth = typeof widthPercent === 'number' ? widthPercent : parseFloat(widthPercent); return PixelRatio.roundToNearestPixel((width * elemWidth) / 100); }; const heightPercentageToDP = (heightPercent) => { const elemHeight = typeof heightPercent === 'number' ? heightPercent : parseFloat(heightPercent); return PixelRatio.roundToNearestPixel((height * elemHeight) / 100); }; const listenOrientationChange = (callback) => { const subscription = Dimensions.addEventListener('change', ({ window }) => { width = window.width; height = window.height; if (typeof callback === 'function') { callback(width < height ? 'portrait' : 'landscape'); } }); return subscription; }; export { widthPercentageToDP, heightPercentageToDP, listenOrientationChange };