Skip to content

Commit

Permalink
Merge pull request #1192 from Infomaniak/fix-compose-rotation
Browse files Browse the repository at this point in the history
fix: Prevent closing ComposeView on rotation
  • Loading branch information
valentinperignon committed Dec 22, 2023
2 parents 8677b21 + 5fb5852 commit affa8f5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions Mail/MailApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct MailApp: App {
var body: some Scene {
WindowGroup {
RootView()
.detectCompactWindow()
.environmentObject(navigationState)
.environmentObject(reviewManager)
.onAppear {
Expand Down
4 changes: 0 additions & 4 deletions Mail/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -43,6 +40,5 @@ struct RootView: View {
PreloadingView(currentAccount: currentAccount)
}
}
.environment(\.isCompactWindow, horizontalSizeClass == .compact || verticalSizeClass == .compact)
}
}
36 changes: 36 additions & 0 deletions Mail/Views/CompactWindowDetectorModifier.swift
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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)
}
}

0 comments on commit affa8f5

Please sign in to comment.