UNPKG

react-native-full-responsive

Version:

Create a fully responsive React Native app for all supported platforms

53 lines 2.35 kB
import { PixelRatio } from 'react-native'; import { getDimensions } from '../utils'; import { getBaseWidth } from './getBaseWidth'; const { screenWidth, screenHeight } = 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 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. */ const responsiveHeight = function (heightPercentage) { let height = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : screenHeight; if (typeof heightPercentage !== 'number') { return heightPercentage; } return 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. */ 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 = 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; }; export { responsiveScale, responsiveWidth, responsiveHeight, responsiveScale as rs, responsiveWidth as rw, responsiveHeight as rh }; //# sourceMappingURL=responsiveMethods.js.map