Loading video...

Video Failed to Load

Go Home

Remember, you can simply disable the gesture recognizer in SwiftUI using a ternary operator. You may need to refactor your gesture recognizer, but it’s quite simple ➡️

22,444 views • 1 year ago •via X (Twitter)

9 Comments

Mike Mikina's profile picture
Mike Mikina1 year ago

A follow up! It turns out that the documentation includes gesture(_:isEnabled:), so you can simply pass a boolean value there. Kudos to @harlanhaskins!

Harlan Haskins's profile picture
Harlan Haskins1 year ago

.gesture(…) also has a variant that takes an isEnabled parameter.

Mike Mikina's profile picture
Mike Mikina1 year ago

Wait, what?! How did I miss it? I swear I was looking for it in the documentation the other day 😄 Thanks for sharing! 🙌

Raul Menezes's profile picture
Raul Menezes1 year ago

You can achieve the same result by using `.disabled(!isActive)` so you don’t need to touch your gestures and keep your code as simple as it can be.

Mike Mikina's profile picture
Mike Mikina1 year ago

In this example, it will certainly work the same way. However, if you have another gesture recognizer or the view has additional interactions, it will not work.

Pavan's profile picture
Pavan1 year ago

Oh I didn’t know this, good one!

Moneky's profile picture
Moneky1 year ago

Is this Swift for newbies?

Rob Jonson's profile picture
Rob Jonson1 year ago

How is nil valid as "some Gesture" ??

Mike Mikina's profile picture
Mike Mikina1 year ago

It's because Optional conditionally conforms to Gesture. You can read more about it here:

Related Videos