UNPKG

react-native-responsive

Version:

A React Native module to manage responsive layouts more efficiently

69 lines (57 loc) • 2.87 kB
import Model from "./model.js"; import { DeviceUtil } from "../apis"; class Device extends Model { constructor(expected) { super(expected); } debug(identifierName) { console.log( `šŸ“± DEVICE LOGS for ${identifierName}:\n`, ` šŸ‘‰ šŸ“± Device Width (css pixels): ${DeviceUtil.width} dip\n`, ` šŸ‘‰ šŸ“± Device Height (css pixels): ${DeviceUtil.height} dip\n`, ` šŸ‘‰ šŸ“± Device Width (physical pixels): ${DeviceUtil.physicalWidth} px\n`, ` šŸ‘‰ šŸ“± Device Height (physical pixels): ${DeviceUtil.physicalHeight} px\n`, ` šŸ‘‰ šŸ“± Device Pixel Ratio: ${DeviceUtil.pixelRatio}\n\n`, ` šŸ‘‰ šŸ“± props.deviceWidth: ${this.expected.deviceWidth} px\n`, ` šŸ‘‰ šŸ“± props.minDeviceWidth: ${this.expected.minDeviceWidth} px\n`, ` šŸ‘‰ šŸ“± props.maxDeviceWidth: ${this.expected.maxDeviceWidth} px\n`, ` šŸ‘‰ šŸ“± props.deviceHeight: ${this.expected.deviceHeight} px\n`, ` šŸ‘‰ šŸ“± props.minDeviceHeight: ${this.expected.minDeviceHeight} px\n`, ` šŸ‘‰ šŸ“± props.maxDeviceHeight: ${this.expected.maxDeviceHeight} px\n`, ` šŸ‘‰ šŸ“± props.devicePixelRatio: ${this.expected.devicePixelRatio}\n`, ` šŸ‘‰ šŸ“± props.minDevicePixelRatio: ${this.expected.minDevicePixelRatio}\n`, ` šŸ‘‰ šŸ“± props.maxDevicePixelRatio: ${this.expected.maxDevicePixelRatio}\n`, ); } isValid() { return this.isValidWidth(this.expected) && this.isValidHeight(this.expected) && this.isValidPixelRatio(this.expected); } isValidWidth(expected) { return Device.isInIntervalOrEqual(DeviceUtil.width, expected.deviceWidth, expected.minDeviceWidth, expected.maxDeviceWidth); } isValidHeight(expected) { return Device.isInIntervalOrEqual(DeviceUtil.height, expected.deviceHeight, expected.minDeviceHeight, expected.maxDeviceHeight); } isValidPixelRatio(expected) { return Device.isInIntervalOrEqual(DeviceUtil.pixelRatio, expected.devicePixelRatio, expected.minDevicePixelRatio, expected.maxDevicePixelRatio); } static isValidWidthFromOperator(operator, expectedWidth) { return Device.isInIntervalOrEqualFromOperator(operator, expectedWidth, DeviceUtil.width); } static isValidHeightFromOperator(operator, expectedHeight) { return Device.isInIntervalOrEqualFromOperator(operator, expectedHeight, DeviceUtil.height); } static isValidPixelRatioFromOperator(operator, expectedPixelRatio) { return Device.isInIntervalOrEqualFromOperator(operator, expectedPixelRatio, DeviceUtil.pixelRatio); } static get information() { return [ `šŸ‘‰ šŸ“± Device Width (css pixels): ${DeviceUtil.width} dip`, `šŸ‘‰ šŸ“± Device Height (css pixels): ${DeviceUtil.height} dip`, `šŸ‘‰ šŸ“± Device Width (physical pixels): ${DeviceUtil.physicalWidth} px`, `šŸ‘‰ šŸ“± Device Height (physical pixels): ${DeviceUtil.physicalHeight} px`, `šŸ‘‰ šŸ“± Device Pixel Ratio: ${DeviceUtil.pixelRatio}` ]; } } export default Device;