diff --git a/Mail/Views/Menu Drawer/Folders/FolderCell.swift b/Mail/Views/Menu Drawer/Folders/FolderCell.swift index 178248a78..17eb64031 100644 --- a/Mail/Views/Menu Drawer/Folders/FolderCell.swift +++ b/Mail/Views/Menu Drawer/Folders/FolderCell.swift @@ -23,16 +23,11 @@ import MailCore import MailCoreUI import MailResources import SwiftUI - -struct FolderCellTypeEnvironment: EnvironmentKey { - static var defaultValue = FolderCell.CellType.menuDrawer -} +import SwiftUIMacros extension EnvironmentValues { - var folderCellType: FolderCell.CellType { - get { self[FolderCellTypeEnvironment.self] } - set { self[FolderCellTypeEnvironment.self] = newValue } - } + @EnvironmentValue + var folderCellType = FolderCell.CellType.menuDrawer } struct FolderCell: View { diff --git a/Mail/Views/Menu Drawer/MailboxManagement/MailboxCell.swift b/Mail/Views/Menu Drawer/MailboxManagement/MailboxCell.swift index 768c7d4ed..55abc8786 100644 --- a/Mail/Views/Menu Drawer/MailboxManagement/MailboxCell.swift +++ b/Mail/Views/Menu Drawer/MailboxManagement/MailboxCell.swift @@ -24,16 +24,11 @@ import MailCoreUI import MailResources import SwiftModalPresentation import SwiftUI - -struct MailboxCellStyleKey: EnvironmentKey { - static var defaultValue = MailboxCell.Style.menuDrawer -} +import SwiftUIMacros extension EnvironmentValues { - var mailboxCellStyle: MailboxCell.Style { - get { self[MailboxCellStyleKey.self] } - set { self[MailboxCellStyleKey.self] = newValue } - } + @EnvironmentValue + var mailboxCellStyle = MailboxCell.Style.menuDrawer } extension View { diff --git a/MailCoreUI/Components/Buttons/IKButton/View+IKButtonEnvironment.swift b/MailCoreUI/Components/Buttons/IKButton/View+IKButtonEnvironment.swift index 4f482d3b1..cf1c2cd80 100644 --- a/MailCoreUI/Components/Buttons/IKButton/View+IKButtonEnvironment.swift +++ b/MailCoreUI/Components/Buttons/IKButton/View+IKButtonEnvironment.swift @@ -17,47 +17,16 @@ */ import SwiftUI - -// MARK: - EnvironmentKey - -struct IKButtonPrimaryStyleKey: EnvironmentKey { - static var defaultValue: any ShapeStyle = TintShapeStyle.tint -} - -struct IKButtonSecondaryStyleKey: EnvironmentKey { - static var defaultValue: any ShapeStyle = UserDefaults.shared.accentColor.onAccent.swiftUIColor -} - -struct IKButtonFullWidthKey: EnvironmentKey { - static var defaultValue = false -} - -struct IKButtonLoadingKey: EnvironmentKey { - static var defaultValue = false -} +import SwiftUIMacros // MARK: - EnvironmentValues -public extension EnvironmentValues { - var ikButtonPrimaryStyle: any ShapeStyle { - get { self[IKButtonPrimaryStyleKey.self] } - set { self[IKButtonPrimaryStyleKey.self] = newValue } - } - - var ikButtonSecondaryStyle: any ShapeStyle { - get { self[IKButtonSecondaryStyleKey.self] } - set { self[IKButtonSecondaryStyleKey.self] = newValue } - } - - var ikButtonFullWidth: Bool { - get { self[IKButtonFullWidthKey.self] } - set { self[IKButtonFullWidthKey.self] = newValue } - } - - var ikButtonLoading: Bool { - get { self[IKButtonLoadingKey.self] } - set { self[IKButtonLoadingKey.self] = newValue } - } +@EnvironmentStorage +extension EnvironmentValues { + var ikButtonPrimaryStyle: any ShapeStyle = TintShapeStyle.tint + var ikButtonSecondaryStyle: any ShapeStyle = UserDefaults.shared.accentColor.onAccent.swiftUIColor + var ikButtonFullWidth = false + var ikButtonLoading = false } // MARK: - View functions diff --git a/MailCoreUI/Extensions/Environment+Extension.swift b/MailCoreUI/Extensions/Environment+Extension.swift index ab1dc4904..706deec02 100644 --- a/MailCoreUI/Extensions/Environment+Extension.swift +++ b/MailCoreUI/Extensions/Environment+Extension.swift @@ -18,14 +18,9 @@ import Foundation import SwiftUI - -public struct CompactWindowKey: EnvironmentKey { - public static let defaultValue = true -} +import SwiftUIMacros public extension EnvironmentValues { - var isCompactWindow: CompactWindowKey.Value { - get { return self[CompactWindowKey.self] } - set { self[CompactWindowKey.self] = newValue } - } + @EnvironmentValue + var isCompactWindow = true } diff --git a/MailCoreUI/ViewModifier/SheetViewModifier.swift b/MailCoreUI/ViewModifier/SheetViewModifier.swift index a9e7ecea9..3a63adf59 100644 --- a/MailCoreUI/ViewModifier/SheetViewModifier.swift +++ b/MailCoreUI/ViewModifier/SheetViewModifier.swift @@ -19,22 +19,13 @@ import MailCore import MailResources import SwiftUI +import SwiftUIMacros public typealias DismissModalAction = () -> Void -public struct DismissModalKey: EnvironmentKey { - public static let defaultValue: DismissModalAction = { /* dismiss nothing by default */ } -} - public extension EnvironmentValues { - var dismissModal: DismissModalAction { - get { - return self[DismissModalKey.self] - } - set { - self[DismissModalKey.self] = newValue - } - } + @EnvironmentValue + var dismissModal: DismissModalAction = { /* dismiss nothing by default */ } } public extension View { diff --git a/Package.resolved b/Package.resolved index 6b9b0f844..82b5f4752 100644 --- a/Package.resolved +++ b/Package.resolved @@ -269,6 +269,15 @@ "version" : "1.0.2" } }, + { + "identity" : "swift-syntax", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-syntax", + "state" : { + "revision" : "64889f0c732f210a935a0ad7cda38f77f876262d", + "version" : "509.1.1" + } + }, { "identity" : "swiftbackports", "kind" : "remoteSourceControl", @@ -314,6 +323,15 @@ "version" : "1.1.3" } }, + { + "identity" : "swiftui-macros", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Wouter01/SwiftUI-Macros.git", + "state" : { + "revision" : "1c544d53727267a7a3e8b4a6728cf2dc88341e0e", + "version" : "1.1.0" + } + }, { "identity" : "swiftui-shimmer", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index 208f56a6a..0f115419b 100644 --- a/Package.swift +++ b/Package.swift @@ -31,6 +31,7 @@ let package = Package( .package(url: "https://github.com/johnpatrickmorgan/NavigationBackport", .upToNextMajor(from: "0.8.1")), .package(url: "https://github.com/aheze/Popovers", .upToNextMajor(from: "1.3.2")), .package(url: "https://github.com/shaps80/SwiftUIBackports", .upToNextMajor(from: "1.15.1")), - .package(url: "https://github.com/httpswift/swifter", .upToNextMajor(from: "1.5.0")) + .package(url: "https://github.com/httpswift/swifter", .upToNextMajor(from: "1.5.0")), + .package(url: "https://github.com/Wouter01/SwiftUI-Macros.git", .upToNextMajor(from: "1.0.0")) ] ) diff --git a/Project.swift b/Project.swift index b79c3da08..68deee636 100644 --- a/Project.swift +++ b/Project.swift @@ -203,7 +203,8 @@ let project = Project(name: "Mail", .external(name: "Lottie"), .external(name: "NavigationBackport"), .external(name: "Popovers"), - .external(name: "SwiftUIBackports") + .external(name: "SwiftUIBackports"), + .external(name: "SwiftUIMacros") ], settings: .settings(base: Constants.baseSettings)) ],