From 5fb5852cd950a62511e73184c18dc9096fbaef4e Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Fri, 22 Dec 2023 12:44:40 +0100 Subject: [PATCH] fix: Prevent closing ComposeView on rotation --- Mail/MailApp.swift | 1 + Mail/RootView.swift | 4 --- .../Views/CompactWindowDetectorModifier.swift | 36 +++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 Mail/Views/CompactWindowDetectorModifier.swift diff --git a/Mail/MailApp.swift b/Mail/MailApp.swift index ad2c2ba42..3ca298cf0 100644 --- a/Mail/MailApp.swift +++ b/Mail/MailApp.swift @@ -54,6 +54,7 @@ struct MailApp: App { var body: some Scene { WindowGroup { RootView() + .detectCompactWindow() .environmentObject(navigationState) .environmentObject(reviewManager) .onAppear { diff --git a/Mail/RootView.swift b/Mail/RootView.swift index 36dfe84fa..acb47655f 100644 --- a/Mail/RootView.swift +++ b/Mail/RootView.swift @@ -20,9 +20,6 @@ import MailCore import SwiftUI struct RootView: View { - @Environment(\.horizontalSizeClass) private var horizontalSizeClass - @Environment(\.verticalSizeClass) private var verticalSizeClass - @EnvironmentObject private var navigationState: RootViewState var body: some View { @@ -43,6 +40,5 @@ struct RootView: View { PreloadingView(currentAccount: currentAccount) } } - .environment(\.isCompactWindow, horizontalSizeClass == .compact || verticalSizeClass == .compact) } } diff --git a/Mail/Views/CompactWindowDetectorModifier.swift b/Mail/Views/CompactWindowDetectorModifier.swift new file mode 100644 index 000000000..d73743493 --- /dev/null +++ b/Mail/Views/CompactWindowDetectorModifier.swift @@ -0,0 +1,36 @@ +/* + Infomaniak Mail - iOS App + Copyright (C) 2022 Infomaniak Network SA + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +import Foundation +import SwiftUI + +extension View { + func detectCompactWindow() -> some View { + modifier(CompactWindowDetectorModifier()) + } +} + +struct CompactWindowDetectorModifier: ViewModifier { + @Environment(\.horizontalSizeClass) private var horizontalSizeClass + @Environment(\.verticalSizeClass) private var verticalSizeClass + + func body(content: Content) -> some View { + content + .environment(\.isCompactWindow, horizontalSizeClass == .compact || verticalSizeClass == .compact) + } +}