[react_native] JS files from D1998038: [react_native] Calculate density independent screen size in JS to prevent loss of precision

This commit is contained in:
Andy Street 2015-04-16 14:50:00 -07:00
parent 642d6cf483
commit baed197a7d

View File

@ -17,6 +17,26 @@ var invariant = require('invariant');
var dimensions = NativeModules.UIManager.Dimensions;
// We calculate the window dimensions in JS so that we don't encounter loss of
// precision in transferring the dimensions (which could be non-integers) over
// the bridge.
if (dimensions.windowPhysicalPixels) {
// parse/stringify => Clone hack
dimensions = JSON.parse(JSON.stringify(dimensions));
var windowPhysicalPixels = dimensions.windowPhysicalPixels;
dimensions.window = {
width: windowPhysicalPixels.width / windowPhysicalPixels.scale,
height: windowPhysicalPixels.height / windowPhysicalPixels.scale,
scale: windowPhysicalPixels.scale,
};
// TODO(andrews): Remove modalFullscreenView
dimensions.modalFullscreenView = dimensions.window;
// delete so no callers rely on this existing
delete dimensions.windowPhysicalPixels;
}
class Dimensions {
/**
* This should only be called from native code.