Skip to content

Commit 8c6bf77

Browse files
committed
Fix Toggle compilation, add OS versions to Examples/Package.swift
1 parent d33184b commit 8c6bf77

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

Examples/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let exampleDependencies: [Target.Dependency] = [
1515

1616
let package = Package(
1717
name: "Examples",
18-
platforms: [.macOS(.v10_15)],
18+
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .macCatalyst(.v13)],
1919
dependencies: [
2020
.package(name: "swift-cross-ui", path: ".."),
2121
.package(

Package.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,17 @@ let package = Package(
146146
.target(
147147
name: "DefaultBackend",
148148
dependencies: [
149-
.target(name: defaultBackend, condition: .when(platforms: [.linux, .macOS, .windows])),
149+
.target(
150+
name: defaultBackend,
151+
condition: .when(platforms: [.linux, .macOS, .windows])
152+
),
150153
// Non-desktop platforms need to be handled separately:
151154
// Only one backend is supported, and `#if` won't work because it's evaluated
152155
// on the compiling desktop, not the target.
153-
.target(name: "UIKitBackend", condition: .when(platforms: [.iOS, .tvOS, .macCatalyst])),
156+
.target(
157+
name: "UIKitBackend",
158+
condition: .when(platforms: [.iOS, .tvOS, .macCatalyst])
159+
),
154160
]
155161
),
156162
.target(name: "AppKitBackend", dependencies: ["SwiftCrossUI"]),

Sources/SwiftCrossUI/Views/Toggle.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@ public struct Toggle: View {
22
@Environment(\.backend) var backend
33

44
/// The style of toggle shown.
5-
var selectedToggleStyle: ToggleStyle
5+
var selectedToggleStyle: ToggleStyle?
66
/// The label to be shown on or beside the toggle.
77
var label: String
88
/// Whether the toggle is active or not.
99
var active: Binding<Bool>
1010

1111
/// Creates a toggle that displays a custom label.
1212
public init(_ label: String, active: Binding<Bool>) {
13-
self.selectedToggleStyle = backend.defaultToggleStyle
1413
self.label = label
1514
self.active = active
1615
}
1716

1817
public var body: some View {
19-
switch selectedToggleStyle {
18+
switch selectedToggleStyle ?? backend.defaultToggleStyle {
2019
case .switch:
2120
HStack {
2221
Text(label)

0 commit comments

Comments
 (0)