Skip to content

Update window size when the in-call status bar is toggled #19919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 19 additions & 40 deletions React/Modules/RCTDeviceInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
#import "RCTUIUtils.h"
#import "RCTUtils.h"

@implementation RCTDeviceInfo {
#if !TARGET_OS_TV
UIInterfaceOrientation _currentInterfaceOrientation;
#endif
}
@implementation RCTDeviceInfo

@synthesize bridge = _bridge;

Expand All @@ -42,11 +38,9 @@ - (void)setBridge:(RCTBridge *)bridge
name:RCTAccessibilityManagerDidUpdateMultiplierNotification
object:_bridge.accessibilityManager];
#if !TARGET_OS_TV
_currentInterfaceOrientation = [RCTSharedApplication() statusBarOrientation];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(interfaceOrientationDidChange)
name:UIApplicationDidChangeStatusBarOrientationNotification
selector:@selector(applicationDidChangeStatusBarFrame)
name:UIApplicationDidChangeStatusBarFrameNotification
object:nil];
#endif
}
Expand All @@ -72,16 +66,21 @@ 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 = @{
@"width": @(window.width),
@"height": @(window.height),
@"scale": @(window.scale),
@"fontScale": @(window.fontScale)
NSDictionary<NSString *, NSNumber *> *screen = @{
@"width": @(dimensions.screen.width),
@"height": @(dimensions.screen.height),
@"scale": @(dimensions.screen.scale),
@"fontScale": @(dimensions.screen.fontScale),
};
NSDictionary<NSString *, NSNumber *> *window = @{
@"width": @(dimensions.window.width),
@"height": @(dimensions.window.height),
@"scale": @(dimensions.window.scale),
@"fontScale": @(dimensions.window.fontScale),
};
return @{
@"window": dims,
@"screen": dims
@"screen": screen,
@"window": window,
};
}

Expand Down Expand Up @@ -125,35 +124,15 @@ - (void)didReceiveNewContentSizeMultiplier

#if !TARGET_OS_TV

- (void)interfaceOrientationDidChange
{
__weak typeof(self) weakSelf = self;
RCTExecuteOnMainQueue(^{
[weakSelf _interfaceOrientationDidChange];
});
}


- (void)_interfaceOrientationDidChange
- (void)applicationDidChangeStatusBarFrame
{
UIInterfaceOrientation nextOrientation = [RCTSharedApplication() statusBarOrientation];

// Update when we go from portrait to landscape, or landscape to portrait
if ((UIInterfaceOrientationIsPortrait(_currentInterfaceOrientation) &&
!UIInterfaceOrientationIsPortrait(nextOrientation)) ||
(UIInterfaceOrientationIsLandscape(_currentInterfaceOrientation) &&
!UIInterfaceOrientationIsLandscape(nextOrientation))) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[_bridge.eventDispatcher sendDeviceEventWithName:@"didUpdateDimensions"
body:RCTExportedDimensions(_bridge)];
[_bridge.eventDispatcher sendDeviceEventWithName:@"didUpdateDimensions"
body:RCTExportedDimensions(_bridge)];
#pragma clang diagnostic pop
}

_currentInterfaceOrientation = nextOrientation;
}

#endif // TARGET_OS_TV


@end
18 changes: 15 additions & 3 deletions React/UIUtils/RCTUIUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,31 @@

#import "RCTUIUtils.h"

#import "RCTUtils.h"

RCTDimensions RCTGetDimensions(CGFloat fontScale)
{
UIScreen *mainScreen = UIScreen.mainScreen;
CGSize screenSize = mainScreen.bounds.size;
RCTDimensions result;
typeof (result.window) dims = {
typeof (result.screen) screen = {
.width = screenSize.width,
.height = screenSize.height,
.scale = mainScreen.scale,
.fontScale = fontScale
};
result.window = dims;
result.screen = dims;
result.screen = screen;

// Use bounds of the root view to take into consideration the size change
// when the in-call status bar is opened.
CGSize windowSize = RCTKeyWindow().rootViewController.view.bounds.size;
typeof (result.window) window = {
.width = windowSize.width,
.height = windowSize.height,
.scale = mainScreen.scale,
.fontScale = fontScale
};
result.window = window;

return result;
}
Expand Down