5

I'm making an app in SwiftUI that requires the user to tap a button repeatedly very fast.

When the user taps the button quickly with multiple fingers, every second or so the button will fail to recognize the tap gesture, and the console will output:

<...> Gesture: Failed to receive system gesture state notification before next touch

In my view, I used a Button, to no luck:

Button(action: handleTap) {
  Text("Press me!")
}

Then, I tried onTapGesture(perform:), again to no avail:

Text("Press me!")
  .onTapGesture(perform: handleTap)

But now, I'm stumped. Am I missing something here? Is SwiftUI not designed to handle rapid inputs in this fashion? I'm relatively new with SwiftUI, so any feedback is greatly appreciated.

Ben Myers
  • 1,173
  • 1
  • 8
  • 25
  • 1
    Happened with UIKit before for me too – aheze Jun 05 '21 at 04:05
  • 4
    Gesture recognisers are relatively slow for such kind of task, you need to use UIKit low level `touchesBegan/touchesEnded` to get all events. – Asperi Jun 05 '21 at 04:27
  • 1
    maybe this can help to disable multi-touch : https://stackoverflow.com/a/67456381/14733292 – Raja Kishan Jun 05 '21 at 05:39
  • @aheze Yes, I tried this with UIKit and I actually noticed it was a bit slower. It's pretty odd; I wonder if it would be better using SpriteKit. – Ben Myers Jun 05 '21 at 20:16
  • @Asperi That seems like a great suggestion. Perhaps SwiftUI has a way to use `touchesBegan` to check if a touch actually hits a certain view? – Ben Myers Jun 05 '21 at 20:17
  • @RajaKishan that is an interesting suggestion, but sadly disabling multi-touch on my view and on my application led to no avail. – Ben Myers Jun 05 '21 at 20:18
  • Found: https://www.reddit.com/r/SwiftUI/comments/p22tvo/whenever_i_tap_the_buttons_on_my_app_relatively/ And sounds reasonable answer. Maybe handleTap will block the main thread too long and this will cause it. Comment out function body and look if it's still happening. If not then go through step by step and search what blocks the main thread and should be moved to another thread – Samps Jul 21 '22 at 08:28
  • @Samps, this still occurs with fast taps which are not doing anything, e.g. ```Text("Click Me!").onTapGesture {}``` has this issue. – Randy Jul 21 '22 at 08:41

0 Answers0