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

Swift 4 swipeable #1249

Closed
wants to merge 12 commits into from
Closed

Swift 4 swipeable #1249

wants to merge 12 commits into from

Conversation

marbetschar
Copy link
Contributor

According to #1106 this pull request now goes to the new swift 4 branch.

Mauricio Cousillas and others added 2 commits June 7, 2017 14:23
And a gracefull fallback to the old iOS7 behaviour which allows swipe actions only on the right.
@AAverin
Copy link

AAverin commented Oct 1, 2017

Right when I was wondering how to add swipeable actions – here is a PR =)
Would be great to have it merged

Marco Betschart added 2 commits October 17, 2017 20:43
If there are any multivalued sections within the form, Eureka automatically enables editingMode to allow swipe actions to be handled correctly. You have to disable editing manually if you do not want this behaviour in forms containing multivalued sections.
@marbetschar
Copy link
Contributor Author

@mtnbarreto can we get this merged?

@marbetschar
Copy link
Contributor Author

any news on this?

@kronik
Copy link

kronik commented Nov 2, 2017

waiting for this PR to be merged too

@marbetschar
Copy link
Contributor Author

marbetschar commented Nov 16, 2017

@mtnbarreto whats missing to get this merged? I'd love merging this swipe feature as soon as possible into the official release, since I need it in my current project. That said, it would be awesome to have this pull request either merged - or getting to know whats wrong or missing, so I can fix/add the stuff needed and to get this merged based upon your suggestions :)

Marco Betschart added 4 commits December 2, 2017 15:45
In order to allow it to be overwritten by a row which subclasses it. This is needed for the new custom row `SplitRow`. `SplitRow` enables to put two Eureka rows side by side into one UITableViewCell.
@marbetschar
Copy link
Contributor Author

@mats-claassen or @mtnbarreto whats missing to get this swipe feature merged or declined?

marbetschar pushed a commit to Mandelkind/SuggestionRow that referenced this pull request Dec 6, 2017
Added support for the Eureka build which is Swipe and SplitRow aware. This is a temporary branch till these pull requests are merged:

- xmartlabs/Eureka#1338
- xmartlabs/Eureka#1249
@m-revetria m-revetria changed the base branch from feature/Xcode9-Swift4 to master December 8, 2017 18:05
Copy link
Member

@m-revetria m-revetria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marbetschar thanks for your contribution. I left some minor comments.

We'll be glad to merge this after you address them.

Additionally, I'm wondering if there is a way to define a type for all platformValues variables. Using Any for them doesn't look so good for me. I'll be thinking about meanwhile.

self?.showAlert()
}

