File tree Expand file tree Collapse file tree 9 files changed +30
-21
lines changed Expand file tree Collapse file tree 9 files changed +30
-21
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,6 @@ public final class AppKitBackend: AppBackend {
20
20
public let defaultTableCellVerticalPadding = 4
21
21
public let defaultPaddingAmount = 10
22
22
public let requiresToggleSwitchSpacer = false
23
- public let defaultToggleStyle = ToggleStyle . button
24
23
public let requiresImageUpdateOnScaleFactorChange = false
25
24
public let menuImplementationStyle = MenuImplementationStyle . dynamicPopover
26
25
public let canRevealFiles = true
Original file line number Diff line number Diff line change @@ -33,7 +33,6 @@ public final class Gtk3Backend: AppBackend {
33
33
public let defaultPaddingAmount = 10
34
34
public let requiresToggleSwitchSpacer = false
35
35
public let scrollBarWidth = 0
36
- public let defaultToggleStyle = ToggleStyle . button
37
36
public let requiresImageUpdateOnScaleFactorChange = true
38
37
public let menuImplementationStyle = MenuImplementationStyle . dynamicPopover
39
38
public let canRevealFiles = true
Original file line number Diff line number Diff line change @@ -32,7 +32,6 @@ public final class GtkBackend: AppBackend {
32
32
public let defaultPaddingAmount = 10
33
33
public let scrollBarWidth = 0
34
34
public let requiresToggleSwitchSpacer = false
35
- public let defaultToggleStyle = ToggleStyle . button
36
35
public let requiresImageUpdateOnScaleFactorChange = false
37
36
public let menuImplementationStyle = MenuImplementationStyle . dynamicPopover
38
37
public let canRevealFiles = true
Original file line number Diff line number Diff line change @@ -75,8 +75,6 @@ public protocol AppBackend {
75
75
var scrollBarWidth : Int { get }
76
76
/// If `true`, a toggle in the ``ToggleStyle/switch`` style grows to fill its parent container.
77
77
var requiresToggleSwitchSpacer : Bool { get }
78
- /// The default style for toggles.
79
- var defaultToggleStyle : ToggleStyle { get }
80
78
/// If `true`, all images in a window will get updated when the window's
81
79
/// scale factor changes (``EnvironmentValues/windowScaleFactor``).
82
80
///
Original file line number Diff line number Diff line change @@ -60,6 +60,9 @@ public struct EnvironmentValues {
60
60
/// The style of list to use.
61
61
package var listStyle : ListStyle
62
62
63
+ /// The style of toggle to use.
64
+ public var toggleStyle : ToggleStyle
65
+
63
66
// Backing storage for extensible subscript
64
67
private var extraValues : [ ObjectIdentifier : Any ]
65
68
@@ -163,6 +166,7 @@ public struct EnvironmentValues {
163
166
window = nil
164
167
extraValues = [ : ]
165
168
listStyle = . default
169
+ toggleStyle = . button
166
170
isEnabled = true
167
171
}
168
172
Original file line number Diff line number Diff line change
1
+ extension View {
2
+ /// Sets the style of the toggle.
3
+ public func toggleStyle( _ toggleStyle: ToggleStyle ) -> some View {
4
+ return EnvironmentModifier ( self ) { environment in
5
+ return environment. with ( \. toggleStyle, toggleStyle)
6
+ }
7
+ }
8
+ }
Original file line number Diff line number Diff line change
1
+ /// A control for toggling between two values (usually representing on and off).
1
2
public struct Toggle : View {
2
3
@Environment ( \. backend) var backend
4
+ @Environment ( \. toggleStyle) var toggleStyle
3
5
4
- /// The style of toggle shown.
5
- var selectedToggleStyle : ToggleStyle ?
6
6
/// The label to be shown on or beside the toggle.
7
7
var label : String
8
8
/// Whether the toggle is active or not.
@@ -15,7 +15,7 @@ public struct Toggle: View {
15
15
}
16
16
17
17
public var body : some View {
18
- switch selectedToggleStyle ?? backend . defaultToggleStyle {
18
+ switch toggleStyle . style {
19
19
case . switch:
20
20
HStack {
21
21
Text ( label)
@@ -32,16 +32,18 @@ public struct Toggle: View {
32
32
}
33
33
}
34
34
35
- extension Toggle {
36
- /// Sets the style of the toggle.
37
- public func toggleStyle( _ selectedToggleStyle: ToggleStyle ) -> Toggle {
38
- var toggle = self
39
- toggle. selectedToggleStyle = selectedToggleStyle
40
- return toggle
41
- }
42
- }
35
+ /// A style of toggle.
36
+ public struct ToggleStyle {
37
+ package var style : Style
43
38
44
- public enum ToggleStyle {
45
- case `switch`
46
- case button
39
+ /// A toggle switch.
40
+ public static let `switch` = Self ( style: . switch)
41
+ /// A toggle button. Generally looks like a regular button when off and an
42
+ /// accented button when on.
43
+ public static let button = Self ( style: . button)
44
+
45
+ package enum Style {
46
+ case `switch`
47
+ case button
48
+ }
47
49
}
Original file line number Diff line number Diff line change @@ -13,7 +13,6 @@ public final class UIKitBackend: AppBackend {
13
13
public let scrollBarWidth = 0
14
14
public let defaultPaddingAmount = 15
15
15
public let requiresToggleSwitchSpacer = true
16
- public let defaultToggleStyle = ToggleStyle . switch
17
16
public let menuImplementationStyle = MenuImplementationStyle . menuButton
18
17
19
18
// TODO: When tables are supported, update these
@@ -76,6 +75,8 @@ public final class UIKitBackend: AppBackend {
76
75
design: . default
77
76
)
78
77
78
+ environment. toggleStyle = . switch
79
+
79
80
switch UITraitCollection . current. userInterfaceStyle {
80
81
case . light:
81
82
environment. colorScheme = . light
Original file line number Diff line number Diff line change @@ -39,7 +39,6 @@ public final class WinUIBackend: AppBackend {
39
39
public let defaultTableCellVerticalPadding = 4
40
40
public let defaultPaddingAmount = 10
41
41
public let requiresToggleSwitchSpacer = false
42
- public let defaultToggleStyle = ToggleStyle . button
43
42
public let requiresImageUpdateOnScaleFactorChange = false
44
43
public let menuImplementationStyle = MenuImplementationStyle . dynamicPopover
45
44
public let canRevealFiles = false
You can’t perform that action at this time.
0 commit comments