siteline / swiftui-introspect

Introspect underlying UIKit/AppKit components from SwiftUI
MIT License
5.69k stars 352 forks source link

Issue with Navigation and accessibility #376

Open honkmaster opened 1 year ago

honkmaster commented 1 year ago

Description

I have an app with the basic structure of a NavigationView which contains a ScrollView. If the user taps an element in the ScrollView, the app navigates to a detail view. The ScrollView is modified using Introspect (v. 1.1.0). Additionally, the ScrollView has set some accessibility attributes to be used in XCUITests. Here is an example of the code.

ScrollView(.horizontal, showsIndicators: false) {
    content
      .accessibilityIdentifier("Bar")
}
.introspect(.scrollView, on: .iOS(.v16, .v17)) { scrollView in
    pagedScrollViewDelegator.width = geometry.size.width + spacing

    scrollView.decelerationRate = .fast
    scrollView.clipsToBounds = false
    scrollView.alwaysBounceVertical = false
    scrollView.delegate = pagedScrollViewDelegator
}
.accessibilityElement(children: .contain)
.accessibilityIdentifier("Foo")

Now there is a problem in the XCUI tests. When the app starts for the first time, all accessibility identifier are set correctly. XCUITests can navigate. But when the tests comes back to the start page, all accessibility identifier inside the modified ScrollView are gone from the hierarchy. If we remove the modification of the ScrollView with Introspect, the test works, the identifier remain even after navigation.

Checklist

Expected behavior

Accessibility accessibility should remain

Actual behavior

Accessibility accessibility are gone after navigation

Steps to reproduce

See above.

Version information

1.1.0

Destination operating system

16.4

Xcode version information

Xcode 15.0

Swift Compiler version information

No response

honkmaster commented 1 year ago

Note:

If I move the accessibility view modifiers from after to before the introspect view modifier the XCUITests seem to continue to work (short debugging). However, this might be a workaround, but should not be required as it is non deterministic.