swiftuitableviewuicontextualaction

How to change UIContextualAction swipe length and add "release to cancel" feature?


Currently, I have a swipe action in my TableView to perform a custom action on swipe on the corresponding cell. However, I'd like to change how far I have to drag to get the default haptic feedback to indicate completion of swipe. Also, I would like to add a feature that hides the swipe action automatically if the action is not completed instead of it remaining on screen. Here's my code so far:

override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

    let customRowAction = UIContextualAction(style: .normal, title: "Action") {(action, view, completed)  -> Void in

        //perform updates to data

        completed(true)

    }

    let configuration = UISwipeActionsConfiguration(actions: [customRowAction])

    return configuration
}

I'd like to achieve an effect similar to that of the Apollo reddit app. Any help would be appreciated!


Solution

  • The design details of the built in row swipe mechanism are not up to you. Either live with them or don’t use them at all (and write your own swipe mechanism from scratch).