Skip to content

Commit

Permalink
add correct window dimensions for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
rdonnelly committed Sep 29, 2018
1 parent ee03459 commit b12cf11
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
15 changes: 11 additions & 4 deletions React/Modules/RCTDeviceInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,23 @@ static BOOL RCTIsIPhoneX() {
RCTAssertMainQueue();

RCTDimensions dimensions = RCTGetDimensions(bridge.accessibilityManager.multiplier);
typeof (dimensions.window) window = dimensions.window; // Window and Screen are considered equal for iOS.
NSDictionary<NSString *, NSNumber *> *dims = @{
typeof (dimensions.window) window = dimensions.window;
NSDictionary<NSString *, NSNumber *> *dimsWindow = @{
@"width": @(window.width),
@"height": @(window.height),
@"scale": @(window.scale),
@"fontScale": @(window.fontScale)
};
typeof (dimensions.screen) screen = dimensions.screen;
NSDictionary<NSString *, NSNumber *> *dimsScreen = @{
@"width": @(screen.width),
@"height": @(screen.height),
@"scale": @(screen.scale),
@"fontScale": @(screen.fontScale)
};
return @{
@"window": dims,
@"screen": dims
@"window": dimsWindow,
@"screen": dimsScreen
};
}

Expand Down
19 changes: 16 additions & 3 deletions React/UIUtils/RCTUIUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,32 @@

#import "RCTUIUtils.h"

#import "RCTUtils.h"

RCTDimensions RCTGetDimensions(CGFloat fontScale)
{
UIScreen *mainScreen = UIScreen.mainScreen;
CGSize screenSize = mainScreen.bounds.size;

UIView *mainWindow;
mainWindow = RCTKeyWindow();
CGSize windowSize = mainWindow.bounds.size;

RCTDimensions result;
typeof (result.window) dims = {
typeof (result.screen) dimsScreen = {
.width = screenSize.width,
.height = screenSize.height,
.scale = mainScreen.scale,
.fontScale = fontScale
};
result.window = dims;
result.screen = dims;
typeof (result.window) dimsWindow = {
.width = windowSize.width,
.height = windowSize.height,
.scale = mainScreen.scale,
.fontScale = fontScale
};
result.screen = dimsScreen;
result.window = dimsWindow;

return result;
}
Expand Down

0 comments on commit b12cf11

Please sign in to comment.