Skip to content

Add support for installing the lib on older OS versions #28

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions Introspect/AppKitIntrospectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SwiftUI
import AppKit

/// Introspection NSView that is inserted alongside the target view.
@available(macOS 15.0, *)
public class IntrospectionNSView: NSView {

required init() {
Expand All @@ -22,6 +23,7 @@ public class IntrospectionNSView: NSView {

/// Introspection View that is injected into the UIKit hierarchy alongside the target view.
/// After `updateNSView` is called, it calls `selector` to find the target view, then `customize` when the target view is found.
@available(macOS 15.0, *)
public struct AppKitIntrospectionView<TargetViewType: NSView>: NSViewRepresentable {

/// Method that introspects the view hierarchy to find the target view.
Expand Down
2 changes: 1 addition & 1 deletion Introspect/Introspect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public enum Introspect {
}
}

enum TargetViewSelector {
public enum TargetViewSelector {
public static func sibling<TargetView: PlatformView>(from entry: PlatformView) -> TargetView? {
guard let viewHost = Introspect.findViewHost(from: entry) else {
return nil
Expand Down
2 changes: 2 additions & 0 deletions Introspect/UIKitIntrospectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import UIKit
import SwiftUI

/// Introspection UIView that is inserted alongside the target view.
@available(iOS 13.0, *)
public class IntrospectionUIView: UIView {

required init() {
Expand All @@ -19,6 +20,7 @@ public class IntrospectionUIView: UIView {

/// Introspection View that is injected into the UIKit hierarchy alongside the target view.
/// After `updateUIView` is called, it calls `selector` to find the target view, then `customize` when the target view is found.
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
public struct UIKitIntrospectionView<TargetViewType: UIView>: UIViewRepresentable {

/// Method that introspects the view hierarchy to find the target view.
Expand Down
2 changes: 2 additions & 0 deletions Introspect/UIKitIntrospectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SwiftUI
import UIKit

/// Introspection UIViewController that is inserted alongside the target view controller.
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
public class IntrospectionUIViewController: UIViewController {
required init() {
super.init(nibName: nil, bundle: nil)
Expand All @@ -16,6 +17,7 @@ public class IntrospectionUIViewController: UIViewController {
}

/// This is the same logic as IntrospectionView but for view controllers. Please see details above.
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
public struct UIKitIntrospectionViewController<TargetViewControllerType: UIViewController>: UIViewControllerRepresentable {

let selector: (IntrospectionUIViewController) -> TargetViewControllerType?
Expand Down
3 changes: 3 additions & 0 deletions Introspect/ViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import AppKit
import UIKit
#endif

@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
extension View {
public func inject<SomeView>(_ view: SomeView) -> some View where SomeView: View {
return overlay(view.frame(width: 0, height: 0))
}
}

#if canImport(UIKit)
@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
extension View {

/// Finds a `TargetView` from a `SwiftUI.View`
Expand Down Expand Up @@ -115,6 +117,7 @@ extension View {
#endif

#if canImport(AppKit) && !targetEnvironment(macCatalyst)
@available(macOS 15.0, *)
extension View {

/// Finds a `TargetView` from a `SwiftUI.View`
Expand Down
9 changes: 9 additions & 0 deletions IntrospectTests/AppKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import XCTest
import SwiftUI
@testable import Introspect

@available(macOS 15.0, *)
enum TestUtils {
static func present<ViewType: View>(view: ViewType) {

Expand All @@ -18,6 +19,7 @@ enum TestUtils {
}
}

@available(macOS 15.0, *)
private struct ListTestView: View {

let spy1: () -> Void
Expand All @@ -37,6 +39,7 @@ private struct ListTestView: View {
}
}

@available(macOS 15.0, *)
private struct ScrollTestView: View {

let spy1: () -> Void
Expand All @@ -60,6 +63,7 @@ private struct ScrollTestView: View {
}
}

@available(macOS 15.0, *)
private struct TextFieldTestView: View {
let spy: () -> Void
@State private var textFieldValue = ""
Expand All @@ -71,6 +75,7 @@ private struct TextFieldTestView: View {
}
}

@available(macOS 15.0, *)
private struct SliderTestView: View {
let spy: () -> Void
@State private var sliderValue = 0.0
Expand All @@ -82,6 +87,7 @@ private struct SliderTestView: View {
}
}

@available(macOS 15.0, *)
private struct StepperTestView: View {
let spy: () -> Void
var body: some View {
Expand All @@ -94,6 +100,7 @@ private struct StepperTestView: View {
}
}

@available(macOS 15.0, *)
private struct DatePickerTestView: View {
let spy: () -> Void
@State private var datePickerValue = Date()
Expand All @@ -107,6 +114,7 @@ private struct DatePickerTestView: View {
}
}

@available(macOS 15.0, *)
private struct SegmentedControlTestView: View {
@State private var pickerValue = 0
let spy: () -> Void
Expand All @@ -123,6 +131,7 @@ private struct SegmentedControlTestView: View {
}
}

@available(macOS 15.0, *)
class AppKitTests: XCTestCase {

func testList() {
Expand Down
15 changes: 15 additions & 0 deletions IntrospectTests/UIKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SwiftUI

@testable import Introspect

@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
enum TestUtils {
static func present<ViewType: View>(view: ViewType) {

Expand All @@ -27,6 +28,7 @@ enum TestUtils {
}
}

@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
private struct NavigationTestView: View {
let spy: () -> Void
var body: some View {
Expand All @@ -41,6 +43,7 @@ private struct NavigationTestView: View {
}
}

@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
private struct ViewControllerTestView: View {
let spy: () -> Void
var body: some View {
Expand All @@ -55,6 +58,7 @@ private struct ViewControllerTestView: View {
}
}

@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
private struct NavigationRootTestView: View {
let spy: () -> Void
var body: some View {
Expand All @@ -69,6 +73,7 @@ private struct NavigationRootTestView: View {
}
}

@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
private struct TabTestView: View {
@State private var selection = 0
let spy: () -> Void
Expand All @@ -83,6 +88,7 @@ private struct TabTestView: View {
}
}

@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
private struct TabRootTestView: View {
@State private var selection = 0
let spy: () -> Void
Expand All @@ -97,6 +103,7 @@ private struct TabRootTestView: View {
}
}

@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
private struct ListTestView: View {

let spy1: () -> Void
Expand All @@ -116,6 +123,7 @@ private struct ListTestView: View {
}
}

@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
private struct ScrollTestView: View {

let spy1: () -> Void
Expand All @@ -139,6 +147,7 @@ private struct ScrollTestView: View {
}
}

@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
private struct TextFieldTestView: View {
let spy: () -> Void
@State private var textFieldValue = ""
Expand All @@ -150,6 +159,7 @@ private struct TextFieldTestView: View {
}
}

@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
@available(tvOS, unavailable)
private struct ToggleTestView: View {
let spy: () -> Void
Expand All @@ -162,6 +172,7 @@ private struct ToggleTestView: View {
}
}

@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
@available(tvOS, unavailable)
private struct SliderTestView: View {
let spy: () -> Void
Expand All @@ -174,6 +185,7 @@ private struct SliderTestView: View {
}
}

@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
@available(tvOS, unavailable)
private struct StepperTestView: View {
let spy: () -> Void
Expand All @@ -187,6 +199,7 @@ private struct StepperTestView: View {
}
}

@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
@available(tvOS, unavailable)
private struct DatePickerTestView: View {
let spy: () -> Void
Expand All @@ -201,6 +214,7 @@ private struct DatePickerTestView: View {
}
}

@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
private struct SegmentedControlTestView: View {
@State private var pickerValue = 0
let spy: () -> Void
Expand All @@ -217,6 +231,7 @@ private struct SegmentedControlTestView: View {
}
}

@available(iOS 13.0, tvOS 13.0, macOS 15.0, *)
class UIKitTests: XCTestCase {
func testNavigation() {

Expand Down
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import PackageDescription
let package = Package(
name: "Introspect",
platforms: [
.macOS(.v10_15), .iOS(.v13), .tvOS(.v13)
.macOS(.v10_13),
.iOS(.v11),
.tvOS(.v11)
],
products: [
.library(
Expand Down