forked from aheze/Setting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingEnvironment.swift
More file actions
88 lines (74 loc) · 2.28 KB
/
SettingEnvironment.swift
File metadata and controls
88 lines (74 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// SettingEnvironment.swift
// Setting
//
// Created by A. Zheng (github.com/aheze) on 4/28/23.
// Copyright © 2023 A. Zheng. All rights reserved.
//
import SwiftUI
private struct EdgePaddingKey: EnvironmentKey {
static let defaultValue = CGFloat(20)
}
private struct PrimaryColorKey: EnvironmentKey {
static let defaultValue = Color.primary
}
private struct SecondaryColorKey: EnvironmentKey {
static let defaultValue = Color.secondary
}
private struct AccentColorKey: EnvironmentKey {
static let defaultValue = Color.accentColor
}
private struct BackgroundColorKey: EnvironmentKey {
static let defaultValue: Color = {
#if os(iOS)
return Color(uiColor: .systemGroupedBackground)
#elseif os(visionOS)
return Color.clear
#else
return Color(nsColor: .windowBackgroundColor)
#endif
}()
}
private struct SecondaryBackgroundColorKey: EnvironmentKey {
static let defaultValue: Color = {
#if os(iOS)
return Color(uiColor: .secondarySystemGroupedBackground)
#elseif os(visionOS)
return Color.clear
#else
return Color(nsColor: .textBackgroundColor)
#endif
}()
}
public extension EnvironmentValues {
/// Padding to line up with the navigation title.
var edgePadding: CGFloat {
get { self[EdgePaddingKey.self] }
set { self[EdgePaddingKey.self] = newValue }
}
/// For text.
var settingPrimaryColor: Color {
get { self[PrimaryColorKey.self] }
set { self[PrimaryColorKey.self] = newValue }
}
/// For secondary labels.
var settingSecondaryColor: Color {
get { self[SecondaryColorKey.self] }
set { self[SecondaryColorKey.self] = newValue }
}
/// For buttons.
var settingAccentColor: Color {
get { self[AccentColorKey.self] }
set { self[AccentColorKey.self] = newValue }
}
/// For outer views.
var settingBackgroundColor: Color {
get { self[BackgroundColorKey.self] }
set { self[BackgroundColorKey.self] = newValue }
}
/// For inner views.
var settingSecondaryBackgroundColor: Color {
get { self[SecondaryBackgroundColorKey.self] }
set { self[SecondaryBackgroundColorKey.self] = newValue }
}
}