-
Notifications
You must be signed in to change notification settings - Fork 147
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
Content extraction is decoupled from Inspectable
conformance
#216
Content extraction is decoupled from Inspectable
conformance
#216
Conversation
Inspectable
conformance
case .gesture: | ||
case _ as any Gesture: | ||
break | ||
default: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We add a default
case but we haven't made this code any less safe. Previously we would return nil
if content.view
did not conform to Inspectable
.
8d32d63
to
4bb9424
Compare
@@ -2,15 +2,15 @@ import SwiftUI | |||
|
|||
@available(iOS 13.0, macOS 10.15, tvOS 13.0, *) | |||
public protocol CustomViewType { | |||
associatedtype T: Inspectable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that environment injection is decoupled from InspectableProtocol
, we no longer need this requirement.
@@ -72,7 +72,7 @@ internal extension Content { | |||
@available(iOS 13.0, macOS 10.15, tvOS 13.0, *) | |||
public extension InspectableView where View: SingleViewContent { | |||
|
|||
func view<T>(_ type: T.Type) throws -> InspectableView<ViewType.View<T>> where T: Inspectable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was necessary because previously ViewType.View<T>
needed to conform to InspectableProtocol
though that requirement no longer exists.
af04454
to
961e0a6
Compare
var missingEnvironmentObjects: [String] { | ||
|
||
internal enum EnvironmentInjection { | ||
static func missingEnvironmentObjects(for entity: Any) -> [String] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to better names than entity
.
961e0a6
to
967bf30
Compare
967bf30
to
f5ddd47
Compare
f5ddd47
to
6b81693
Compare
@@ -7,38 +7,6 @@ public protocol Inspectable { | |||
func extractContent(environmentObjects: [AnyObject]) throws -> Any | |||
} | |||
|
|||
@available(iOS 13.0, macOS 10.15, tvOS 13.0, *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the Move code without changes
commit I consolidate the extraction code into a single file.
@@ -55,14 +55,16 @@ internal extension Content { | |||
|
|||
func extractCustomView() throws -> Content { | |||
let inspectable = try Inspector.cast(value: view, type: Inspectable.self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -126,21 +128,6 @@ public extension NSViewControllerRepresentable where Self: Inspectable { | |||
} | |||
} | |||
|
|||
@available(iOS 13.0, macOS 10.15, tvOS 13.0, *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These conformances are no longer necessary since we threw these errors in ContentExtractor
.
ViewInspector/Sources/ViewInspector/ContentExtraction.swift
Lines 41 to 70 in 47d11e6
private func validateSource() throws { | |
switch contentSource.source { | |
#if os(macOS) | |
case is any NSViewRepresentable: | |
throw InspectionError.notSupported( | |
"Please use `.actualView().nsView()` for inspecting the contents of NSViewRepresentable") | |
case is any NSViewControllerRepresentable: | |
throw InspectionError.notSupported( | |
"Please use `.actualView().viewController()` for inspecting the contents of NSViewControllerRepresentable") | |
#endif | |
#if os(iOS) || os(tvOS) | |
case is any UIViewRepresentable: | |
throw InspectionError.notSupported( | |
"Please use `.actualView().uiView()` for inspecting the contents of UIViewRepresentable") | |
case is any UIViewControllerRepresentable: | |
throw InspectionError.notSupported( | |
"Please use `.actualView().viewController()` for inspecting the contents of UIViewControllerRepresentable") | |
#endif | |
#if os(watchOS) | |
case is any WKInterfaceObjectRepresentable: | |
throw InspectionError.notSupported( | |
""" | |
Please use `.actualView().interfaceObject()` for inspecting \ | |
the contents of WKInterfaceObjectRepresentable | |
""") | |
#endif | |
default: | |
return | |
} | |
} |
@@ -1,4 +1,4 @@ | |||
// swift-tools-version:5.3 | |||
// swift-tools-version:5.7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to target Swift 5.7 to be able to access this functionality: https://github.com/apple/swift-evolution/blob/main/proposals/0309-unlock-existential-types-for-all-protocols.md
@nalexn I'm curious to see what you think of this PR. I'm very open to making revisions (e.g. adding tests, updating naming, restructuring). Lmk! |
That's an interesting take, @bachand I'll try to find some time this week to review & complete your solution! |
I've continued the process of de-Inspectable-fication in this branch. Haven't reviewed the original code in the PR yet, just continued building on top of it. There is no doubt this PR will be a huge milestone for the library, yet, there is quite some work left to make |
I checked out the branch. I see you added a protocol called
👍
Agreed. I felt this as well as I tried to push further when I was working on this PR.
Makes sense. Keep me in the loop about how I can be helpful! |
The library was using Since we've removed a distinctive mark from custom views, this now had to be added to standard views, thus SwiftUICitizen mark. I was also hoping to use this for maintaining the |
Thanks @nalexn for finishing the work and for publishing the 0.9.3 release 🙏 |
This PR is easiest to review commit by commit.
Changes
This PR follows my investigation in #213 which followed my question (#203) about the purpose of the
Inspectable
protocol.With this PR,
Inspectable
is now a "marker" protocol with no requirements. Swift 5.7 introduces new functionality that enables us to callbody
on protocols likeView
that have an associated type. The lack of this functionality was a reason why it was necessary for views to conform toInspectable
in order to be inspected.The public API of ViewInspector remains the same after this PR. My goal is to eliminate the need for views to conform to
Inspectable
in order to be inspected.Testing
I am developing using Xcode 14.1 on macOS 13.1. My Mac has an M1 processor. When I open the Package.swift and run the tests (Cmd + u) for my Mac I see 4 failing tests on HEAD of the master branch.
I cannot run the full test suite for iOS. I've filed an issue #217.
Reviewers
@nalexn