Skip to content

Commit

Permalink
Merge pull request #1082 from Infomaniak/discovery-ipad
Browse files Browse the repository at this point in the history
feat: Present DiscoveryView with discoveryPresenter
  • Loading branch information
Ambrdctr authored Oct 24, 2023
2 parents afa4e4c + 0cc0ac9 commit bc3a178
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 30 deletions.
27 changes: 0 additions & 27 deletions Mail/Views/AI Writer/AIPromptPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ extension View {
@ViewBuilder modalContent: @escaping () -> ModalContent) -> some View {
modifier(AIPromptPresenter(isPresented: isPresented, modalContent: modalContent))
}

func aiDiscoveryPresenter<ModalContent: View>(isPresented: Binding<Bool>,
@ViewBuilder modalContent: @escaping () -> ModalContent) -> some View {
modifier(AIDiscoveryPresenter(isPresented: isPresented, modalContent: modalContent))
}
}

struct AIPromptPresenter<ModalContent: View>: ViewModifier {
Expand All @@ -55,25 +50,3 @@ struct AIPromptPresenter<ModalContent: View>: ViewModifier {
}
}
}

struct AIDiscoveryPresenter<ModalContent: View>: ViewModifier {
@Environment(\.isCompactWindow) private var isCompactWindow

@Binding var isPresented: Bool

@ViewBuilder let modalContent: () -> ModalContent

func body(content: Content) -> some View {
content
.sheet(isPresented: Binding(get: { isCompactWindow && isPresented }, set: { isPresented = $0 })) {
if #available(iOS 16.0, *) {
modalContent().modifier(SelfSizingPanelViewModifier())
} else {
modalContent().modifier(SelfSizingPanelBackportViewModifier())
}
}
.customAlert(isPresented: Binding(get: { !isCompactWindow && isPresented }, set: { isPresented = $0 })) {
modalContent()
}
}
}
48 changes: 48 additions & 0 deletions Mail/Views/Bottom sheets/Discovery/DiscoveryPresenter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
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 SwiftUI

extension View {
func discoveryPresenter<ModalContent: View>(isPresented: Binding<Bool>,
@ViewBuilder modalContent: @escaping () -> ModalContent) -> some View {
modifier(DiscoveryPresenter(isPresented: isPresented, modalContent: modalContent))
}
}

struct DiscoveryPresenter<ModalContent: View>: ViewModifier {
@Environment(\.isCompactWindow) private var isCompactWindow

@Binding var isPresented: Bool

@ViewBuilder let modalContent: ModalContent

func body(content: Content) -> some View {
content
.sheet(isPresented: Binding(get: { isCompactWindow && isPresented }, set: { isPresented = $0 })) {
if #available(iOS 16.0, *) {
modalContent.modifier(SelfSizingPanelViewModifier())
} else {
modalContent.modifier(SelfSizingPanelBackportViewModifier())
}
}
.customAlert(isPresented: Binding(get: { !isCompactWindow && isPresented }, set: { isPresented = $0 })) {
modalContent
}
}
}
2 changes: 1 addition & 1 deletion Mail/Views/New Message/ComposeMessageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ struct ComposeMessageView: View {
dismissMessageView()
}
}
.aiDiscoveryPresenter(isPresented: $isShowingAIPopover) {
.discoveryPresenter(isPresented: $isShowingAIPopover) {
DiscoveryView(item: .aiDiscovery) {
UserDefaults.shared.shouldPresentAIFeature = false
} completionHandler: { willShowAIPrompt in
Expand Down
4 changes: 2 additions & 2 deletions Mail/Views/SplitView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ struct SplitView: View {
}
}
}
.floatingPanel(isPresented: $isShowingUpdateAvailable) {
.discoveryPresenter(isPresented: $isShowingUpdateAvailable) {
DiscoveryView(item: .updateDiscovery) { /* Empty on purpose */ } completionHandler: { update in
guard update else { return }
let url: URLConstants = Bundle.main.isRunningInTestFlight ? .testFlight : .appStore
openURL(url.url)
}
}
.floatingPanel(isPresented: $isShowingSyncDiscovery) {
.discoveryPresenter(isPresented: $isShowingSyncDiscovery) {
DiscoveryView(item: .syncDiscovery) {
UserDefaults.shared.shouldPresentSyncDiscovery = false
} completionHandler: { update in
Expand Down

0 comments on commit bc3a178

Please sign in to comment.