From 2b4daf228d2f99bb36fbbc7458b7e53f462f8d82 Mon Sep 17 00:00:00 2001 From: Felix Oghina Date: Mon, 1 Jun 2015 10:19:25 -0700 Subject: [PATCH] Expose fontScale to JS --- Libraries/Utilities/Dimensions.js | 1 + Libraries/Utilities/PixelRatio.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/Libraries/Utilities/Dimensions.js b/Libraries/Utilities/Dimensions.js index b93000a33..31fa0d4dc 100644 --- a/Libraries/Utilities/Dimensions.js +++ b/Libraries/Utilities/Dimensions.js @@ -29,6 +29,7 @@ if (dimensions && dimensions.windowPhysicalPixels) { width: windowPhysicalPixels.width / windowPhysicalPixels.scale, height: windowPhysicalPixels.height / windowPhysicalPixels.scale, scale: windowPhysicalPixels.scale, + fontScale: windowPhysicalPixels.fontScale, }; // delete so no callers rely on this existing diff --git a/Libraries/Utilities/PixelRatio.js b/Libraries/Utilities/PixelRatio.js index a3e4d9e77..7660fad30 100644 --- a/Libraries/Utilities/PixelRatio.js +++ b/Libraries/Utilities/PixelRatio.js @@ -59,6 +59,20 @@ class PixelRatio { return Dimensions.get('window').scale; } + /** + * Returns the scaling factor for font sizes. This is the ratio that is used to calculate the + * absolute font size, so any elements that heavily depend on that should use this to do + * calculations. + * + * If a font scale is not set, this returns the device pixel ratio. + * + * Currently this is only implemented on Android and reflects the user preference set in + * Settings > Display > Font size, on iOS it will always return the default pixel ratio. + */ + static getFontScale(): number { + return Dimensions.get('window').fontScale || PixelRatio.get(); + } + /** * Converts a layout size (dp) to pixel size (px). *