ViewInspector icon indicating copy to clipboard operation
ViewInspector copied to clipboard

Accessing properties on a view that takes a generic

Open JOyo246 opened this issue 1 year ago • 8 comments

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

JOyo246 avatar Feb 28 '24 16:02 JOyo246