@tamagui/react-native-web-lite
Version:
React Native for Web
35 lines (34 loc) • 1.02 kB
JavaScript
import { Dimensions } from "../Dimensions/index.mjs";
class PixelRatio {
/**
* Returns the device pixel density.
*/
static get() {
return Dimensions.get("window").scale;
}
/**
* No equivalent for Web
*/
static getFontScale() {
return Dimensions.get("window").fontScale || PixelRatio.get();
}
/**
* Converts a layout size (dp) to pixel size (px).
* Guaranteed to return an integer number.
*/
static getPixelSizeForLayoutSize(layoutSize) {
return Math.round(layoutSize * PixelRatio.get());
}
/**
* Rounds a layout size (dp) to the nearest layout size that corresponds to
* an integer number of pixels. For example, on a device with a PixelRatio
* of 3, `PixelRatio.roundToNearestPixel(8.4) = 8.33`, which corresponds to
* exactly (8.33 * 3) = 25 pixels.
*/
static roundToNearestPixel(layoutSize) {
const ratio = PixelRatio.get();
return Math.round(layoutSize * ratio) / ratio;
}
}
export { PixelRatio };
//# sourceMappingURL=index.mjs.map