<<< ButtonRow("Swipe Actions") { (row: ButtonRow) -> Void in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the same indentation that is used in the whole project (4 spaces)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

super.viewDidLoad()

form +++ Section(footer: "Eureka sets table.isEditing = false for SwipeActions.\n\nMultivaluedSections need table.isEditing = true, therefore both can't be used on the same view.")
<<< LabelRow("Actions Right: iOS >= 7"){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please always keep a white space before an opening curly brace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -98,7 +98,18 @@ open class BaseRow: BaseRowType {
public var isHidden: Bool { return hiddenCache }

/// The section to which this row belongs.
public weak var section: Section?
open weak var section: Section?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change does not seem to be needed? Please revert it back

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Done.


if #available(iOS 11, *){
self.platformValue = UIContextualAction(style: style.platformValue as! UIContextualAction.Style, title: title){ action, view, completion -> Void in
handler(action,view,completion)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep arguments separated by spaces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


public let platformValue: Any

public var backgroundColor: UIColor?{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These properties seem that will have some effect just on iOS 11. Can't them be available just for iOS 11+?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Is changed.


public class SwipeAction{

public let platformValue: Any
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think platformValue is not clear enough. Maybe just contextualAction or rowAction

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used contextualAction as suggested.

public var performsFirstActionWithFullSwipe: Bool = false
public var actions: [SwipeAction] = []

public var platformValue: Any?{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that this can be available just from iOS 11, right? If so then you can set its type to UISwipeActionsConfiguration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Fixed.

case normal = 0
case destructive = 1

var platformValue: Any{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if all these platformValues can have a type more concrete than Any. @mtnbarreto thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Used marker protocols to fix this. See SwipeActions.swift at the bottom of the file.

Copy link
Member

@m-revetria m-revetria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, grate work! thanks for fixing the comments


import Foundation

public typealias SwipeActionHandler = (ContextualAction, ContextualActionSource, ((Bool) -> Void)?) -> Void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should pass the row as closure argument.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContextualActionSource can be removed since the row is passed as argument now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a brilliant idea! We should ideally use the specific Row type right? Not just BaseRow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented as public typealias SwipeActionHandler = (ContextualAction, BaseRow, ((Bool) -> Void)?) -> Void

public let contextualAction: ContextualAction

@available(iOS 11, *)
public var backgroundColor: UIColor?{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to make UIContextualAction and UITableViewRowAction conform to a protocol like this:

public protocol ContextualAction{
     var backgroundColor: UIColor?
     var image: UIImage?
     var title: String?
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course 👍🏼 makes a whole lot more sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to add the following in order to make UITableViewRowAction conform to the newly created ContextualAction protocol:

extension UITableViewRowAction: ContextualAction {
	public var image: UIImage? {
		get { return nil }
		set { return }
	}
}

configure(self)
}

public var performsFirstActionWithFullSwipe: Bool = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove : Bool

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.


public class SwipeConfiguration{

public init(configure: (SwipeConfiguration) -> Void){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a struct here and each row should have an instance of the strict already created so Eureka users can do something like that:

row.leftSwipe.actions = [swipeAction1, swipeAction2]
row.rightSwipe.actions = [swipeAction1, swipeAction2]

init should be refactored to init() in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks amazing. One question: Would you prefer using leftSwipe and rightSwipe instead of leadingSwipe and trailingSwipe ?

If I'll look at PushRow, left/right looks more familiar. But due to the nature of this gesture it might lead to confusions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done using leadingSwipe and trailingSwipe.

}
}

public var title: String?{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove it since we can do contextualAction.title, contextualAction.image and contextualAction. backgroundColor and so on can be accessed directly using the protocol containing these properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite its true these properties can be accessed directly it looks a bit awkward in the form definition code. That's why I also made SwipeAction conforming to the newly created ContextualAction protocol - and let SwipeAction.contextualAction create the platform specific action on demand.

This way we end up with a nice and clean looking form initialisation code:

let infoAction = SwipeAction(style: .normal, title: "Info", handler: { (action, row, completionHandler) in
	print("Info")
	completionHandler?(true)
})
infoAction.backgroundColor = .blue

$0.leadingSwipe.actions = [infoAction]
$0.leadingSwipe.performsFirstActionWithFullSwipe = true

}
}

public init(contextualStyle: ContextualStyle){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this init.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

}
}

public enum Style: Int{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary : Int here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiler throws Enum case cannot have a raw value if the enum does not have a raw type if : Int is removed

@available(iOSApplicationExtension 11.0, *)
extension UIContextualAction.Style: ContextualStyle{}

public protocol ContextualActionSource{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer needed according my feedback.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed ContextualActionSource

@mtnbarreto
Copy link
Member

@marbetschar We also need to add feature documentation in the readme in order to get this merged.

@marbetschar
Copy link
Contributor Author

@mtnbarreto where to put the feature documentation?

@marbetschar
Copy link
Contributor Author

@mtnbarreto also added feature documentation to README.md

mtnbarreto pushed a commit that referenced this pull request Dec 19, 2017
@mtnbarreto
Copy link
Member

@marbetschar Finally it got merged! #1361. Thanks for contributing!

@mtnbarreto mtnbarreto closed this Dec 20, 2017
@marbetschar
Copy link
Contributor Author

@mtnbarreto perfect timing, thank you very much!!!! 🎉🎄🌟🎅🏻

@matiasvillaverde
Copy link

Is possible to update this version by Cocoapods? Now the last version is 4.0.1

Thanks for this cool feature!

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.

None yet

8 participants