siteline / swiftui-introspect

Introspect underlying UIKit/AppKit components from SwiftUI
MIT License
5.67k stars 351 forks source link

TabView Introspection #181

Closed rehatkathuria closed 1 year ago

rehatkathuria commented 1 year ago

Tested on a vanilla SwiftUI project. The following doesn't fire the closure. Am I misunderstanding this specific introspection closure?

Added using SPM referencing the main branch

@main
struct FooBarApp: App {
    @State var selection = 1

    var body: some Scene {
        WindowGroup {
            TabView(selection: $selection) {
                Rectangle()
                    .fill(Color.green)
                    .frame(width: 50, height: 50)
                    .tag(1)

                Rectangle()
                    .fill(Color.blue)
                    .frame(width: 50, height: 50)
                    .tag(2)

                Rectangle()
                    .fill(Color.red)
                    .frame(width: 50, height: 50)
                    .tag(3)
            }
            .tabViewStyle(.page(indexDisplayMode: .never))
            .introspectPagedTabView { collectionView, scrollView in
                print("SV -> \(scrollView)")
            }
        }
    }
}
davdroman commented 1 year ago

@rehatkathuria which version of iOS are you running it on? Is it iOS 16, or lower?

grdsdev commented 1 year ago

I faced the same issue.

On iOS 16 you should use introspectCollectionView instead of introspectPagedTabView for this.

I opened a PR with a fix for this in #200

davdroman commented 1 year ago

Fixed by #200. Thank you @grsouza!