I have the following SwiftUI view that inserts a tappable row in a List:
struct AddItemRow: View {
let prompt: String
let action: (() -> Void)?
var body: some View {
HStack {
ZStack {
Image(systemName: "circle.fill")
.foregroundColor(.white)
.font(.system(.title2))
.padding(.leading, 0)
Image(systemName: "plus.circle.fill")
.foregroundColor(.green)
.font(.system(.title2))
.padding(.leading, 0)
}
.accessibilityHidden(true)
Text(prompt)
.padding(.leading, 8.0)
.accessibilityRemoveTraits(.isStaticText)
.accessibilityIdentifier(prompt)
}
.frame(minHeight: 32.0)
.onTapGesture(count: 1, perform: {
action?()
})
.accessibilityAddTraits(.isButton)
.accessibilityElement(children: .combine)
}
}
I have KIF tests that previously worked with this view, before SwiftUI was adopted for this list, the main content of the screen, as a subview in a UIHostingController.
My test calls the following support function:
func addRow(_ type: ContactComponent) {
let identifier = "add " + type.rawValue
tester().waitForAnimationsToFinish()
tester().tapView(withAccessibilityIdentifier: identifier) // brings row into view
tester().waitForAnimationsToFinish()
tester().tapView(withAccessibilityIdentifier: identifier)
tester().waitForAnimationsToFinish()
}
Previously this worked correctly. Now, the row in question scrolls into view, but the second tap does not activate the row.
Things I have tried:
- The row works fine in actual use.
- In Accessibility Inspector, the row is selectable, the label is the expected correct label, it has a button trait, and clicking "Activate" correctly activates the row.
- Altering the view so this row is already on screen when the view is first displayed does not make any difference. The row does not register a tap.
- Manually clicking the row in the iOS Simulator while the test is running correctly activates the action, which adds a row to the list, and the KIF test then successfully goes on to interact correctly with the textfields in that additional row.
- I have tried multiple ways to restructure the addItem view, such as setting
.accessibilityElement(children: hidden) and then applying the accessibiltyLabel and accessibilityIdentifier to the whole view, or moving the order of the modifiers so the onTapGesture appears before or after the other view modifiers. This does not change anything. I am willing to try other combinations that might be suggested but it is likely I've already tried them. 😕
Any leads would be appreciated. I am about to undertake a complete redesign of the rest of the app in SwiftUI. This is currently the only section in SwiftUI and the only place my KIF tests are failing. I would like to migrate forward my KIF tests if I can but I clearly need KIF to be able to tap SwiftUI elements that are user-tappable.
I have the following SwiftUI view that inserts a tappable row in a List:
I have KIF tests that previously worked with this view, before SwiftUI was adopted for this list, the main content of the screen, as a subview in a UIHostingController.
My test calls the following support function:
Previously this worked correctly. Now, the row in question scrolls into view, but the second tap does not activate the row.
Things I have tried:
.accessibilityElement(children: hidden)and then applying the accessibiltyLabel and accessibilityIdentifier to the whole view, or moving the order of the modifiers so theonTapGestureappears before or after the other view modifiers. This does not change anything. I am willing to try other combinations that might be suggested but it is likely I've already tried them. 😕Any leads would be appreciated. I am about to undertake a complete redesign of the rest of the app in SwiftUI. This is currently the only section in SwiftUI and the only place my KIF tests are failing. I would like to migrate forward my KIF tests if I can but I clearly need KIF to be able to tap SwiftUI elements that are user-tappable.