mirror of
https://github.com/status-im/react-native.git
synced 2025-02-26 16:10:58 +00:00
[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:
parent
642d6cf483
commit
baed197a7d
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user