Skip to content

Commit

Permalink
Merge pull request #1178 from TortugaPower/fix-ipados18-crash
Browse files Browse the repository at this point in the history
Fix crash for iPads running iPadOS 18
  • Loading branch information
GianniCarlo authored Sep 11, 2024
2 parents 53fc558 + 7e6f44c commit 089e1e8
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion BookPlayer/AppTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ class AppTabBarController: UITabBarController {

private var disposeBag = Set<AnyCancellable>()
private var themedStatusBarStyle: UIStatusBarStyle?
/// iPadOS 18 moves the regular tab bar to the navigation bar
private let regularOffset: CGFloat = -24
private var compactOffset: CGFloat {
-tabBar.bounds.size.height + self.view.safeAreaInsets.bottom
}
private lazy var viewBottomConstraint = self.miniPlayer.bottomAnchor.constraint(
equalTo: view.safeAreaLayoutGuide.bottomAnchor,
constant: compactOffset
)
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
if UserDefaults.standard.object(forKey: Constants.UserDefaults.orientationLock) != nil,
let orientation = UIDeviceOrientation(rawValue: UserDefaults.standard.integer(forKey: Constants.UserDefaults.orientationLock)) {
Expand Down Expand Up @@ -49,6 +58,14 @@ class AppTabBarController: UITabBarController {
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

if #available(iOS 18.0, *),
UIDevice.current.userInterfaceIdiom == .pad,
traitCollection.horizontalSizeClass != .compact {
viewBottomConstraint.constant = regularOffset
} else {
viewBottomConstraint.constant = compactOffset
}

guard self.traitCollection.userInterfaceStyle != .unspecified else { return }

ThemeManager.shared.checkSystemMode()
Expand All @@ -72,8 +89,21 @@ class AppTabBarController: UITabBarController {
self.miniPlayer.heightAnchor.constraint(equalToConstant: 88),
self.miniPlayer.leftAnchor.constraint(equalTo: view.leftAnchor),
self.miniPlayer.rightAnchor.constraint(equalTo: view.rightAnchor),
self.miniPlayer.bottomAnchor.constraint(equalTo: tabBar.topAnchor)
viewBottomConstraint,
])

guard
#available(iOS 18.0, *),
UIDevice.current.userInterfaceIdiom == .pad
else {
return
}

if traitCollection.horizontalSizeClass == .compact {
viewBottomConstraint.constant = compactOffset
} else {
viewBottomConstraint.constant = regularOffset
}
}

func bindObservers() {
Expand Down

0 comments on commit 089e1e8

Please sign in to comment.