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

feat: Use Environment macros #1392

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 3 additions & 8 deletions Mail/Views/Menu Drawer/Folders/FolderCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 3 additions & 8 deletions Mail/Views/Menu Drawer/MailboxManagement/MailboxCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions MailCoreUI/Extensions/Environment+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 3 additions & 12 deletions MailCoreUI/ViewModifier/SheetViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
]
)
3 changes: 2 additions & 1 deletion Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
],
Expand Down
Loading