Move device checks to Theme

Drop unused code along the way.
This commit is contained in:
Davide De Rosa 2022-05-15 20:50:01 +02:00
parent d558edf665
commit eaaa1fe260
3 changed files with 25 additions and 18 deletions

View File

@ -26,20 +26,31 @@
import SwiftUI
import PassepartoutCore
extension Color {
init(red: Double, green: Double, blue: Double, brightness: Double) {
self.init(
red: red * brightness,
green: green * brightness,
blue: blue * brightness
)
}
}
extension View {
var themeIdiom: UIUserInterfaceIdiom {
UIDevice.current.userInterfaceIdiom
}
var themeIsiPad: Bool {
#if targetEnvironment(macCatalyst)
false
#else
UIDevice.current.userInterfaceIdiom == .pad
#endif
}
var themeIsiPadPortrait: Bool {
#if targetEnvironment(macCatalyst)
false
#else
let device: UIDevice = .current
return device.userInterfaceIdiom == .pad && device.orientation.isPortrait
#endif
}
var themeIsMultitasking: Bool {
UIDevice.current.isMultitaskingSupported
}
}
// MARK: Global

View File

@ -58,8 +58,9 @@ extension OrganizerView {
private var mainView: some View {
List {
if profileManager.hasProfiles {
if #available(iOS 15, *), themeIdiom == .pad {
// FIXME: iPad multitasking, navigation binding does not clear on pop without Section
// FIXME: iPad multitasking, navigation binding does not clear on pop without Section
if themeIsiPad && themeIsMultitasking {
Section {
profilesView
} header: {

View File

@ -78,7 +78,7 @@ extension OrganizerView {
return
}
isFirstLaunch = false
if !isiPadPortrait, let activeProfileId = profileManager.activeProfileId {
if !themeIsiPadPortrait, let activeProfileId = profileManager.activeProfileId {
profileManager.currentProfileId = activeProfileId
}
}
@ -103,10 +103,5 @@ extension OrganizerView {
private func persist() {
profileManager.persist()
}
private var isiPadPortrait: Bool {
let device: UIDevice = .current
return device.userInterfaceIdiom == .pad && device.orientation.isPortrait
}
}
}