From eaaa1fe260965bae81bfd72236865ad544f618fd Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sun, 15 May 2022 20:50:01 +0200 Subject: [PATCH] Move device checks to Theme Drop unused code along the way. --- Passepartout/App/Constants/Theme.swift | 31 +++++++++++++------ .../App/Views/OrganizerView+Profiles.swift | 5 +-- .../App/Views/OrganizerView+Scene.swift | 7 +---- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Passepartout/App/Constants/Theme.swift b/Passepartout/App/Constants/Theme.swift index aca67365..1e6f1df0 100644 --- a/Passepartout/App/Constants/Theme.swift +++ b/Passepartout/App/Constants/Theme.swift @@ -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 diff --git a/Passepartout/App/Views/OrganizerView+Profiles.swift b/Passepartout/App/Views/OrganizerView+Profiles.swift index 8023dda3..e7d7a8ae 100644 --- a/Passepartout/App/Views/OrganizerView+Profiles.swift +++ b/Passepartout/App/Views/OrganizerView+Profiles.swift @@ -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: { diff --git a/Passepartout/App/Views/OrganizerView+Scene.swift b/Passepartout/App/Views/OrganizerView+Scene.swift index cb98e81b..5016c5ac 100644 --- a/Passepartout/App/Views/OrganizerView+Scene.swift +++ b/Passepartout/App/Views/OrganizerView+Scene.swift @@ -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 - } } }