From 95f65d57f018a18ec352c6bf7fde1a6e3c4550c9 Mon Sep 17 00:00:00 2001 From: Timothy Moose Date: Sun, 3 Dec 2023 10:41:56 -0600 Subject: [PATCH] #534 Fix warnings? --- SwiftMessages/BaseView.swift | 10 +-- .../MarginAdjustable+Extensions.swift | 21 +----- SwiftMessages/PhysicsAnimation.swift | 4 +- SwiftMessages/Presenter.swift | 65 ++++++++----------- SwiftMessages/TopBottomAnimation.swift | 4 +- 5 files changed, 35 insertions(+), 69 deletions(-) diff --git a/SwiftMessages/BaseView.swift b/SwiftMessages/BaseView.swift index e5aa7b9c..c41d166b 100644 --- a/SwiftMessages/BaseView.swift +++ b/SwiftMessages/BaseView.swift @@ -280,6 +280,11 @@ open class BaseView: UIView, BackgroundViewable, MarginAdjustable { private var layoutConstraints: [NSLayoutConstraint] = [] private var regularWidthLayoutConstraints: [NSLayoutConstraint] = [] + + open override func layoutSubviews() { + super.layoutSubviews() + updateShadowPath() + } } /* @@ -334,11 +339,6 @@ extension BaseView { // Update the layer's `shadowPath` without animation layer.shadowPath = shadowPath } } - - open override func layoutSubviews() { - super.layoutSubviews() - updateShadowPath() - } } /* diff --git a/SwiftMessages/MarginAdjustable+Extensions.swift b/SwiftMessages/MarginAdjustable+Extensions.swift index b6277885..da8f46d1 100644 --- a/SwiftMessages/MarginAdjustable+Extensions.swift +++ b/SwiftMessages/MarginAdjustable+Extensions.swift @@ -13,25 +13,8 @@ extension MarginAdjustable where Self: UIView { var layoutMargins: UIEdgeInsets = layoutMarginAdditions var safeAreaInsets: UIEdgeInsets = { guard respectSafeArea else { return .zero } - if #available(iOS 11, *) { - insetsLayoutMarginsFromSafeArea = false - return self.safeAreaInsets - } else { - #if SWIFTMESSAGES_APP_EXTENSIONS - let application: UIApplication? = nil - #else - let application: UIApplication? = UIApplication.shared - #endif - if !context.safeZoneConflicts.isDisjoint(with: [.statusBar]), - let app = application, - app.statusBarOrientation == .portrait || app.statusBarOrientation == .portraitUpsideDown { - let frameInWindow = convert(bounds, to: window) - let top = max(0, 20 - frameInWindow.minY) - return UIEdgeInsets(top: top, left: 0, bottom: 0, right: 0) - } else { - return .zero - } - } + insetsLayoutMarginsFromSafeArea = false + return self.safeAreaInsets }() if !context.safeZoneConflicts.isDisjoint(with: .overStatusBar) { safeAreaInsets.top = 0 diff --git a/SwiftMessages/PhysicsAnimation.swift b/SwiftMessages/PhysicsAnimation.swift index 0fb976c5..c073fe4a 100644 --- a/SwiftMessages/PhysicsAnimation.swift +++ b/SwiftMessages/PhysicsAnimation.swift @@ -93,9 +93,7 @@ public class PhysicsAnimation: NSObject, Animator { guard let adjustable = messageView as? MarginAdjustable & UIView, let context = context else { return } adjustable.preservesSuperviewLayoutMargins = false - if #available(iOS 11, *) { - adjustable.insetsLayoutMarginsFromSafeArea = false - } + adjustable.insetsLayoutMarginsFromSafeArea = false adjustable.layoutMargins = adjustable.defaultMarginAdjustment(context: context) } diff --git a/SwiftMessages/Presenter.swift b/SwiftMessages/Presenter.swift index 5a3648b8..44f92015 100644 --- a/SwiftMessages/Presenter.swift +++ b/SwiftMessages/Presenter.swift @@ -236,7 +236,7 @@ class Presenter: NSObject { } private func safeZoneConflicts() -> SafeZoneConflicts { - guard let window = maskingView.window else { return [] } + guard let _ = maskingView.window else { return [] } let windowLevel: UIWindow.Level = { if let vc = presentationContext.viewControllerValue() as? WindowViewController { return vc.config.windowLevel ?? .normal @@ -253,47 +253,34 @@ class Presenter: NSObject { if let vc = presentationContext.viewControllerValue() as? UITabBarController { return vc.sm_isVisible(view: vc.tabBar) } return false }() - if #available(iOS 11, *) { - if windowLevel > .normal { - // TODO seeing `maskingView.safeAreaInsets.top` value of 20 on - // iPhone 8 with status bar window level. This seems like an iOS bug since - // the message view's window is above the status bar. Applying a special rule - // to allow the animator to revove this amount from the layout margins if needed. - // This may need to be reworked if any future device has a legitimate 20pt top safe area, - // such as with a potentially smaller notch. - if maskingView.safeAreaInsets.top == 20 { - return [.overStatusBar] - } else { - var conflicts: SafeZoneConflicts = [] - if maskingView.safeAreaInsets.top > 0 { - conflicts.formUnion(.sensorNotch) - } - if maskingView.safeAreaInsets.bottom > 0 { - conflicts.formUnion(.homeIndicator) - } - return conflicts + if windowLevel > .normal { + // TODO seeing `maskingView.safeAreaInsets.top` value of 20 on + // iPhone 8 with status bar window level. This seems like an iOS bug since + // the message view's window is above the status bar. Applying a special rule + // to allow the animator to revove this amount from the layout margins if needed. + // This may need to be reworked if any future device has a legitimate 20pt top safe area, + // such as with a potentially smaller notch. + if maskingView.safeAreaInsets.top == 20 { + return [.overStatusBar] + } else { + var conflicts: SafeZoneConflicts = [] + if maskingView.safeAreaInsets.top > 0 { + conflicts.formUnion(.sensorNotch) } + if maskingView.safeAreaInsets.bottom > 0 { + conflicts.formUnion(.homeIndicator) + } + return conflicts } - var conflicts: SafeZoneConflicts = [] - if !underNavigationBar { - conflicts.formUnion(.sensorNotch) - } - if !underTabBar { - conflicts.formUnion(.homeIndicator) - } - return conflicts - } else { - #if SWIFTMESSAGES_APP_EXTENSIONS - return [] - #else - if UIApplication.shared.isStatusBarHidden { return [] } - if (windowLevel > UIWindow.Level.normal) || underNavigationBar { return [] } - let statusBarFrame = UIApplication.shared.statusBarFrame - let statusBarWindowFrame = window.convert(statusBarFrame, from: nil) - let statusBarViewFrame = maskingView.convert(statusBarWindowFrame, from: nil) - return statusBarViewFrame.intersects(maskingView.bounds) ? SafeZoneConflicts.statusBar : [] - #endif } + var conflicts: SafeZoneConflicts = [] + if !underNavigationBar { + conflicts.formUnion(.sensorNotch) + } + if !underTabBar { + conflicts.formUnion(.homeIndicator) + } + return conflicts } private func getPresentationContext() throws -> PresentationContext { diff --git a/SwiftMessages/TopBottomAnimation.swift b/SwiftMessages/TopBottomAnimation.swift index 21b0f271..a0d440c7 100644 --- a/SwiftMessages/TopBottomAnimation.swift +++ b/SwiftMessages/TopBottomAnimation.swift @@ -130,9 +130,7 @@ public class TopBottomAnimation: NSObject, Animator { guard let adjustable = messageView as? MarginAdjustable & UIView, let context = context else { return } adjustable.preservesSuperviewLayoutMargins = false - if #available(iOS 11, *) { - adjustable.insetsLayoutMarginsFromSafeArea = false - } + adjustable.insetsLayoutMarginsFromSafeArea = false var layoutMargins = adjustable.defaultMarginAdjustment(context: context) switch style { case .top: