Skip to content

Commit 4fadb85

Browse files
authored
Merge pull request #16 from thefuntasty/feature/platform-independent-height
Use double for platform independent cell sizes
2 parents 3b6870c + 4cc660d commit 4fadb85

3 files changed

Lines changed: 10 additions & 12 deletions

File tree

Example/Headers/PhonesHeaderModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct PhonesHeaderModel {
1717
extension PhonesHeaderModel: SupplementaryViewModel, CellConvertible {
1818
typealias Cell = PhonesHeader
1919

20-
var height: CGFloat {
20+
var height: Double {
2121
return 50
2222
}
2323
}

Sources/CellModel.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,17 @@
66
// Copyright © 2018 FUNTASTY Digital, s.r.o. All rights reserved.
77
//
88

9-
import struct UIKit.CGFloat
10-
import class Foundation.Bundle
11-
import class UIKit.UINib
12-
139
public protocol CellModel: ReusableView {
14-
var cellHeight: CGFloat { get }
10+
var cellHeight: Double { get }
1511
var highlighting: Bool { get }
1612
var separatorIsHidden: Bool { get }
1713

1814
func configure(cell: AnyObject)
1915
}
2016

2117
public extension CellModel {
22-
var cellHeight: CGFloat {
23-
return 44
18+
var cellHeight: Double {
19+
return 44.0
2420
}
2521

2622
var highlighting: Bool {
@@ -33,7 +29,7 @@ public extension CellModel {
3329
}
3430

3531
public protocol SupplementaryViewModel: ReusableView {
36-
var height: CGFloat { get }
32+
var height: Double { get }
3733

3834
func configure(cell: AnyObject)
3935
}

Sources/DataSource.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ extension AbstractDataSource: UITableViewDataSource {
127127
}
128128

129129
public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
130-
return header(in: section)?.height ?? CGFloat.leastNonzeroMagnitude
130+
let height = header(in: section)?.height
131+
return height.flatMap { CGFloat($0) } ?? CGFloat.leastNonzeroMagnitude
131132
}
132133

133134
public func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
@@ -138,7 +139,8 @@ extension AbstractDataSource: UITableViewDataSource {
138139
}
139140

140141
public func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
141-
return footer(in: section)?.height ?? CGFloat.leastNonzeroMagnitude
142+
let height = footer(in: section)?.height
143+
return height.flatMap { CGFloat($0) } ?? CGFloat.leastNonzeroMagnitude
142144
}
143145
}
144146

@@ -162,7 +164,7 @@ extension AbstractDataSource: UICollectionViewDataSource {
162164

163165
extension AbstractDataSource: UITableViewDelegate {
164166
public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
165-
return cellModel(at: indexPath).cellHeight
167+
return CGFloat(cellModel(at: indexPath).cellHeight)
166168
}
167169

168170
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

0 commit comments

Comments
 (0)