rn-custom-style-sheet
Version:
React Native component to select a specific value from a range of values.
27 lines (25 loc) • 1.24 kB
JavaScript
import { Platform } from 'react-native';
export function getGeneralScreenResolution(screenResolution, guideLineLayout, baseSizeLayout) {
const baseWidth = screenResolution.shortDimension / guideLineLayout.width;
const baseHeight = screenResolution.longDimension / guideLineLayout.height;
// Calculate the base size by averaging the base width and base height.
const baseSizeRatio = (baseWidth + baseHeight) / 2;
// Consider 1.2 as a threshold for identifying tablets based on analyzing multiple devices.
const isIPad = Platform.OS === 'ios' && Platform.isPad;
const isTablet = isIPad || baseSizeRatio > (baseSizeLayout?.androidTabletRatio ?? 1.2);
let threshold = isTablet ? baseSizeLayout?.thresholdOfTablet ?? 0.4 : baseSizeLayout?.thresholdOfPhone ?? 0.5;
if (baseSizeLayout?.thresholdFunction) {
threshold = baseSizeLayout.thresholdFunction(baseSizeRatio, isTablet);
}
// Adjust the base size based on whether the device is identified as a tablet or not.
const baseSizeWithThreshold = (baseWidth + baseHeight) * threshold;
return {
baseWidth,
baseHeight,
isTablet,
threshold,
baseSizeRatio,
baseSizeWithThreshold
};
}
//# sourceMappingURL=GeneralScreenResolutionUtils.js.map