Skip to content

Commit

Permalink
PLAYRTS-5578 Refactor layout constraints code
Browse files Browse the repository at this point in the history
  • Loading branch information
mutaben committed Nov 19, 2024
1 parent ce4df6b commit 60c91a4
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions Application/Sources/UI/Controllers/TabBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ @interface TabBarController ()
@property (nonatomic, readonly) NSLayoutConstraint *playerLeadingConstraint;
@property (nonatomic, readonly) NSLayoutConstraint *playerTrailingConstraint;
@property (nonatomic, readonly) NSLayoutConstraint *playerHeightConstraint;
@property (nonatomic, readonly) NSLayoutConstraint *playerBottomToViewConstraint;
@property (nonatomic, readonly) NSLayoutConstraint *playerBottomToSafeAreaConstraint;
@property (nonatomic, readonly) NSLayoutConstraint *playerBottomConstraint;

@end

Expand All @@ -44,8 +43,7 @@ @implementation TabBarController
@synthesize playerLeadingConstraint = _playerLeadingConstraint;
@synthesize playerTrailingConstraint = _playerTrailingConstraint;
@synthesize playerHeightConstraint = _playerHeightConstraint;
@synthesize playerBottomToViewConstraint = _playerBottomToViewConstraint;
@synthesize playerBottomToSafeAreaConstraint = _playerBottomToSafeAreaConstraint;
@synthesize playerBottomConstraint = _playerBottomConstraint;

#pragma mark Object lifecycle

Expand Down Expand Up @@ -128,10 +126,10 @@ - (NSLayoutConstraint *)playerHeightConstraint

- (NSLayoutConstraint*)preiOS18BottomConstraint
{
if (! _playerBottomToViewConstraint) {
_playerBottomToViewConstraint = [self.miniPlayerView.bottomAnchor constraintEqualToAnchor:self.tabBar.topAnchor];
if (! _playerBottomConstraint) {
_playerBottomConstraint = [self.miniPlayerView.bottomAnchor constraintEqualToAnchor:self.tabBar.topAnchor];
}
return _playerBottomToViewConstraint;
return _playerBottomConstraint;

}

Expand All @@ -140,11 +138,10 @@ - (NSLayoutConstraint *)playerBottomToViewConstraint

if (@available(iOS 18.0, *)) {
if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
if (! _playerBottomToViewConstraint) {
_playerBottomToViewConstraint = [self.miniPlayerView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor];
if (! _playerBottomConstraint) {
_playerBottomConstraint = [self.miniPlayerView.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor];
}
_playerBottomToViewConstraint.constant = -self.tabBar.bounds.size.height;
return _playerBottomToViewConstraint;
return _playerBottomConstraint;
} else {
return [self preiOS18BottomConstraint];
}
Expand All @@ -153,14 +150,6 @@ - (NSLayoutConstraint *)playerBottomToViewConstraint
}
}

- (NSLayoutConstraint *)playerBottomToSafeAreaConstraint
{
if (! _playerBottomToSafeAreaConstraint) {
_playerBottomToSafeAreaConstraint = [self.miniPlayerView.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor];
}
return _playerBottomToSafeAreaConstraint;
}

#pragma mark View lifecycle

- (void)viewDidLoad
Expand Down Expand Up @@ -429,17 +418,22 @@ - (void)updateLayoutAnimated:(BOOL)animated

if (self.miniPlayerView.active) {
self.playerHeightConstraint.constant = MiniPlayerHeight;
self.playerBottomToSafeAreaConstraint.constant = -self.miniPlayerOffset;
if (@available(iOS 18.0, *)) {
if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
self.playerBottomToViewConstraint.constant = -self.miniPlayerOffset;
}
} else {
self.playerBottomToViewConstraint.constant = -self.miniPlayerOffset;
}
}
else {
self.playerHeightConstraint.constant = 0.f;
self.playerBottomToSafeAreaConstraint.constant = 0.f;
self.playerBottomToViewConstraint.constant = 0.f;
}

self.playerHeightConstraint.active = YES;
BOOL isRegular = (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassRegular);
self.playerBottomToViewConstraint.active = ! isRegular;
self.playerBottomToSafeAreaConstraint.active = isRegular;
self.playerBottomToViewConstraint.active = YES;

CALayer *miniPlayerLayer = self.miniPlayerView.layer;
if (UIAccessibilityIsVoiceOverRunning()) {
Expand Down

0 comments on commit 60c91a4

Please sign in to comment.