Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use native panels #720

Merged
merged 32 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c6b09c6
feat: Use presentationDetents for panels on iOS 16
PhilippeWeidmann Apr 26, 2023
3d30413
feat: Backport panel to iOS 15
PhilippeWeidmann Apr 26, 2023
240f06d
feat: ContactActionsView native panel
PhilippeWeidmann Apr 26, 2023
303b2da
feat: ReplyActionsView native panel
PhilippeWeidmann Apr 26, 2023
44b1719
Merge branch 'master' into refactor-panels
PhilippeWeidmann Apr 27, 2023
aca3c65
feat: ActionsPanelViewModifier
PhilippeWeidmann Apr 27, 2023
1c49cd5
refactor: Remove FloatingPanel lib related code
PhilippeWeidmann Apr 27, 2023
046f9ed
refactor(ActionsView): Reply - Use binding instead of closure
PhilippeWeidmann Apr 27, 2023
ca9e27c
refactor: ReportJunkView native floatingPanel
PhilippeWeidmann Apr 27, 2023
504f1d8
refactor: Remove GlobalBottomSheet
PhilippeWeidmann Apr 27, 2023
0c38d2a
refactor: ReportJunkView native model
PhilippeWeidmann Apr 27, 2023
341dc27
refactor: Reconnect ReportDisplayProblemView to panel
PhilippeWeidmann Apr 27, 2023
5747102
refactor: Remove useless code -> DisplayedFloatingPanelState
PhilippeWeidmann Apr 27, 2023
e091050
refactor: Move mailNavigationPath to NavigationStore
PhilippeWeidmann Apr 27, 2023
f5fafd7
fix: Use StateObject instead of ObservedObject
PhilippeWeidmann Apr 28, 2023
d63bee2
fix: Use Dispatch reportDisplayProblem
PhilippeWeidmann May 1, 2023
26d4251
feat: Display popover instead of panel on large size
PhilippeWeidmann May 2, 2023
12a3562
feat: AdaptivePanelViewModifier for message reply
PhilippeWeidmann May 2, 2023
0fe8380
feat: AdaptivePanelViewModifier for contacts
PhilippeWeidmann May 2, 2023
1e74fa4
feat: Add isCompactWindow to present popover or panel accordingly
PhilippeWeidmann May 2, 2023
ef7dfe9
feat: AdaptiveActionsViewModifier for swipe actions
PhilippeWeidmann May 2, 2023
8f7be06
refactor: Fix properties order
PhilippeWeidmann May 2, 2023
a782ce5
refactor: Prevent duplicated code in popover
PhilippeWeidmann May 2, 2023
443dfd7
fix(ThreadListSwipeAction): Re-add preview
PhilippeWeidmann May 2, 2023
fe3fa71
refactor: Remove useless MoveSheet
PhilippeWeidmann May 2, 2023
d81e1a9
feat: MoveEmailView without sheetstate
PhilippeWeidmann May 2, 2023
7639572
fix: Disable multiselection after selecting action
PhilippeWeidmann May 3, 2023
fe3a2e3
fix(MoveEmailView): Close sheet without waiting for task completion
PhilippeWeidmann May 3, 2023
1287d77
refactor(SheetView): This is now a SheetViewModifier
PhilippeWeidmann May 3, 2023
9b603f1
fix(ActionsViewModel): Also dispatch moveAction
PhilippeWeidmann May 3, 2023
4ccb110
Merge branch 'master' into refactor-panels
PhilippeWeidmann May 3, 2023
9e8557d
refactor: Prevent move duplication
PhilippeWeidmann May 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions .package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@
"version" : "3.8.0"
}
},
{
"identity" : "floatingpanel",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SCENEE/FloatingPanel",
"state" : {
"revision" : "2a29cb5b3ecf4beb67cf524a030dd74a11b956c4",
"version" : "2.6.1"
}
},
{
"identity" : "ios-bug-tracker",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -224,6 +215,15 @@
"version" : "1.5.2"
}
},
{
"identity" : "swiftbackports",
"kind" : "remoteSourceControl",
"location" : "https://github.com/shaps80/SwiftBackports",
"state" : {
"revision" : "fafbeabf78b7e364abbbb7565cdfeee42af16211",
"version" : "1.0.2"
}
},
{
"identity" : "swiftregex",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -260,6 +260,15 @@
"version" : "1.3.0"
}
},
{
"identity" : "swiftuibackports",
"kind" : "remoteSourceControl",
"location" : "https://github.com/shaps80/SwiftUIBackports",
"state" : {
"revision" : "556d42f391b74059a354b81b8c8e19cc7cb576f4",
"version" : "1.15.1"
}
},
{
"identity" : "wrappinghstack",
"kind" : "remoteSourceControl",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,33 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import CocoaLumberjackSwift
import MailCore
import MailResources
import SwiftUI

struct SheetView<Content>: View where Content: View {
@Environment(\.dismiss) private var dismiss
struct ActionsPanelButton<Content: View>: View {
@Environment(\.isCompactWindow) private var isCompactWindow

@ViewBuilder let content: Content
@State private var actionsTarget: ActionsTarget?

var body: some View {
NavigationView {
content
.navigationBarItems(leading: Button {
dismiss()
} label: {
Label(MailResourcesStrings.Localizable.buttonClose, systemImage: "xmark")
})
}
.onReceive(NotificationCenter.default.publisher(for: Constants.dismissMoveSheetNotificationName)) { _ in
dismiss()
}
}
}
var message: Message?
var threads: [Thread]?
var isMultiSelectionEnabled = false
@ViewBuilder var label: () -> Content

struct SheetView_Previews: PreviewProvider {
static var previews: some View {
SheetView {
EmptyView()
var body: some View {
Button {
if let message {
actionsTarget = .message(message)
} else if let threads {
actionsTarget = .threads(threads, isMultiSelectionEnabled)
} else {
DDLogWarn("MoreButton has no action target, did you forget to set message or threads ?")
}
} label: {
label()
}
.actionsPanel(actionsTarget: $actionsTarget)
}
}
29 changes: 16 additions & 13 deletions Mail/Components/ToolbarButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,31 @@ import MailCore
import MailResources
import SwiftUI

struct ToolbarButton: View {
struct ToolbarButtonLabel: View {
@Environment(\.verticalSizeClass) private var sizeClass

let text: String
let icon: Image
let action: () -> Void

init(text: String, icon: Image, action: @escaping () -> Void) {
self.text = text
self.icon = icon
self.action = action
var body: some View {
Label {
Text(text)
.textStyle(MailTextStyle.labelMediumAccent)
} icon: {
icon
}
.dynamicLabelStyle(sizeClass: sizeClass ?? .regular)
}
}

struct ToolbarButton: View {
let text: String
let icon: Image
let action: () -> Void

var body: some View {
Button(action: action) {
Label {
Text(text)
.textStyle(MailTextStyle.labelMediumAccent)
} icon: {
icon
}
.dynamicLabelStyle(sizeClass: sizeClass ?? .regular)
ToolbarButtonLabel(text: text, icon: icon)
}
.frame(maxWidth: .infinity)
}
Expand Down
1 change: 0 additions & 1 deletion Mail/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate, AccountManagerDelegate
let view = view.environment(\.window, window)
// Set root view controller
let hostingController = UIHostingController(rootView: view)
FloatingPanelHelper.shared.attachToViewController(hostingController)
setRootViewController(hostingController)
}

Expand Down
47 changes: 47 additions & 0 deletions Mail/Utils/AdaptivePanelViewModifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
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 adaptivePanel<Item: Identifiable, Content: View>(item: Binding<Item?>,
@ViewBuilder content: @escaping (Item) -> Content) -> some View {
return modifier(AdaptivePanelViewModifier(item: item, panelContent: content))
}
}

struct AdaptivePanelViewModifier<Item: Identifiable, PanelContent: View>: ViewModifier {
@Environment(\.isCompactWindow) private var isCompactWindow

@Binding var item: Item?
@ViewBuilder var panelContent: (Item) -> PanelContent

func body(content: Content) -> some View {
if isCompactWindow {
content.floatingPanel(item: $item) { item in
panelContent(item)
}
} else {
content.popover(item: $item) { item in
panelContent(item)
.padding()
.frame(idealWidth: 400)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,14 @@ public extension EnvironmentValues {
set { self[WindowKey.self] = newValue }
}
}

public struct CompactWindowKey: EnvironmentKey {
public static let defaultValue = true
}

public extension EnvironmentValues {
var isCompactWindow: CompactWindowKey.Value {
get { return self[CompactWindowKey.self] }
set { self[CompactWindowKey.self] = newValue }
}
}
Loading