Skip to content

Commit

Permalink
Safe area insets’ support
Browse files Browse the repository at this point in the history
  • Loading branch information
rivera-ernesto committed Nov 10, 2019
1 parent 6ad7fb9 commit 8c2f8b5
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions Source/PTEDashboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

@implementation PTEDashboard
{
CGSize _screenSize;
CGSize _insetScreenSize;
UIWindow * _keyWindow;
UITableView * _consoleTableView;
NSArray * _fullscreenOnlyViews;
Expand All @@ -40,7 +40,7 @@ + (PTEDashboard *)sharedDashboard
dispatch_once(&onceToken, ^
{
CGRect frame = UIScreen.mainScreen.bounds;
_sharedDashboard = [[self alloc] initWithFrame:UIEdgeInsetsInsetRect(window.frame, window.safeAreaInsets)];
_sharedDashboard = [[self alloc] initWithFrame:frame];
});
return _sharedDashboard;
}
Expand All @@ -51,7 +51,7 @@ - (instancetype)initWithFrame:(CGRect)frame
if (self)
{
self.windowLevel = UIWindowLevelStatusBar + 1;
_screenSize = frame.size;
_insetScreenSize = frame.size;

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
Expand Down Expand Up @@ -93,6 +93,14 @@ - (void)dealloc
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)safeAreaInsetsDidChange
{
[super safeAreaInsetsDidChange];

self.frame = UIEdgeInsetsInsetRect(self.frame, self.safeAreaInsets);
_insetScreenSize = self.frame.size;
}

- (void)show
{
self.hidden = NO;
Expand Down Expand Up @@ -123,15 +131,15 @@ - (void)handleStatusBarOrientationChange:(NSNotification *)notification
switch (nextOrientation)
{
case UIInterfaceOrientationLandscapeLeft:
frame.origin = CGPointMake(0.0, _screenSize.height);
frame.origin = CGPointMake(0.0, _insetScreenSize.height);
transform = CGAffineTransformMakeRotation(- M_PI / 2.0);
break;
case UIInterfaceOrientationLandscapeRight:
frame.origin = CGPointMake(_screenSize.width, 0.0);
frame.origin = CGPointMake(_insetScreenSize.width, 0.0);
transform = CGAffineTransformMakeRotation(M_PI / 2.0);
break;
case UIInterfaceOrientationPortraitUpsideDown:
frame.origin = CGPointMake(_screenSize.width, _screenSize.height);
frame.origin = CGPointMake(_insetScreenSize.width, _insetScreenSize.height);
transform = CGAffineTransformMakeRotation(M_PI);
break;
default:
Expand Down Expand Up @@ -207,12 +215,12 @@ - (void)handlePanGesture:(UIPanGestureRecognizer *)gestureRecognizer

- (BOOL)isMaximized
{
return self.bounds.size.height == _screenSize.height;
return self.bounds.size.height == _insetScreenSize.height;
}

- (void)setMaximized:(BOOL)maximized
{
[self setWindowHeight:_screenSize.height];
[self setWindowHeight:_insetScreenSize.height];
}

- (BOOL)isMinimized
Expand All @@ -229,10 +237,10 @@ - (void)setWindowHeight:(CGFloat)height
{
// Validate height
height = MAX(kMinimumHeight, height);
if (_screenSize.height - height < kMinimumHeight * 2.0)
if (_insetScreenSize.height - height < kMinimumHeight * 2.0)
{
// Snap to bottom
height = _screenSize.height;
height = _insetScreenSize.height;
}

// Adjust layout
Expand All @@ -243,7 +251,7 @@ - (void)setWindowHeight:(CGFloat)height
_consoleTableView.frame = _consoleTableView.superview.bounds;
self.frame = CGRectMake(self.frame.origin.x,
self.frame.origin.y,
_screenSize.width,
_insetScreenSize.width,
height);
}
else
Expand All @@ -256,15 +264,15 @@ - (void)setWindowHeight:(CGFloat)height
_consoleTableView.frame = tableFrame;
self.frame = CGRectMake(self.frame.origin.x,
self.frame.origin.y,
_screenSize.width - 40.0,
_insetScreenSize.width - 40.0,
height);
_consoleTableView.contentOffset = CGPointMake(0.0,
MAX(_consoleTableView.contentOffset.y,
_consoleTableView.tableHeaderView.bounds.size.height));
}

// Change keyWindow to enable keyboard input
if (height == _screenSize.height)
if (height == _insetScreenSize.height)
{
// Maximized
if (!_keyWindow)
Expand Down

0 comments on commit 8c2f8b5

Please sign in to comment.