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
Inspector emissary for view modifier #110
Inspector emissary for view modifier #110
Conversation
Note, I have tried searching for a second text string in the context of the async calls and have found none. As I said, I'm trying ascertain the difference between the |
At the first glance, I cannot grasp why this happens - really bizarre. I'm about to release a new version - wanted to include this PR as well, but it seems like it deserves further investigation and possibly a revisited approach - I'd ideally come to the |
Reference to the related discussion: #108 |
I have a thought and want to run it by you. The |
@nalexn: I think I solved the problem with dynamic inspection of view extensions. I having a working |
…itionally, fixed `on` method for view modifers.
Conflicts: Sources/ViewInspector/InspectionEmissary.swift
…or view modifiers.
@nalexn: Please review the changes I made to this PR. These changes fix the |
…to content of a custom view modifier.
…est has to extend the class to conform `InspectionEmissaryBase`.
@nalexn: Don't merge this yet. I'm having issues defining inspection emissaries in a way that doesn't require the runtime to import ViewInspector. |
…definition of an inspection emissary to conform to a inspection emissary protocol (i.e., `InspectionEmissary` or `InspectionEmissaryForViewModifer`).
The last commit resolves the problem I was experiencing. However, I had to eliminate |
Hey - reviewed the code - looks good and works great! The only concern is the requirement to refactor the ViewModifier to return a custom view. I thought a bit how can we eliminate the recursive So if we add this extension: extension ViewModifier {
func body() -> Any {
return body(content: _ViewModifier_Content<Self>())
}
} We'll be able to construct the Body at any moment we want, including when the ViewModifier is hosted on screen and ready for async inspection. That is, if we previously had struct InspectableTestModifier: ViewModifier, Inspectable {
var didAppear: ((Self.Body) -> Void)?
func body(content: Self.Content) -> some View {
HStack {
EmptyView()
content
.padding(.top, 15)
}
.onAppear { self.didAppear?(self.body(content: content)) }
}
} We can do instead struct InspectableTestModifier: ViewModifier, Inspectable {
var didAppear: ((Self) -> Void)?
func body(content: Self.Content) -> some View {
HStack {
EmptyView()
content
.padding(.top, 15)
}
.onAppear { self.didAppear?(self) }
}
} just like for an arbitrary custom view, but for the I'd want to experiment more with this approach, as it promises a unified approach for Views and ViewModifiers without requiring a refactoring of the ViewModifier's body. |
Looks like a good idea. |
Have a look at this slight refactoring. The simple tests pass, but I want to add your tests with more sophisticated ViewModifier's structure to assure there are no issues like you've encountered |
Wow, you made it work! I went down this path at one point, but couldn't quite make it do the right thing. By doing this, does one still have to refactor the view out of the body of the view modifier? And you mentioned something above about requiring an extension to ViewModifier. Where do you define that? |
Nah, I really want to avoid it, and so far it works without it. I'm now refactoring the
Ended up simply calling |
Hey @gili-labs , I think I got to a workable solution in this branch. |
@gili-labs I tested it with your examples and it works as expected, I'll likely be preparing a release soon with this code. I think I should close this PR without merging, but I'll give you a shout-out in the release notes as your work played an essential role in solving this challenging task! |
This sounds great! Are you planning on releasing today? |
I want to review and merge another PR, plus check if I can put in some more "low hanging fruits". Can easily defer it for a couple of days. |
This is resolved now in v0.8.0 |
@nalexn I have created this PR with the changes I made to InspectionEmissary to support view modifiers. It works great. However, the
testViewModifierOnFunction
test fails. I left it this way on purpose in order that you can look at the difference between this and theInspectionEmissaryForViewModifier
. I do not see a difference. I dumped the body of the modifier in the debugger, and they seem identical and cannot ascertain why the ViewInspector would treat them differently.