From da26d42d5cd740b6d556be952a230fddbeb3ac3c Mon Sep 17 00:00:00 2001 From: iDevelopper Date: Sat, 25 May 2024 07:23:03 +0200 Subject: [PATCH] Fixed the display of the popup bar and bottom bar shadow line --- .../PBPopupController-Swift/PBPopupBar.swift | 4 +- .../PBPopupController.swift | 6 +-- .../UIViewController+Private.swift | 48 +++++++++++-------- .../UIViewController+Support.swift | 9 ++-- 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/PBPopupController/PBPopupController/PBPopupController-Swift/PBPopupBar.swift b/PBPopupController/PBPopupController/PBPopupController-Swift/PBPopupBar.swift index 73175b0..1ef551d 100644 --- a/PBPopupController/PBPopupController/PBPopupController-Swift/PBPopupBar.swift +++ b/PBPopupController/PBPopupController/PBPopupController-Swift/PBPopupBar.swift @@ -301,9 +301,7 @@ internal let PBPopupBarImageHeightFloating: CGFloat = 40.0 */ @objc public var inheritsVisualStyleFromBottomBar: Bool = true { didSet { - if inheritsVisualStyleFromBottomBar == true { - self.popupController.containerViewController.configurePopupBarFromBottomBar() - } + self.popupController.containerViewController.configurePopupBarFromBottomBar() } } diff --git a/PBPopupController/PBPopupController/PBPopupController-Swift/PBPopupController.swift b/PBPopupController/PBPopupController/PBPopupController-Swift/PBPopupController.swift index 41b5fbe..ae7a019 100644 --- a/PBPopupController/PBPopupController/PBPopupController-Swift/PBPopupController.swift +++ b/PBPopupController/PBPopupController/PBPopupController-Swift/PBPopupController.swift @@ -717,8 +717,8 @@ extension PBPopupPresentationStyle UIView.animate(withDuration: animated ? vc.popupBar.popupBarPresentationDuration : 0.0, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0, options: [.curveEaseInOut, .layoutSubviews], animations: { - vc.configureScrollEdgeAppearanceForBottomBar() - + vc.configurePopupBarFromBottomBar() + self.popupBarView.frame = self.popupBarViewFrameForPopupStateClosed() self.popupBarView.alpha = 1.0 @@ -754,7 +754,7 @@ extension PBPopupPresentationStyle vc.popupBar.ignoreLayoutDuringTransition = true UIView.animate(withDuration: animated ? vc.popupBar.popupBarPresentationDuration : 0.0, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0, options: [.curveLinear, .layoutSubviews], animations: { - vc.configureScrollEdgeAppearanceForBottomBar() + vc.configurePopupBarFromBottomBar() self.popupBarView.frame = contentFrame self.popupBarView.alpha = 0.0 diff --git a/PBPopupController/PBPopupController/PBPopupController-Swift/UIViewController+Private.swift b/PBPopupController/PBPopupController/PBPopupController-Swift/UIViewController+Private.swift index b6f9305..9bfc666 100644 --- a/PBPopupController/PBPopupController/PBPopupController-Swift/UIViewController+Private.swift +++ b/PBPopupController/PBPopupController/PBPopupController-Swift/UIViewController+Private.swift @@ -268,9 +268,6 @@ internal extension UITabBarController if self.popupController.popupPresentationState == .presenting { self.tabBar.scrollEdgeAppearance = self.tabBar.standardAppearance } - else { - self.tabBar.scrollEdgeAppearance = nil - } } #endif } @@ -285,15 +282,22 @@ internal extension UITabBarController let bottomBarAppearance = self.tabBar.standardAppearance - self.bottomBarAppearance = bottomBarAppearance.copy() + if self.bottomBarAppearance == nil { + self.bottomBarAppearance = bottomBarAppearance.copy() + } + + self.popupBar.shadowColor = self.bottomBarAppearance.shadowColor - if self.bottomBarAppearance.shadowColor != nil { - self.popupBar.shadowColor = self.bottomBarAppearance.shadowColor + bottomBarAppearance.shadowColor = self.bottomBarAppearance.shadowColor + if self.popupBar.isFloating, self.popupController.popupPresentationState != .hidden { + if self.popupController.popupPresentationState != .dismissing { + bottomBarAppearance.shadowColor = .clear + } } - bottomBarAppearance.shadowColor = appearance.shadowColor - if self.popupBar.isFloating { - bottomBarAppearance.shadowColor = .clear + self.tabBar.standardAppearance = bottomBarAppearance + if #available(iOS 15.0, *) { + self.tabBar.scrollEdgeAppearance = bottomBarAppearance } if self.popupBar.inheritsVisualStyleFromBottomBar == false { @@ -710,9 +714,7 @@ internal extension UINavigationController if self.popupController.popupPresentationState == .presenting { self.toolbar.scrollEdgeAppearance = self.toolbar.standardAppearance - } - else { - self.toolbar.scrollEdgeAppearance = nil + self.toolbar.compactScrollEdgeAppearance = self.toolbar.standardAppearance } } #endif @@ -728,15 +730,24 @@ internal extension UINavigationController let bottomBarAppearance = self.toolbar.standardAppearance - self.bottomBarAppearance = bottomBarAppearance.copy() + if self.bottomBarAppearance == nil { + self.bottomBarAppearance = bottomBarAppearance.copy() + } - if self.bottomBarAppearance.shadowColor != nil { - self.popupBar.shadowColor = self.bottomBarAppearance.shadowColor + self.popupBar.shadowColor = self.bottomBarAppearance.shadowColor + + bottomBarAppearance.shadowColor = self.bottomBarAppearance.shadowColor + if self.popupBar.isFloating, self.popupController.popupPresentationState != .hidden { + if self.popupController.popupPresentationState != .dismissing { + bottomBarAppearance.shadowColor = .clear + } } - bottomBarAppearance.shadowColor = appearance.shadowColor - if self.popupBar.isFloating { - bottomBarAppearance.shadowColor = .clear + self.toolbar.standardAppearance = bottomBarAppearance + self.toolbar.compactAppearance = bottomBarAppearance + if #available(iOS 15.0, *) { + self.toolbar.scrollEdgeAppearance = bottomBarAppearance + self.toolbar.compactScrollEdgeAppearance = bottomBarAppearance } if self.popupBar.inheritsVisualStyleFromBottomBar == false { @@ -1101,7 +1112,6 @@ internal extension UIViewController @objc func configurePopupBarFromBottomBar() { let toolBarAppearance = UIToolbarAppearance() - toolBarAppearance.configureWithDefaultBackground() self.popupBar.shadowColor = toolBarAppearance.shadowColor self.popupBar.backgroundColor = nil diff --git a/PBPopupController/PBPopupController/PBPopupController-Swift/UIViewController+Support.swift b/PBPopupController/PBPopupController/PBPopupController-Swift/UIViewController+Support.swift index 6fb20fa..c35788b 100644 --- a/PBPopupController/PBPopupController/PBPopupController-Swift/UIViewController+Support.swift +++ b/PBPopupController/PBPopupController/PBPopupController-Swift/UIViewController+Support.swift @@ -211,6 +211,11 @@ public extension UIViewController ) } } + else { + withUnsafePointer(to: &AssociatedKeys.bottomBarAppearance) { + objc_setAssociatedObject(self, $0, nil, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) + } + } } } @@ -532,8 +537,6 @@ public extension UIViewController controller.view.setNeedsLayout() controller.view.layoutIfNeeded() - self.configurePopupBarFromBottomBar() - self.popupController._presentPopupBarAnimated(animated) { completion?() } @@ -703,7 +706,7 @@ public extension UIViewController - SeeAlso: `PBPopupBar.inheritsVisualStyleFromBottomBar`. */ @objc func updatePopupBarAppearance() { - self.popupBar.inheritsVisualStyleFromBottomBar = true + self.bottomBarAppearance = nil self.popupBar.updatePopupBarAppearance() } }