From bf01dc638a1908be2392becbf74a137ced6e74aa Mon Sep 17 00:00:00 2001 From: Max Sokolov Date: Thu, 9 Jun 2016 02:27:25 +0300 Subject: [PATCH] add row action --- Tablet/TableRow.swift | 12 +++++- Tablet/TableRowAction.swift | 41 +++++++++++++++++++ Tablet/Tablet.swift | 15 ------- Tablet/Tablet.xcodeproj/project.pbxproj | 4 ++ .../Controllers/MainController.swift | 13 ++++-- 5 files changed, 65 insertions(+), 20 deletions(-) create mode 100644 Tablet/TableRowAction.swift diff --git a/Tablet/TableRow.swift b/Tablet/TableRow.swift index 1c59fe4..4c5c0d4 100644 --- a/Tablet/TableRow.swift +++ b/Tablet/TableRow.swift @@ -30,8 +30,9 @@ public protocol Row { } public class TableRow: Row { - + public let item: ItemType + private var actions = [RowAction]() public var reusableIdentifier: String { return CellType.reusableIdentifier() @@ -45,11 +46,18 @@ public class TableRow]? = nil) { self.item = item } public func configure(cell: UITableViewCell) { (cell as? CellType)?.configure(item) } + + // MARK: - actions - + + public func addAction(action: TableRowAction) { + + + } } \ No newline at end of file diff --git a/Tablet/TableRowAction.swift b/Tablet/TableRowAction.swift new file mode 100644 index 0000000..05740e6 --- /dev/null +++ b/Tablet/TableRowAction.swift @@ -0,0 +1,41 @@ +// +// Copyright (c) 2015 Max Sokolov https://twitter.com/max_sokolov +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to deal in +// the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +// the Software, and to permit persons to whom the Software is furnished to do so, +// subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +import UIKit + +public enum TableActionType { + + case Click + case Custom(String) +} + +protocol RowAction { + +} + +public class TableRowAction: RowAction { + + public init(_ action: TableActionType, handler: (row: TableRow) -> Void) { + + + + + } +} \ No newline at end of file diff --git a/Tablet/Tablet.swift b/Tablet/Tablet.swift index ad2034b..bf5e653 100644 --- a/Tablet/Tablet.swift +++ b/Tablet/Tablet.swift @@ -24,21 +24,6 @@ struct TabletNotifications { static let CellAction = "TabletNotificationsCellAction" } -public enum TableActionType { - - case Click - case Custom(String) -} - -public class TableRowAction { - - let type: TableActionType - - public init(type: TableActionType, handler: (data: ActionData) -> Void) { - self.type = type - } -} - /** The actions that Tablet provides. */ diff --git a/Tablet/Tablet.xcodeproj/project.pbxproj b/Tablet/Tablet.xcodeproj/project.pbxproj index 1a824df..f562bbc 100644 --- a/Tablet/Tablet.xcodeproj/project.pbxproj +++ b/Tablet/Tablet.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ DA539C9F1CFB025C00368ACB /* Operators.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA539C9E1CFB025C00368ACB /* Operators.swift */; }; DA539CC61D01D44500368ACB /* TableRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA539CC51D01D44500368ACB /* TableRow.swift */; }; DA9EA7351D06155E0021F650 /* HeightStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9EA7341D06155E0021F650 /* HeightStrategy.swift */; }; + DA9EA73E1D08D6AA0021F650 /* TableRowAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = DA9EA73D1D08D6AA0021F650 /* TableRowAction.swift */; }; DAC2D6741C9D743D009E9C19 /* Tablet.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DAC2D6691C9D743D009E9C19 /* Tablet.framework */; }; DAC2D6871C9D7517009E9C19 /* Tablet.h in Headers */ = {isa = PBXBuildFile; fileRef = DAC2D6851C9D7517009E9C19 /* Tablet.h */; settings = {ATTRIBUTES = (Public, ); }; }; DAC2D6901C9D799E009E9C19 /* TableDirector.swift in Sources */ = {isa = PBXBuildFile; fileRef = DAC2D68C1C9D799E009E9C19 /* TableDirector.swift */; }; @@ -35,6 +36,7 @@ DA539C9E1CFB025C00368ACB /* Operators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Operators.swift; sourceTree = ""; }; DA539CC51D01D44500368ACB /* TableRow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableRow.swift; sourceTree = ""; }; DA9EA7341D06155E0021F650 /* HeightStrategy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HeightStrategy.swift; sourceTree = ""; }; + DA9EA73D1D08D6AA0021F650 /* TableRowAction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableRowAction.swift; sourceTree = ""; }; DAC2D6691C9D743D009E9C19 /* Tablet.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Tablet.framework; sourceTree = BUILT_PRODUCTS_DIR; }; DAC2D6731C9D743D009E9C19 /* TabletTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TabletTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; DAC2D6841C9D7517009E9C19 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -99,6 +101,7 @@ children = ( DAC2D68C1C9D799E009E9C19 /* TableDirector.swift */, DA539CC51D01D44500368ACB /* TableRow.swift */, + DA9EA73D1D08D6AA0021F650 /* TableRowAction.swift */, DAC2D68E1C9D799E009E9C19 /* TableSection.swift */, DAC2D68D1C9D799E009E9C19 /* TableRowBuilder.swift */, DA9EA7341D06155E0021F650 /* HeightStrategy.swift */, @@ -230,6 +233,7 @@ DAC2D6901C9D799E009E9C19 /* TableDirector.swift in Sources */, DAC2D6921C9D799E009E9C19 /* TableSection.swift in Sources */, DA9EA7351D06155E0021F650 /* HeightStrategy.swift in Sources */, + DA9EA73E1D08D6AA0021F650 /* TableRowAction.swift in Sources */, DA539CC61D01D44500368ACB /* TableRow.swift in Sources */, DA08A04F1CF3AB0C00BBF1F8 /* ConfigurableCell.swift in Sources */, DAC2D6911C9D799E009E9C19 /* TableRowBuilder.swift in Sources */, diff --git a/TabletDemo/Classes/Presentation/Controllers/MainController.swift b/TabletDemo/Classes/Presentation/Controllers/MainController.swift index 7d6b396..905c33f 100644 --- a/TabletDemo/Classes/Presentation/Controllers/MainController.swift +++ b/TabletDemo/Classes/Presentation/Controllers/MainController.swift @@ -30,15 +30,22 @@ class MainController: UIViewController { - + let a = TableRowAction(.Click) { + (row) in + + } let row1 = TableRow(item: "1") let row2 = TableRow(item: "2") - let row3 = TableRow(item: "3") + let row3 = TableRow(item: "3", actions: [a]) - + row1 + + .addAction(TableRowAction(.Click) { (row) in + + })