Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwiftUI button being tapped but the click is not registered in XCode 16 beta. #1302

Open
ispatel22 opened this issue Sep 9, 2024 · 7 comments

Comments

@ispatel22
Copy link

UI elements of a SwiftUI view get tapped but are not registered. For example, if there is a button with an accessibility identifier, KIF detects and taps on it, but the button's action method is not getting called. This issue only happens if you run the project on the latest XCode 16 beta. This bug does NOT occur on XCode 15. Below is the link to a sample repo that reproduces the issue.

KIFTapBug repo

@ispatel22 ispatel22 changed the title SwiftUI button being tapped but the click is not registered XCode 16 beta. SwiftUI button being tapped but the click is not registered in XCode 16 beta. Sep 9, 2024
@danielbarela
Copy link
Contributor

I would also add that running the tests on the iOS17 simulator from the Xcode 16 beta does work, however running the same test on the iOS18 simulator does not.

@ispatel22
Copy link
Author

After debugging, I noticed issues with gesture recognizer on the button in the sample repo.

If the app is ran on iOS 18 Xcode 16:

  • There is ONLY UIHoverGestureRecognizer on the SwiftUIView
    I manually added a test UITapGestureRecognizer in the KIF test and the call back method gets called.

Things I tried to fix:

  • Added a .onTapGesture to the button in MySwiftUIView.swift but it did not work.

If the app is ran on iOS 17 Xcode 16:

  • There is a UIGestureRecognizer and UIHoverGestureRecognizer on the SwiftUIView and the test passes as intended.

To see the issue:

  1. Put a break point after the following line UIView* showTextButton = [[viewTester usingIdentifier:@"ShowTextButtonIdentifier"] waitForView]; in test_01
  2. Run the test and in the debugger, under showTextButton look for gestureRecognizers. Run the test for both iOS 18 and iOS 17

@ispatel22
Copy link
Author

@justinseanmartin @danielbarela Will this issue be fixed any time soon?

@justinseanmartin
Copy link
Contributor

justinseanmartin commented Sep 17, 2024

I haven't had time to take a look just yet. If you'd like to dig in and see if you can find a root cause, I'd be happy to help with pointers and guidance and help get it merged. Even setting up an integration test in KIF integration suite would be helpful for having something to use to investigate the issue and verify the fix.

EDIT: Sorry, I should've read more closely. I see you did a bunch of your homework here. I'd guess the issue is in how the touch event is being synthesized with the HID event. I'd guess we can diff the touch events being sent from real user input compared to what KIF is doing to synthesize them. I'm not sure when I'll have time to dig in, but that's where I would start. We aren't impacted by this yet, but presumably we will be eventually.

@ispatel22
Copy link
Author

@justinseanmartin I'm not sure what you mean by we can diff the touch events being sent from real user input compared to what KIF is doing to synthesize them.

@BartlomiejWlodarczak
Copy link

BartlomiejWlodarczak commented Sep 18, 2024

I have been working on the same exact issue impacting another project and believe I have found the underlying change in iOS 18. As it was my first or second guess as well, I found that it is not related to the HID event. Having in mind that Apple introduced a mechanism for correlating UIKit and SwiftUI gestures - I ended up digging through the disassembled code related to touch instantiation / handling / hit testing.
I'll create a PR when I find some spare time.

@ispatel22 What @justinseanmartin meant by that is that when tapping/clicking on a real device or simulator the digitizer a HIDEvent is emitted, and it might vary from the event that is created by the KIF code. e.g. In real conditions there is a parent event with transducer type - hand, and it contains another event with transducer type - finger.
Look here: https://github.com/WebKit/WebKit/blob/94ffe3454ef85d60f9448bc61d42dd7dd6f54833/Tools/WebKitTestRunner/ios/HIDEventGenerator.mm#L411C18-L411C39
They are injecting the gesture in another way, so I believe that's why they needed to put more effort into making sure it's as close as the real event as possible, otherwise it wouldn't work correctly.

@ispatel22
Copy link
Author

@BartlomiejWlodarczak Do you have a fix for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants