Skip to content

Conversation

quiekedei
Copy link
Contributor

@quiekedei quiekedei commented Apr 7, 2018

Problem:

On iOS 10 and lower, when adding a trailing SwipeAction to a Row, this action is cast to a UITableViewRowAction and returned from tableView(_:editActionsForRowAt:) in FormViewController. Unfortunately the same does not happen on iOS 11, since there a SwipeAction is cast to UIContextualAction instead of UITableViewRowAction, leaving tableView(_:editActionsForRowAt:) to return nothing and making UIKit fall back to default behavior.

This leads to inconsistent behavior between iOS versions, which is, of course, unfavorable.

Solution:

I propose the introduction of tableViewRowAction(forRow:) alongside the already existing func contextualAction(forRow:). This way, in tableView(_:editActionsForRowAt:), we can explicitly request UITableViewRowActions and establish consistent behavior across iOS versions.

Demo:

Given the following form setup…

form +++ Section("Rows")
	<<< LabelRow {
		$0.title = "← Delete me!"
		
		let action = SwipeAction(style: .destructive, title: " Bam! 💥", handler: { (action, row, completionBlock) in
			completionBlock?(true)
		})
		
		action.backgroundColor = UIColor.darkGray
		
		$0.trailingSwipe.actions = [action]
	}

tableView.setEditing(true, animated: false)

… the current behavior when tapping the delete icon on iOS 11 is as follows:

current_behavior

The expected behavior, however, is the same as it already is on iOS 10 and lower:

expected_behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant