Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
adellibovi committed Mar 16, 2017
2 parents 8f97ff4 + 4f27e8b commit 3fb0947
Show file tree
Hide file tree
Showing 47 changed files with 775 additions and 757 deletions.
26 changes: 13 additions & 13 deletions Examples/SampleApp/SampleApp/ActionBar/ActionBarManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ import Foundation
import TableViewKit

class ActionBarManager: ActionBarDelegate {

let manager: TableViewManager

init(manager: TableViewManager) {
self.manager = manager
}

public func actionBar(_ actionBar: ActionBar, direction: Direction) {
guard let indexPath = indexPathForResponder(forDirection: direction) else { return }

manager.tableView.scrollToRow(at: indexPath, at: .top, animated: true)
manager.tableView.cellForRow(at: indexPath)?.becomeFirstResponder()
}

public func actionBar(_ actionBar: ActionBar, doneButtonPressed doneButtonItem: UIBarButtonItem) { }

fileprivate func indexPathForResponder(forDirection direction: Direction) -> IndexPath? {

func isFirstResponder(item: Item) -> Bool {
if isResponder(item: item),
let indexPath = item.indexPath(in: manager),
Expand All @@ -28,26 +28,26 @@ class ActionBarManager: ActionBarDelegate {
}
return false
}

func isResponder(item: Item) -> Bool {
return (item as? UIResponder)?.canBecomeFirstResponder ?? false
}

let array = manager.sections.flatMap { $0.items }
guard let currentItem = array.first(where: isFirstResponder),
let index = array.index(of: currentItem)
else { return nil }

let item: Item?

switch direction {
case .next:
item = array.suffix(from: index).dropFirst().first(where: isResponder)
case .previous:
item = array.prefix(upTo: index).reversed().first(where: isResponder)
}

return item?.indexPath(in: manager)

}
}
4 changes: 1 addition & 3 deletions Examples/SampleApp/SampleApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: Any]?) -> Bool {
// Override point for customization after application launch.

return true
}

Expand All @@ -33,6 +33,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

4 changes: 2 additions & 2 deletions Examples/SampleApp/SampleApp/CustomCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import UIKit
import TableViewKit

class CustomCell: TableViewCell {

override func awakeFromNib() {
super.awakeFromNib()
}
}
}
21 changes: 8 additions & 13 deletions Examples/SampleApp/SampleApp/CustomHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,28 @@ import UIKit
import TableViewKit

public class CustomHeaderFooterView: UITableViewHeaderFooterView {

@IBOutlet weak var label: UILabel!
}


public class CustomHeaderDrawer: HeaderFooterDrawer {

public static let nib = UINib(nibName: String(describing: CustomHeaderFooterView.self), bundle: nil)
static public var type = HeaderFooterType.nib(CustomHeaderDrawer.nib, CustomHeaderFooterView.self)

static public func draw(_ view: UITableViewHeaderFooterView, with item: Any) {
let item = item as! CustomHeaderItem
let view = view as! CustomHeaderFooterView

static public func draw(_ view: CustomHeaderFooterView, with item: CustomHeaderItem) {
view.label.text = item.title
}
}


public class CustomHeaderItem: HeaderFooter {

public static var drawer = AnyHeaderFooterDrawer(CustomHeaderDrawer.self)

public var title: String?
public var height: Height? = .dynamic(44.0)

public var drawer: HeaderFooterDrawer.Type = CustomHeaderDrawer.self


public init() { }

public convenience init(title: String) {
self.init()
self.title = title
Expand Down
27 changes: 12 additions & 15 deletions Examples/SampleApp/SampleApp/CustomItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,35 @@ import UIKit
import TableViewKit

public class CustomDrawer: CellDrawer {

static public var type = CellType.class(UITableViewCell.self)

static public func draw(_ cell: UITableViewCell, with item: Any) {
let item = item as! CustomItem

public static var type = CellType.class(UITableViewCell.self)

public static func draw(_ cell: UITableViewCell, with item: CustomItem) {
cell.accessoryType = item.accessoryType
cell.accessoryView = item.accessoryView
cell.textLabel?.text = item.title
}
}


public class CustomItem: Selectable, Item {

public static var drawer = AnyCellDrawer(CustomDrawer.self)

public var title: String?
public var onSelection: (Selectable) -> () = { _ in }

public var onSelection: (Selectable) -> Void = { _ in }

public var cellStyle: UITableViewCellStyle = .default
public var accessoryType: UITableViewCellAccessoryType = .none
public var accessoryView: UIView?
public var cellHeight: CGFloat? = UITableViewAutomaticDimension

public var drawer: CellDrawer.Type = CustomDrawer.self


public init() { }

public convenience init(title: String) {
self.init()
self.title = title
}

public func didSelect() {
onSelection(self)
}
Expand Down
Loading

0 comments on commit 3fb0947

Please sign in to comment.