Skip to content

Commit

Permalink
Remove Toggle introspection on visionOS (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
davdroman authored Oct 4, 2023
1 parent 0f309ad commit 6ae6714
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 56 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Changelog

## master

- Removed: `Toggle` introspection on visionOS (#373)

## [1.0.0]

- Removed: obsoleted Introspect module (#275)
Expand Down
12 changes: 6 additions & 6 deletions Examples/Showcase/Showcase/AppView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,14 @@ struct SimpleElementsShowcase: View {
#endif
}

#if !os(tvOS)
#if !os(visionOS)
HStack {
Toggle("Toggle Red", isOn: $toggleValue)
#if os(iOS) || os(visionOS)
#if os(iOS)
.introspect(
.toggle,
on: .iOS(.v13, .v14, .v15, .v16, .v17), .visionOS(.v1)
on: .iOS(.v13, .v14, .v15, .v16, .v17)
) { toggle in
toggle.backgroundColor = .red
}
Expand All @@ -417,10 +419,10 @@ struct SimpleElementsShowcase: View {
#endif

Toggle("Toggle Green", isOn: $toggleValue)
#if os(iOS) || os(visionOS)
#if os(iOS)
.introspect(
.toggle,
on: .iOS(.v13, .v14, .v15, .v16, .v17), .visionOS(.v1)
on: .iOS(.v13, .v14, .v15, .v16, .v17)
) { toggle in
toggle.backgroundColor = .green
}
Expand All @@ -431,8 +433,6 @@ struct SimpleElementsShowcase: View {
#endif
}

#if !os(tvOS)
#if !os(visionOS)
HStack {
Slider(value: $sliderValue, in: 0...100)
#if os(iOS)
Expand Down
19 changes: 2 additions & 17 deletions Sources/ViewTypes/Toggle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,10 @@ import SwiftUI
///
/// ### visionOS
///
/// ```swift
/// struct ContentView: View {
/// @State var isOn = false
///
/// var body: some View {
/// Toggle("Toggle", isOn: $isOn)
/// .introspect(.toggle, on: .visionOS(.v1)) {
/// print(type(of: $0)) // UISwitch
/// }
/// }
/// }
/// ```
/// Not available.
public struct ToggleType: IntrospectableViewType {}

#if !os(tvOS)
#if !os(tvOS) && !os(visionOS)
extension IntrospectableViewType where Self == ToggleType {
public static var toggle: Self { .init() }
}
Expand All @@ -65,10 +54,6 @@ extension iOSViewVersion<ToggleType, UISwitch> {
public static let v16 = Self(for: .v16)
public static let v17 = Self(for: .v17)
}

extension visionOSViewVersion<ToggleType, UISwitch> {
public static let v1 = Self(for: .v1)
}
#elseif canImport(AppKit)
extension macOSViewVersion<ToggleType, NSButton> {
public static let v10_15 = Self(for: .v10_15)
Expand Down
20 changes: 2 additions & 18 deletions Sources/ViewTypes/ToggleWithSwitchStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,14 @@ import SwiftUI
///
/// ### visionOS
///
/// ```swift
/// struct ContentView: View {
/// @State var isOn = false
///
/// var body: some View {
/// Toggle("Switch", isOn: $isOn)
/// .toggleStyle(.switch)
/// .introspect(.toggle(style: .switch), on: .visionOS(.v1)) {
/// print(type(of: $0)) // UISwitch
/// }
/// }
/// }
/// ```
/// Not available.
public struct ToggleWithSwitchStyleType: IntrospectableViewType {
public enum Style {
case `switch`
}
}

#if !os(tvOS)
#if !os(tvOS) && !os(visionOS)
extension IntrospectableViewType where Self == ToggleWithSwitchStyleType {
public static func toggle(style: Self.Style) -> Self { .init() }
}
Expand All @@ -72,10 +60,6 @@ extension iOSViewVersion<ToggleWithSwitchStyleType, UISwitch> {
public static let v16 = Self(for: .v16)
public static let v17 = Self(for: .v17)
}

extension visionOSViewVersion<ToggleWithSwitchStyleType, UISwitch> {
public static let v1 = Self(for: .v1)
}
#elseif canImport(AppKit)
extension macOSViewVersion<ToggleWithSwitchStyleType, NSSwitch> {
public static let v10_15 = Self(for: .v10_15)
Expand Down
2 changes: 1 addition & 1 deletion Tests/Tests/TestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import XCTest

#if canImport(UIKit)
enum TestUtils {
#if targetEnvironment(macCatalyst)
#if targetEnvironment(macCatalyst) || os(visionOS)
static let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 480, height: 300))
#else
static let window = UIWindow(frame: UIScreen.main.bounds)
Expand Down
14 changes: 7 additions & 7 deletions Tests/Tests/ViewTypes/ToggleTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !os(tvOS)
#if !os(tvOS) && !os(visionOS)
import SwiftUI
import SwiftUIIntrospect
import XCTest
Expand All @@ -18,22 +18,22 @@ final class ToggleTests: XCTestCase {

VStack {
Toggle("", isOn: .constant(true))
#if os(iOS) || os(visionOS)
.introspect(.toggle, on: .iOS(.v13, .v14, .v15, .v16, .v17), .visionOS(.v1), customize: spy0)
#if os(iOS)
.introspect(.toggle, on: .iOS(.v13, .v14, .v15, .v16, .v17), customize: spy0)
#elseif os(macOS)
.introspect(.toggle, on: .macOS(.v10_15, .v11, .v12, .v13, .v14), customize: spy0)
#endif

Toggle("", isOn: .constant(false))
#if os(iOS) || os(visionOS)
.introspect(.toggle, on: .iOS(.v13, .v14, .v15, .v16, .v17), .visionOS(.v1), customize: spy1)
#if os(iOS)
.introspect(.toggle, on: .iOS(.v13, .v14, .v15, .v16, .v17), customize: spy1)
#elseif os(macOS)
.introspect(.toggle, on: .macOS(.v10_15, .v11, .v12, .v13, .v14), customize: spy1)
#endif

Toggle("", isOn: .constant(true))
#if os(iOS) || os(visionOS)
.introspect(.toggle, on: .iOS(.v13, .v14, .v15, .v16, .v17), .visionOS(.v1), customize: spy2)
#if os(iOS)
.introspect(.toggle, on: .iOS(.v13, .v14, .v15, .v16, .v17), customize: spy2)
#elseif os(macOS)
.introspect(.toggle, on: .macOS(.v10_15, .v11, .v12, .v13, .v14), customize: spy2)
#endif
Expand Down
14 changes: 7 additions & 7 deletions Tests/Tests/ViewTypes/ToggleWithSwitchStyleTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !os(tvOS)
#if !os(tvOS) && !os(visionOS)
import SwiftUI
import SwiftUIIntrospect
import XCTest
Expand All @@ -19,24 +19,24 @@ final class ToggleWithSwitchStyleTests: XCTestCase {
VStack {
Toggle("", isOn: .constant(true))
.toggleStyle(.switch)
#if os(iOS) || os(visionOS)
.introspect(.toggle(style: .switch), on: .iOS(.v13, .v14, .v15, .v16, .v17), .visionOS(.v1), customize: spy0)
#if os(iOS)
.introspect(.toggle(style: .switch), on: .iOS(.v13, .v14, .v15, .v16, .v17), customize: spy0)
#elseif os(macOS)
.introspect(.toggle(style: .switch), on: .macOS(.v10_15, .v11, .v12, .v13, .v14), customize: spy0)
#endif

Toggle("", isOn: .constant(false))
.toggleStyle(.switch)
#if os(iOS) || os(visionOS)
.introspect(.toggle(style: .switch), on: .iOS(.v13, .v14, .v15, .v16, .v17), .visionOS(.v1), customize: spy1)
#if os(iOS)
.introspect(.toggle(style: .switch), on: .iOS(.v13, .v14, .v15, .v16, .v17), customize: spy1)
#elseif os(macOS)
.introspect(.toggle(style: .switch), on: .macOS(.v10_15, .v11, .v12, .v13, .v14), customize: spy1)
#endif

Toggle("", isOn: .constant(true))
.toggleStyle(.switch)
#if os(iOS) || os(visionOS)
.introspect(.toggle(style: .switch), on: .iOS(.v13, .v14, .v15, .v16, .v17), .visionOS(.v1), customize: spy2)
#if os(iOS)
.introspect(.toggle(style: .switch), on: .iOS(.v13, .v14, .v15, .v16, .v17), customize: spy2)
#elseif os(macOS)
.introspect(.toggle(style: .switch), on: .macOS(.v10_15, .v11, .v12, .v13, .v14), customize: spy2)
#endif
Expand Down

0 comments on commit 6ae6714

Please sign in to comment.