rn-custom-style-sheet
Version:
React Native component to select a specific value from a range of values.
72 lines (71 loc) • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getDevice = getDevice;
exports.getMatchObject = getMatchObject;
exports.hyphenateKeys = hyphenateKeys;
exports.shallowEqualObjects = shallowEqualObjects;
var _hyphenateStyleName = _interopRequireDefault(require("hyphenate-style-name"));
var _reactNative = require("react-native");
var _Core = require("../../../Core");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function getMatchObject() {
const window = _reactNative.Dimensions.get('window');
const screen = _reactNative.Dimensions.get('screen');
const {
isRTL
} = _reactNative.I18nManager;
const orientation = window.width < window.height ? _Core.OrientationEnum.Portrait : _Core.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: _reactNative.PixelRatio.get(),
type: _reactNative.Platform.isTV ? 'tv' : _reactNative.Platform.OS,
direction: isRTL ? 'rtl' : 'ltr',
prefersColorScheme: _reactNative.Appearance.getColorScheme() === _Core.ThemeModeEnum.Dark ? _Core.ThemeModeEnum.Dark : _Core.ThemeModeEnum.Light
};
}
function hyphenateKeys(obj) {
if (!obj) return undefined;
const keys = Object.keys(obj);
return keys.reduce((result, key) => {
result[(0, _hyphenateStyleName.default)(key)] = obj[key];
return result;
}, {});
}
function getDevice(deviceFromProps, deviceFromContext) {
const result = hyphenateKeys(deviceFromProps) ?? hyphenateKeys(deviceFromContext) ?? hyphenateKeys(getMatchObject());
return result ?? {};
}
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