Skip to content

Commit

Permalink
Merge pull request #720 from Infomaniak/refactor-panels
Browse files Browse the repository at this point in the history
refactor: Use native panels
  • Loading branch information
Ambrdctr committed May 3, 2023
2 parents 6130c44 + 9e8557d commit 5e93ed7
Show file tree
Hide file tree
Showing 36 changed files with 725 additions and 734 deletions.
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

0 comments on commit 5e93ed7

Please sign in to comment.