Skip to content

Commit

Permalink
TableView Style argument added & Examples updated
Browse files Browse the repository at this point in the history
  • Loading branch information
rushisangani committed May 19, 2021
1 parent f441457 commit 1783c2b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,62 @@ open class RSSelectionMenu<T: Equatable>: UIViewController, UIPopoverPresentatio

// MARK: - Init

convenience public init(dataSource: DataSource<T>, cellConfiguration configuration: @escaping UITableViewCellConfiguration<T>) {
self.init(selectionStyle: .single, dataSource: dataSource, cellConfiguration: configuration)
}

convenience public init(selectionStyle: SelectionStyle, dataSource: DataSource<T>, cellConfiguration configuration: @escaping UITableViewCellConfiguration<T>) {
self.init(selectionStyle: selectionStyle, dataSource: dataSource, cellType: .basic, cellConfiguration: configuration)
}

convenience public init(selectionStyle: SelectionStyle, dataSource: DataSource<T>, cellType: CellType, cellConfiguration configuration: @escaping UITableViewCellConfiguration<T>) {
convenience public init(
dataSource: DataSource<T>,
tableViewStyle: UITableView.Style = .plain,
cellConfiguration configuration: @escaping UITableViewCellConfiguration<T>) {

self.init(
selectionStyle: .single,
dataSource: dataSource,
tableViewStyle: tableViewStyle,
cellConfiguration: configuration
)
}

convenience public init(
selectionStyle: SelectionStyle,
dataSource: DataSource<T>,
tableViewStyle: UITableView.Style = .plain,
cellConfiguration configuration: @escaping UITableViewCellConfiguration<T>) {

self.init(
selectionStyle: selectionStyle,
dataSource: dataSource,
tableViewStyle: tableViewStyle,
cellType: .basic,
cellConfiguration: configuration
)
}

convenience public init(
selectionStyle: SelectionStyle,
dataSource: DataSource<T>,
tableViewStyle: UITableView.Style = .plain,
cellType: CellType,
cellConfiguration configuration: @escaping UITableViewCellConfiguration<T>) {

self.init()

// data source
let selectionDataSource = RSSelectionMenuDataSource<T>(dataSource: dataSource, forCellType: cellType, cellConfiguration: configuration)
let selectionDataSource = RSSelectionMenuDataSource<T>(
dataSource: dataSource,
forCellType: cellType,
cellConfiguration: configuration
)

// delegate
let selectionDelegate = RSSelectionMenuDelegate<T>(selectedItems: [])

// initilize tableview
self.tableView = RSSelectionTableView<T>(selectionStyle: selectionStyle, cellType: cellType, dataSource: selectionDataSource, delegate: selectionDelegate, from: self)
self.tableView = RSSelectionTableView<T>(
selectionStyle: selectionStyle,
tableViewStyle: tableViewStyle,
cellType: cellType,
dataSource: selectionDataSource,
delegate: selectionDelegate,
from: self
)
}

// MARK: - Life Cycle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ open class RSSelectionMenuDelegate<T: Equatable>: NSObject, UITableViewDelegate
}

public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return self.isSearchBarAdded(tableView).0 ? defaultHeaderHeight : 1
let height: CGFloat = [UITableView.Style.plain, .grouped].contains(tableView.style) ? 1.0 : 24.0
return self.isSearchBarAdded(tableView).0 ? defaultHeaderHeight : height
}
}

Expand Down
15 changes: 13 additions & 2 deletions RSSelectionMenu/RSSelectionMenu/Source/RSSelectionTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,19 @@ open class RSSelectionTableView<T: Equatable>: UITableView {

// MARK: - Life Cycle

convenience public init(selectionStyle: SelectionStyle, cellType: CellType, dataSource: RSSelectionMenuDataSource<T>, delegate: RSSelectionMenuDelegate<T>, from: RSSelectionMenu<T>) {
self.init()
convenience public init(
selectionStyle: SelectionStyle,
tableViewStyle: UITableView.Style,
cellType: CellType,
dataSource: RSSelectionMenuDataSource<T>,
delegate: RSSelectionMenuDelegate<T>,
from: RSSelectionMenu<T>) {

if #available(iOS 13.0, *) {
self.init(frame: .zero, style: tableViewStyle)
} else {
self.init()
}

self.selectionDataSource = dataSource
self.selectionDelegate = delegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ extension ViewController {
// Cell configuration following parameters.
// 1. UITableViewCell 2. Item of type T 3. IndexPath

let selectionMenu = RSSelectionMenu(dataSource: simpleDataArray) { (cell, item, indexPath) in
var tableViewStyle: UITableView.Style = .plain
if #available(iOS 13.0, *) {
tableViewStyle = UITableView.Style.insetGrouped
}

let selectionMenu = RSSelectionMenu(dataSource: simpleDataArray, tableViewStyle: tableViewStyle) { (cell, item, indexPath) in
cell.textLabel?.text = item
}

Expand Down Expand Up @@ -151,7 +156,7 @@ extension ViewController {
menu.cellSelectionStyle = self.cellSelectionStyle

// show as Popover
menu.show(style: .popover(sourceView: sender, size: nil), from: self)
menu.show(style: .popover(sourceView: sender, size: nil, arrowDirection: .down, hideNavBar: true), from: self)
}


Expand Down

0 comments on commit 1783c2b

Please sign in to comment.