UNPKG

rn-custom-style-sheet

Version:

React Native component to select a specific value from a range of values.

62 lines 2.06 kB
import hyphenate from 'hyphenate-style-name'; import { Appearance, Dimensions, I18nManager, Platform, PixelRatio } from 'react-native'; import { OrientationEnum, ThemeModeEnum } from '../../../Core'; export function getMatchObject() { const window = Dimensions.get('window'); const screen = Dimensions.get('screen'); const { isRTL } = I18nManager; const orientation = window.width < window.height ? OrientationEnum.Portrait : OrientationEnum.Landscape; const windowWidth = window.width; const windowHeight = window.height; const screenWidth = screen.width; const screenHeight = screen.height; return { width: windowWidth, height: windowHeight, orientation: orientation, aspectRatio: windowWidth / windowHeight, deviceWidth: screenWidth, deviceHeight: screenHeight, deviceAspectRatio: screenWidth / screenHeight, pixelRatio: PixelRatio.get(), type: Platform.isTV ? 'tv' : Platform.OS, direction: isRTL ? 'rtl' : 'ltr', prefersColorScheme: Appearance.getColorScheme() === ThemeModeEnum.Dark ? ThemeModeEnum.Dark : ThemeModeEnum.Light }; } export function hyphenateKeys(obj) { if (!obj) return undefined; const keys = Object.keys(obj); return keys.reduce((result, key) => { result[hyphenate(key)] = obj[key]; return result; }, {}); } export function getDevice(deviceFromProps, deviceFromContext) { const result = hyphenateKeys(deviceFromProps) ?? hyphenateKeys(deviceFromContext) ?? hyphenateKeys(getMatchObject()); return result ?? {}; } export function shallowEqualObjects(objA, objB) { if (objA === objB) { return true; } if (!objA || !objB) { return false; } const aKeys = Object.keys(objA); const bKeys = Object.keys(objB); const len = aKeys.length; if (bKeys.length !== len) { return false; } for (let i = 0; i < len; i++) { const key = aKeys[i]; if (key && (objA[key] !== objB[key] || !Object.prototype.hasOwnProperty.call(objB, key))) { return false; } } return true; } //# sourceMappingURL=UseDeviceUtils.js.map