ViewInspector
ViewInspector copied to clipboard
Accessing properties on a view that takes a generic
Considering some view that takes in content
struct WrapperView<Content>: View where Content: View {
let someProperty: Int
@ViewBuilder var content: () -> Content
var body: some View {
VStack {
Text("Some property \(someProperty / 2)")
content()
}
}
}
let sut = VStack {
WrapperView("Cool") {
VStack {VStack {VStack {VStack { Text("Some Complicated Content") }}}}
}
}
We can find a view that is nested in content like so:
let foundWrapper = try sut.find(WrapperView<EmptyView>.self) // succeeds
let foundText = try foundWrapper.find(Text.self) // succeeds
But, now it seems as though it's impossible to access someProperty?
let foundWrapperAV = try foundWrapper.actualView().someProperty // fails with type mismatch
Just want to make sure we are not missing anything. we'd like to be able to get the properties of WrapperView, ignoring the Content generic