mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Expose screen metrics and window metrics
Summary: public https://github.com/facebook/react-native/pull/4935 changed the window dimensions for android by replacing them with the actual screen dimensions. This changes the window dimensions back to their original values and adds `Dimensions.get('screen')` for the actual screen dimensions of the device. Reviewed By: astreet Differential Revision: D2921584 fb-gh-sync-id: 5d2677029c71d50691691dc651a11e9c8b115e8f shipit-source-id: 5d2677029c71d50691691dc651a11e9c8b115e8f
This commit is contained in:
committed by
facebook-github-bot-3
parent
6f1417c849
commit
228a1fe7d4
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var Platform = require('Platform');
|
||||
var UIManager = require('UIManager');
|
||||
|
||||
var invariant = require('invariant');
|
||||
@@ -31,7 +32,21 @@ if (dimensions && dimensions.windowPhysicalPixels) {
|
||||
scale: windowPhysicalPixels.scale,
|
||||
fontScale: windowPhysicalPixels.fontScale,
|
||||
};
|
||||
if (Platform.OS === 'android') {
|
||||
// Screen and window dimensions are different on android
|
||||
var screenPhysicalPixels = dimensions.screenPhysicalPixels;
|
||||
dimensions.screen = {
|
||||
width: screenPhysicalPixels.width / screenPhysicalPixels.scale,
|
||||
height: screenPhysicalPixels.height / screenPhysicalPixels.scale,
|
||||
scale: screenPhysicalPixels.scale,
|
||||
fontScale: screenPhysicalPixels.fontScale,
|
||||
};
|
||||
|
||||
// delete so no callers rely on this existing
|
||||
delete dimensions.screenPhysicalPixels;
|
||||
} else {
|
||||
dimensions.screen = dimensions.window;
|
||||
}
|
||||
// delete so no callers rely on this existing
|
||||
delete dimensions.windowPhysicalPixels;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user