siteline/swiftui-introspect

Introspecting ScrollView and iOS 17

ralfebert opened this issue · 9 comments

I am currently using Introspect 0.2.3 and it works fine on iOS 15 / 16.
When I tested on iOS 17 beta 3, I don't get the callback with the UIScrollView anymore.
So I tried upgrading to SwiftUIIntrospect 0.9.0 and getting the ScrollView works fine here also on iOS 17, but the View that's behind the ScrollView became un-tappable / doesn't react on tap events anymore. I am blindly guessing the View for Introspection might be blocking those events.
As a workaround, I added my own version of introspectScrollView and downgraded back to 0.2.3, using selector: TargetViewSelector.siblingContainingOrAncestor only on iOS 17 (not sure if that's the best way, but it works):

public func introspectScrollView2(customize: @escaping (UIScrollView) -> ()) -> some View {
        if #available(iOS 17, *) {
            return introspect(selector: TargetViewSelector.siblingContainingOrAncestor, customize: customize)
        } else {
            return introspect(selector: TargetViewSelector.siblingOfTypeOrAncestor, customize: customize)
        }
    }

Please use the new SwiftUIIntrospect module. The old Introspect module is unstable, deprecated, and will be effectively removed this autumn.

https://github.com/siteline/SwiftUI-Introspect#scrollview

@davdroman Thanks for your reply; I tried the new module, and introspection started working on iOS 17 again, but then the View that's behind the ScrollView became un-tappable / doesn't react on tap events anymore; so I resorted to the old version because I had fully working solution already for that :) Any hints how I can help to get the tap events issue fixed?

Can you share a small reproducible code sample of the scenario you describe? Thanks in advanced.

@davdroman Here you go:

struct ContentView: View {
    @State private var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 51.5, longitude: -0.1), span: MKCoordinateSpan(latitudeDelta: 0.5, longitudeDelta: 0.5))
    
    var body: some View {
        ZStack {
            Map(coordinateRegion: $region)
                .ignoresSafeArea()

            self.bottomDrawerScrollView
        }
    }
    
    @ViewBuilder var bottomDrawerScrollView : some View {
        ScrollView([.vertical]) {
            Text("Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem Ipsum ")
        }
        .offset(x: 0, y: 400)
        .introspect(.scrollView, on: .iOS(.v15, .v16, .v17)) { scrollView in
            scrollView.backgroundColor = .yellow
        }
    }

}

Without the .introspect, you can pan the map, with the .introspect, you can not pan it around anymore.

Thank you! I’ll investigate this later today as I’m currently AFK.

@ralfebert thank you for your patience and for the code sample. I was able to pinpoint the issue and the fix is now available in 0.9.1.

I ended up having to revert my apps to use the old version of introspect and the snippet in the first comment due to bugs with the current scrollview implementation.

@jbromberg would you be able to open a new issue explaining what the bugs you've encountered look like? With the upcoming 1.0 release, Introspect will no longer be part of this repo so it's worth fixing any bugs in SwiftUIIntrospect going forward to prevent version lock-in.

@davdroman just opened issue #356. Seems to be the main bug I was encountering.