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
Swift 4 swipeable #1249
Conversation
And a gracefull fallback to the old iOS7 behaviour which allows swipe actions only on the right.
Right when I was wondering how to add swipeable actions – here is a PR =) |
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.
@mtnbarreto can we get this merged? |
any news on this? |
waiting for this PR to be merged too |
@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 :) |
Updates from upstream
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.
Made var section open
@mats-claassen or @mtnbarreto whats missing to get this swipe feature merged or declined? |
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
There was a problem hiding this 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.
Example/Example/ViewController.swift
Outdated
self?.showAlert() | ||
} | ||
|
||
<<< ButtonRow("Swipe Actions") { (row: ButtonRow) -> Void in |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Example/Example/ViewController.swift
Outdated
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"){ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Source/Core/BaseRow.swift
Outdated
@@ -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? |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. Done.
Source/Core/SwipeActions.swift
Outdated
|
||
if #available(iOS 11, *){ | ||
self.platformValue = UIContextualAction(style: style.platformValue as! UIContextualAction.Style, title: title){ action, view, completion -> Void in | ||
handler(action,view,completion) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Source/Core/SwipeActions.swift
Outdated
|
||
public let platformValue: Any | ||
|
||
public var backgroundColor: UIColor?{ |
There was a problem hiding this comment.
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+?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Is changed.
Source/Core/SwipeActions.swift
Outdated
|
||
public class SwipeAction{ | ||
|
||
public let platformValue: Any |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used contextualAction
as suggested.
Source/Core/SwipeActions.swift
Outdated
public var performsFirstActionWithFullSwipe: Bool = false | ||
public var actions: [SwipeAction] = [] | ||
|
||
public var platformValue: Any?{ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Fixed.
Source/Core/SwipeActions.swift
Outdated
case normal = 0 | ||
case destructive = 1 | ||
|
||
var platformValue: Any{ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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
Source/Core/SwipeActions.swift
Outdated
|
||
import Foundation | ||
|
||
public typealias SwipeActionHandler = (ContextualAction, ContextualActionSource, ((Bool) -> Void)?) -> Void |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
Source/Core/SwipeActions.swift
Outdated
public let contextualAction: ContextualAction | ||
|
||
@available(iOS 11, *) | ||
public var backgroundColor: UIColor?{ |
There was a problem hiding this comment.
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?
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 }
}
}
Source/Core/SwipeActions.swift
Outdated
configure(self) | ||
} | ||
|
||
public var performsFirstActionWithFullSwipe: Bool = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove : Bool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
Source/Core/SwipeActions.swift
Outdated
|
||
public class SwipeConfiguration{ | ||
|
||
public init(configure: (SwipeConfiguration) -> Void){ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
Source/Core/SwipeActions.swift
Outdated
} | ||
} | ||
|
||
public var title: String?{ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Source/Core/SwipeActions.swift
Outdated
} | ||
} | ||
|
||
public init(contextualStyle: ContextualStyle){ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
Source/Core/SwipeActions.swift
Outdated
} | ||
} | ||
|
||
public enum Style: Int{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary : Int
here.
There was a problem hiding this comment.
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
Source/Core/SwipeActions.swift
Outdated
@available(iOSApplicationExtension 11.0, *) | ||
extension UIContextualAction.Style: ContextualStyle{} | ||
|
||
public protocol ContextualActionSource{} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed ContextualActionSource
@marbetschar We also need to add feature documentation in the readme in order to get this merged. |
@mtnbarreto where to put the feature documentation? |
@mtnbarreto also added feature documentation to README.md |
@marbetschar Finally it got merged! #1361. Thanks for contributing! |
@mtnbarreto perfect timing, thank you very much!!!! 🎉🎄🌟🎅🏻 |
Is possible to update this version by Cocoapods? Now the last version is 4.0.1 Thanks for this cool feature! |
According to #1106 this pull request now goes to the new swift 4 branch.