SwiftUI: ListItem gestures

后端 未结 2 754
离开以前
离开以前 2021-02-04 14:05

Target is a modification with the following behavior:

(but only with 2 buttons - 1 on the left side, 1 on the right)

Behavior:

  • short swipe

2条回答
  •  無奈伤痛
    2021-02-04 14:53

    Unfortunately there isn't any native SwiftUI solution so far (as of SwiftUI 2 beta).

    • SwiftUI - Still no support for custom swipe actions
    • How is possible configure the List "onDelete" action / Button?
    • SwiftUI - List editing mode - how to change delete button title?

    You can make your custom swipe actions using UIKit and wrap them in UIViewRepresentable.

    Some solutions (you may have seen them already):

    • SwiftUI - Custom Swipe Actions In List
    • Create gesture to edit list item using SwiftUI

    Or you can just use a library instead (at least until a native solution is developed).

    Some libraries:

    • SwipeCell (SwiftUI) (may be exactly what you need)
    • SwipeCellKit (UIKit)

    If you want to implement simultaneous swipe gesture you need to use UIViewRepresentable again:

    • How to detect a tap gesture location in SwiftUI? (this is for tap gestures only but with nice explanation)
    • SwiftUI: Multitouch gesture / Multiple Gestures (this is the adaptation of the above but with swipe gestures)

    Summing up

    • Answer to the first question: SwipeCell
    • Answer to the second question: SwiftUI: Multitouch gesture / Multiple Gestures

提交回复
热议问题