Skip to content

Commit

Permalink
Improved bar layouts and default appearances
Browse files Browse the repository at this point in the history
RTL improvements to floating bar
Improved support for changing toolbar and tab bar appearances
Fixed a tab bar transition bug with floating bars
  • Loading branch information
LeoNatan committed Sep 2, 2023
1 parent accc510 commit 0d3b620
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 94 deletions.
63 changes: 42 additions & 21 deletions LNPopupController/LNPopupController/Private/LNPopupBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ - (void)setBarStyle:(LNPopupBarStyle)barStyle

[self _fixupSwiftUIControllersWithBarStyle];

[_barContainingController.bottomDockingViewForPopup_nocreateOrDeveloper setNeedsLayout];
[self setNeedsLayout];

[self _appearanceDidChange];
Expand Down Expand Up @@ -425,9 +426,14 @@ - (void)layoutSubviews
[self _layoutCustomBarController];

[self _layoutImageView];

CGSize toolbarSize = [_toolbar sizeThatFits:CGSizeMake(_contentView.bounds.size.width, CGFLOAT_MAX)];
_toolbar.bounds = CGRectMake(0, 0, _contentView.bounds.size.width, toolbarSize.height);

CGFloat toolbarWidth = _contentView.bounds.size.width;
if(_resolvedStyle == LNPopupBarStyleCompact)
{
toolbarWidth += 12;
}
CGSize toolbarSize = [_toolbar sizeThatFits:CGSizeMake(toolbarWidth, CGFLOAT_MAX)];
_toolbar.bounds = CGRectMake(0, 0, toolbarWidth, toolbarSize.height);
_toolbar.center = CGPointMake(_contentView.bounds.size.width / 2, _contentView.bounds.size.height / 2 - 1);
[_toolbar layoutIfNeeded];

Expand Down Expand Up @@ -478,6 +484,11 @@ - (void)_applyGroupingIdentifier:(NSString*)groupingIdentifier toVisualEffectVie
return;
}

if([[visualEffectView valueForKey:self._effectGroupingIdentifierKey] isEqualToString:groupingIdentifier])
{
return;
}

[visualEffectView setValue:groupingIdentifier ?: [NSString stringWithFormat:@"<%@:%p> Backdrop Group", self.class, self] forKey:self._effectGroupingIdentifierKey];
}

Expand Down Expand Up @@ -593,8 +604,8 @@ - (void)_appearanceDidChange
{
CAGradientLayer* mask = [CAGradientLayer new];
mask.frame = _backgroundView.bounds;
mask.colors = @[(id)UIColor.clearColor.CGColor, (id)UIColor.whiteColor.CGColor, (id)UIColor.whiteColor.CGColor];
mask.locations = @[@0, @0.5, @1];
mask.colors = @[(id)UIColor.clearColor.CGColor, (id)UIColor.whiteColor.CGColor];
mask.locations = @[@0, @0.85];
_backgroundView.layer.mask = mask;

_floatingBackgroundView.hidden = NO;
Expand Down Expand Up @@ -906,9 +917,10 @@ - (void)_updateTitleInsetsForCompactBar:(UIEdgeInsets*)titleInsets
widthLeft = MAX(widthLeft, self.layoutMargins.left);
widthRight = MAX(widthRight, self.layoutMargins.right);

//The added padding is for iOS 10 and below, or for certain conditions where iOS 11 won't put its own padding
titleInsets->left = widthLeft;
titleInsets->right = widthRight;
titleInsets->left = MAX(widthLeft + 8, widthRight + 8);
titleInsets->right = MAX(widthLeft + 8, widthRight + 8);
// titleInsets->left = widthLeft + 8;
// titleInsets->right = widthRight + 8;
}

- (void)_updateTitleInsetsForProminentBar:(UIEdgeInsets*)titleInsets
Expand All @@ -935,7 +947,7 @@ - (void)_updateTitleInsetsForProminentBar:(UIEdgeInsets*)titleInsets
[rightViewFirst.superview layoutIfNeeded];

BOOL isFloating = _resolvedStyle == LNPopupBarStyleFloating;
CGFloat imageToTitlePadding = isFloating ? 8 : 20;
CGFloat imageToTitlePadding = isFloating ? 8 : self.layoutMargins.left;

