Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Inconsistencies when using SwipeAction #1504

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

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