react-native-full-responsive
Version:
Create a fully responsive React Native app for all supported platforms
43 lines (42 loc) • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useMediaQuery = exports.useMQ = void 0;
var _react = require("react");
var _constants = require("../constants");
var _reactNative = require("react-native");
const useMediaQuery = function () {
let thresholds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _constants.DefaultThresholds;
const {
width,
height
} = (0, _reactNative.useWindowDimensions)();
const mergedThresholds = (0, _react.useMemo)(() => {
return {
..._constants.DefaultThresholds,
...thresholds
};
}, [thresholds]);
const deviceSize = (0, _react.useMemo)(() => {
let type;
const candidatedSize = width < height ? width : height;
if (candidatedSize <= mergedThresholds.xs) {
type = 'xs';
} else if (candidatedSize <= mergedThresholds.sm) {
type = 'sm';
} else if (candidatedSize <= mergedThresholds.md) {
type = 'md';
} else if (candidatedSize <= mergedThresholds.lg) {
type = 'lg';
} else if (candidatedSize <= mergedThresholds.xl) {
type = 'xl';
} else {
type = '2xl';
}
return type;
}, [mergedThresholds, height, width]);
return deviceSize;
};
exports.useMQ = exports.useMediaQuery = useMediaQuery;
//# sourceMappingURL=useMediaQuery.js.map