CGRect leftViewLastFrame = CGRectZero;
if(leftViewLast != nil)
Expand All @@ -946,6 +958,10 @@ - (void)_updateTitleInsetsForProminentBar:(UIEdgeInsets*)titleInsets
{
leftViewLastFrame.size.width += isFloating ? imageToTitlePadding : MIN(_contentView.layoutMargins.left, imageToTitlePadding);
}
else
{
leftViewLastFrame.size.width -= 8;
}
}

CGRect rightViewFirstFrame = CGRectMake(_contentView.bounds.size.width, 0, 0, 0);
Expand All @@ -957,6 +973,10 @@ - (void)_updateTitleInsetsForProminentBar:(UIEdgeInsets*)titleInsets
{
rightViewFirstFrame.origin.x -= isFloating ? imageToTitlePadding : MIN(_contentView.layoutMargins.left, imageToTitlePadding);
}
else
{
rightViewFirstFrame.origin.x += 8;
}
}

CGFloat widthLeft = 0;
Expand All @@ -976,6 +996,7 @@ - (void)_updateTitleInsetsForProminentBar:(UIEdgeInsets*)titleInsets
titleInsets->right = widthRight;
}

//DO NOT CHANGE NAME! Used by LNPopupUI
- (UIFont*)_titleFont
{
CGFloat fontSize = 15;
Expand All @@ -1002,11 +1023,13 @@ - (UIFont*)_titleFont
return [[UIFontMetrics metricsForTextStyle:UIFontTextStyleSubheadline] scaledFontForFont:[UIFont systemFontOfSize:fontSize weight:fontWeight]];
}

//DO NOT CHANGE NAME! Used by LNPopupUI
- (UIColor*)_titleColor
{
return UIColor.labelColor;
}

//DO NOT CHANGE NAME! Used by LNPopupUI
- (UIFont*)_subtitleFont
{
CGFloat fontSize = 15;
Expand All @@ -1033,6 +1056,7 @@ - (UIFont*)_subtitleFont
return [[UIFontMetrics metricsForTextStyle:UIFontTextStyleFootnote] scaledFontForFont:[UIFont systemFontOfSize:fontSize weight:fontWeight]];
}

//DO NOT CHANGE NAME! Used by LNPopupUI
- (UIColor*)_subtitleColor
{
return UIColor.secondaryLabelColor;
Expand Down Expand Up @@ -1071,6 +1095,10 @@ - (void)_layoutTitles
#endif
_titleLabel.textColor = self._titleColor;
_titleLabel.font = self._titleFont;
if(_resolvedStyle == LNPopupBarStyleCompact)
{
_titleLabel.textAlignment = NSTextAlignmentCenter;
}
[_titlesView addSubview:_titleLabel];
}

Expand Down Expand Up @@ -1106,6 +1134,10 @@ - (void)_layoutTitles
#endif
_subtitleLabel.textColor = self._subtitleColor;
_subtitleLabel.font = self._subtitleFont;
if(_resolvedStyle == LNPopupBarStyleCompact)
{
_subtitleLabel.textAlignment = NSTextAlignmentCenter;
}
[_titlesView addSubview:_subtitleLabel];
}

Expand Down Expand Up @@ -1143,24 +1175,13 @@ - (void)_layoutTitles
CGFloat height = _contentView.bounds.size.height;
titleLabelFrame.size.height = height;

//Add some padding for compact bar
if(_resolvedStyle == LNPopupBarStyleCompact)
{
titleLabelFrame.origin.x += 8;
titleLabelFrame.size.width -= 16;
}

