Skip to content

Commit

Permalink
#534 Fix warnings?
Browse files Browse the repository at this point in the history
  • Loading branch information
wtmoose committed Dec 3, 2023
1 parent 62e12e1 commit 95f65d5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 69 deletions.
10 changes: 5 additions & 5 deletions SwiftMessages/BaseView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

/*
Expand Down Expand Up @@ -334,11 +339,6 @@ extension BaseView {
// Update the layer's `shadowPath` without animation
layer.shadowPath = shadowPath }
}

open override func layoutSubviews() {
super.layoutSubviews()
updateShadowPath()
}
}

/*
Expand Down
21 changes: 2 additions & 19 deletions SwiftMessages/MarginAdjustable+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions SwiftMessages/PhysicsAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
65 changes: 26 additions & 39 deletions SwiftMessages/Presenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions SwiftMessages/TopBottomAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 95f65d5

Please sign in to comment.