react-native-full-responsive
Version:
Create a fully responsive React Native app for all supported platforms
61 lines (60 loc) • 2.64 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.rw = exports.rs = exports.rh = exports.responsiveWidth = exports.responsiveScale = exports.responsiveHeight = void 0;
var _reactNative = require("react-native");
var _utils = require("../utils");
var _getBaseWidth = require("./getBaseWidth");
const {
screenWidth,
screenHeight
} = (0, _utils.getDimensions)();
/**
* The responsive width size will be calculated using the passed percentage.
* @param widthPercentage
* @param width screen width of device
* @returns calculated size, if the passed percentage is not a number, it will be the passed value.
*/
const responsiveWidth = function (widthPercentage) {
let width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : screenWidth;
if (typeof widthPercentage !== 'number') {
return widthPercentage;
}
return _reactNative.PixelRatio.roundToNearestPixel(width * widthPercentage / 100);
};
/**
* The responsive height size will be calculated using the passed percentage.
* @param heightPercentage
* @param height screen height of device
* @returns calculated size, if the passed percentage is not a number, it will be the passed value.
*/
exports.rw = exports.responsiveWidth = responsiveWidth;
const responsiveHeight = function (heightPercentage) {
let height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : screenHeight;
if (typeof heightPercentage !== 'number') {
return heightPercentage;
}
return _reactNative.PixelRatio.roundToNearestPixel(height * heightPercentage / 100);
};
/**
* The responsive scaled size will be calculated using the passed size.
* @param size
* @param width screen width of device
* @param height screen height of device
* @returns scaled size, if the passed size is not a number, it will be the passed value.
*/
exports.rh = exports.responsiveHeight = responsiveHeight;
const responsiveScale = function (size) {
let width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : screenWidth;
let height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : screenHeight;
let config = arguments.length > 3 ? arguments[3] : undefined;
if (typeof size !== 'number') {
return size;
}
const baseWidth = (0, _getBaseWidth.getBaseWidth)(config === null || config === void 0 ? void 0 : config.type, config === null || config === void 0 ? void 0 : config.bases);
const dimension = width < height ? width : height;
return dimension / baseWidth * size;
};
exports.rs = exports.responsiveScale = responsiveScale;
//# sourceMappingURL=responsiveMethods.js.map
;