if(_attributedSubtitle.length > 0 || _swiftuiSubtitleController != nil)
{
CGRect subtitleLabelFrame = _titlesView.bounds;
subtitleLabelFrame.size.height = height;

if(_resolvedStyle == LNPopupBarStyleCompact)
{
//Add some padding for compact bar
subtitleLabelFrame.origin.x += 8;
subtitleLabelFrame.size.width -= 16;

titleLabelFrame.origin.y -= _titleLabel.font.lineHeight / 2;
subtitleLabelFrame.origin.y += _subtitleLabel.font.lineHeight / 2;
}
Expand Down Expand Up @@ -1299,7 +1320,7 @@ - (void)_layoutImageView
else
{
CGFloat safeLeading = isFloating ? 8 : MAX(self.window.safeAreaInsets.right, self.layoutMargins.right);
_imageView.center = CGPointMake(self.bounds.size.width - safeLeading - imageSize / 2, barHeight / 2);
_imageView.center = CGPointMake(_contentView.bounds.size.width - safeLeading - imageSize / 2, barHeight / 2);
}

_imageView.bounds = CGRectMake(0, 0, imageSize, imageSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ - (void)presentPopupBarAnimated:(BOOL)animated openPopup:(BOOL)open completion:(
_LNCallDelegateObjectBool(_containerController, @selector(popupPresentationControllerWillPresentPopupBar:animated:), animated);
[self.popupBar.customBarViewController _userFacing_viewWillAppear:animated];

[_bottomBar _ln_triggerBarAppearanceRefreshIfNeeded];
[_bottomBar _ln_triggerBarAppearanceRefreshIfNeededTriggeringLayout:YES];
_containerController._ln_bottomBarExtension_nocreate.alpha = 1.0;

CGRect barFrame = self.popupBar.frame;
Expand Down Expand Up @@ -1330,7 +1330,7 @@ - (void)dismissPopupBarAnimated:(BOOL)animated completion:(void(^)(void))complet
self.popupBar.shadowView.alpha = 0.0;
_LNPopupSupportSetPopupInsetsForViewController(_containerController, YES, UIEdgeInsetsZero);

[_bottomBar _ln_triggerBarAppearanceRefreshIfNeeded];
[_bottomBar _ln_triggerBarAppearanceRefreshIfNeededTriggeringLayout:YES];

CGFloat currentBarAlpha = self.popupBarStorage.alpha;
[UIView animateWithDuration:0.5 delay:0.0 usingSpringWithDamping:500 initialSpringVelocity:0 options:UIViewAnimationOptionAllowAnimatedContent animations:^{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef void (^LNInWindowBlock)(dispatch_block_t);

@property (nonatomic, weak, nullable) LNPopupController* attachedPopupController;

- (void)_ln_triggerBarAppearanceRefreshIfNeeded;
- (void)_ln_triggerBarAppearanceRefreshIfNeededTriggeringLayout:(BOOL)layout;
- (BOOL)_ln_scrollEdgeAppearanceRequiresFadeForPopupBar:(LNPopupBar*)popupBar;

- (void)_ln_letMeKnowWhenViewInWindowHierarchy:(LNInWindowBlock)block;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ -(void)setAttachedPopupController:(LNPopupController *)attachedPopupController
objc_setAssociatedObject(self, LNPopupAttachedPopupController, objToSet, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (void)_ln_triggerBarAppearanceRefreshIfNeeded
- (void)_ln_triggerBarAppearanceRefreshIfNeededTriggeringLayout:(BOOL)layout
{
//Do nothing on UIView.
}
Expand Down Expand Up @@ -377,20 +377,25 @@ + (void)load
LNSwizzleMethod(self, @selector(standardAppearance), @selector(_lnpopup_standardAppearance));
LNSwizzleMethod(self, @selector(compactAppearance), @selector(_lnpopup_compactAppearance));
#endif
LNSwizzleMethod(self, @selector(setStandardAppearance:), @selector(_lnpopup_setStandardAppearance:));
LNSwizzleMethod(self, @selector(setCompactAppearance:), @selector(_lnpopup_setCompactAppearance:));
LNSwizzleMethod(self, @selector(scrollEdgeAppearance), @selector(_lnpopup_scrollEdgeAppearance));
LNSwizzleMethod(self, @selector(compactScrollEdgeAppearance), @selector(_lnpopup_compactScrollEdgeAppearance));
}
}
}

- (void)_ln_triggerBarAppearanceRefreshIfNeeded
- (void)_ln_triggerBarAppearanceRefreshIfNeededTriggeringLayout:(BOOL)layout
{
if(@available(iOS 15.0, *))
{
self.scrollEdgeAppearance = self._lnpopup_scrollEdgeAppearance;
self.compactScrollEdgeAppearance = self._lnpopup_compactScrollEdgeAppearance;
[self setNeedsLayout];
[self layoutIfNeeded];
if(layout)
{
[self setNeedsLayout];
[self layoutIfNeeded];
}
}
}

Expand Down Expand Up @@ -445,6 +450,20 @@ - (UIToolbarAppearance*)_lnpopup_compactAppearance
}
#endif

- (void)_lnpopup_setStandardAppearance:(UIToolbarAppearance *)standardAppearance
{
[self _lnpopup_setStandardAppearance:standardAppearance];

[self _ln_triggerBarAppearanceRefreshIfNeededTriggeringLayout:YES];
}

- (void)_lnpopup_setCompactAppearance:(UIToolbarAppearance *)compactAppearance
{
[self _lnpopup_setCompactAppearance:compactAppearance];

[self _ln_triggerBarAppearanceRefreshIfNeededTriggeringLayout:YES];
}

@end

@interface UITabBar (ScrollEdgeSupport) @end
Expand All @@ -459,6 +478,7 @@ + (void)load
#if ! LNPopupControllerEnforceStrictClean
LNSwizzleMethod(self, @selector(standardAppearance), @selector(_lnpopup_standardAppearance));
#endif
LNSwizzleMethod(self, @selector(setStandardAppearance:), @selector(_lnpopup_setStandardAppearance:));
LNSwizzleMethod(self, @selector(scrollEdgeAppearance), @selector(_lnpopup_scrollEdgeAppearance));
}

Expand Down Expand Up @@ -487,27 +507,36 @@ - (void)_ln_transitionBackgroundViewsAnimated:(BOOL)arg1
[self _ln_transitionBackgroundViewsAnimated:YES];
}

