Пропустить навигацию
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,2 тыс. подписчиков

Открыть в X
224 отметки «Нравится»СкачатьОригинальный пост

22 491 просмотр

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 комментариев

Комментарии из оригинального поста в X (Twitter)

  • Фото профиля Mike Mikina

    @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 отметок «Нравится»

  • Фото профиля Harlan Haskins

    @harlanhaskins

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

    3 отметки «Нравится»

  • Фото профиля Mike Mikina

    @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 отметка «Нравится»

  • Фото профиля Raul Menezes

    @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 отметка «Нравится»

  • Фото профиля Mike Mikina

    @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

    @pavm035

    Oh I didn’t know this, good one!

    1 отметка «Нравится»

  • Фото профиля Moneky

    @wealthybaboon

    Is this Swift for newbies?

  • Фото профиля Rob Jonson

    @ConfusedVorlon

    How is nil valid as "some Gesture" ??

  • Фото профиля Mike Mikina

    @mikemikina

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