Skip navigation
Remember, you can simply disable the gesture recognizer in SwiftUI using a ternary operator.
0:00 / 0:24

Remember, you can simply disable the gesture recognizer in SwiftUI using a ternary operator.

Mike Mikina

@mikemikina1.2K followers

Visit on X
224 likesDownloadOriginal post

22,491 views

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 ➡️

9 Comments

Comments from the original post on X (Twitter)

  • Mike Mikina's profile picture

    @mikemikina

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

    7 likes

  • Harlan Haskins's profile picture

    @harlanhaskins

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

    3 likes

  • Mike Mikina's profile picture

    @mikemikina

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

    1 like

  • Raul Menezes's profile picture

    @rmenezes89

    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.

    1 like

  • Mike Mikina's profile picture

    @mikemikina

    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

    @pavm035

    Oh I didn’t know this, good one!

    1 like

  • Moneky's profile picture

    @wealthybaboon

    Is this Swift for newbies?

  • Rob Jonson's profile picture

    @ConfusedVorlon

    How is nil valid as "some Gesture" ??

  • Mike Mikina's profile picture

    @mikemikina

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