Expose fontScale to JS

This commit is contained in:
Felix Oghina 2015-06-01 10:19:25 -07:00
parent 57ce9fb11a
commit 2b4daf228d
2 changed files with 15 additions and 0 deletions

View File

@ -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

View File

@ -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).
*