- (void)_ln_triggerBarAppearanceRefreshIfNeeded
- (void)_ln_triggerBarAppearanceRefreshIfNeededTriggeringLayout:(BOOL)layout
{
id backgroundView = nil;

if(@available(iOS 15.0, *))
{
#if ! LNPopupControllerEnforceStrictClean
backgroundView = [self valueForKey:_LNPopupDecodeBase64String(_bV)];
objc_setAssociatedObject(backgroundView, LNPopupBarBackgroundViewForceAnimatedKey, @(YES), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
if(backgroundView != nil)
{
objc_setAssociatedObject(backgroundView, LNPopupBarBackgroundViewForceAnimatedKey, @(YES), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
#endif
self.scrollEdgeAppearance = self._lnpopup_scrollEdgeAppearance;
}

//This triggers a refresh of the bar appearance.
[self setNeedsLayout];
[self layoutIfNeeded];
if(layout)
{
//This triggers a refresh of the bar appearance.
[self setNeedsLayout];
[self layoutIfNeeded];
}

if(@available(iOS 15.0, *))
{
#if ! LNPopupControllerEnforceStrictClean
objc_setAssociatedObject(backgroundView, LNPopupBarBackgroundViewForceAnimatedKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
if(backgroundView != nil)
{
objc_setAssociatedObject(backgroundView, LNPopupBarBackgroundViewForceAnimatedKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
#endif
}
}
Expand Down Expand Up @@ -541,4 +570,11 @@ - (UITabBarAppearance *)_lnpopup_standardAppearance
}
#endif

- (void)_lnpopup_setStandardAppearance:(UITabBarAppearance *)standardAppearance
{
[self _lnpopup_setStandardAppearance:standardAppearance];

[self _ln_triggerBarAppearanceRefreshIfNeededTriggeringLayout:YES];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,12 @@ - (void)sBWT:(NSInteger)t iE:(BOOL)e
[self _setTabBarHiddenDuringTransition:YES];
}

if(self._ln_popupController_nocreate.popupBar.resolvedStyle == LNPopupBarStyleFloating)
{
self._ln_popupController_nocreate.popupBar.backgroundView.frame = backgroundViewFrame;
self._ln_popupController_nocreate.popupBar.backgroundView.alpha = context.isCancelled ? 0.0 : 1.0;
}

self._ln_popupController_nocreate.popupBar.bottomShadowView.hidden = YES;
self._ln_popupController_nocreate.popupBar.bottomShadowView.alpha = 1.0;
[self._ln_popupController_nocreate _setContentToState:self._ln_popupController_nocreate.popupControllerInternalState];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
3985DE602549539B00CD76EE /* IntroWebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3985DE5F2549539B00CD76EE /* IntroWebViewController.m */; };
3988E3581B59C3000039C09B /* DemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3988E3571B59C3000039C09B /* DemoViewController.m */; };
399748721D5652250079492B /* DemoPopupContentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 399748711D5652250079492B /* DemoPopupContentViewController.m */; };
39988C762AA1557F00C3BB04 /* SafeSystemImages.m in Sources */ = {isa = PBXBuildFile; fileRef = 39988C752AA1557F00C3BB04 /* SafeSystemImages.m */; };
39988C772AA1557F00C3BB04 /* SafeSystemImages.m in Sources */ = {isa = PBXBuildFile; fileRef = 39988C752AA1557F00C3BB04 /* SafeSystemImages.m */; };
39A3B58B230D400B00E10425 /* SplitViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 39A3B58A230D400B00E10425 /* SplitViewController.m */; };
39BBA86924FEC32F00D9712A /* ManualLayoutCustomBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39BBA86824FEC32F00D9712A /* ManualLayoutCustomBarViewController.swift */; };
39BBA86A24FEC3E500D9712A /* ManualLayoutScene.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 39BBA86524FEC25400D9712A /* ManualLayoutScene.storyboard */; };
Expand Down Expand Up @@ -156,6 +158,8 @@
3988E3571B59C3000039C09B /* DemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoViewController.m; sourceTree = "<group>"; };
399748701D5652250079492B /* DemoPopupContentViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoPopupContentViewController.h; sourceTree = "<group>"; };
399748711D5652250079492B /* DemoPopupContentViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoPopupContentViewController.m; sourceTree = "<group>"; };
39988C742AA1557F00C3BB04 /* SafeSystemImages.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SafeSystemImages.h; sourceTree = "<group>"; };
39988C752AA1557F00C3BB04 /* SafeSystemImages.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SafeSystemImages.m; sourceTree = "<group>"; };
39A134DA1B73FFC0003AB4C5 /* LNPopupControllerExample-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LNPopupControllerExample-Bridging-Header.h"; sourceTree = "<group>"; };
39A3B589230D400B00E10425 /* SplitViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SplitViewController.h; sourceTree = "<group>"; };
39A3B58A230D400B00E10425 /* SplitViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SplitViewController.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -313,6 +317,8 @@
children = (
39837A211B756F4C004D2DA9 /* RandomColors.h */,
39837A1F1B756F1A004D2DA9 /* RandomColors.m */,
39988C742AA1557F00C3BB04 /* SafeSystemImages.h */,
39988C752AA1557F00C3BB04 /* SafeSystemImages.m */,
);
name = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -488,6 +494,7 @@
39756327254ED9EB0066981E /* DemoGallery.m in Sources */,
397C56281B7538A5007A67F0 /* DemoAlbumTableViewController.swift in Sources */,
39837A241B758541004D2DA9 /* DemoMusicPlayerController.swift in Sources */,
39988C762AA1557F00C3BB04 /* SafeSystemImages.m in Sources */,
393F23271E16C192000E969D /* CustomMapBarViewController.swift in Sources */,
393F232B1E16D1E4000E969D /* HigherSearchBar.swift in Sources */,
39A3B58B230D400B00E10425 /* SplitViewController.m in Sources */,
Expand Down Expand Up @@ -530,6 +537,7 @@
39FAFC4324E71A6C008BBC2D /* DemoViewController.m in Sources */,
39FAFC4424E71A6C008BBC2D /* PortraitTabBarController.swift in Sources */,
39E9746F250193B8009F24DF /* ColorfulButton.swift in Sources */,
39988C772AA1557F00C3BB04 /* SafeSystemImages.m in Sources */,
39FAFC4524E71A6C008BBC2D /* SceneDelegate.m in Sources */,
39FAFC4624E71A6C008BBC2D /* MusicCell.swift in Sources */,
);
Expand Down
Loading

0 comments on commit 0d3b620

Please sign in to comment.