Skip to content

Commit 9b47f7d

Browse files
committed
refactor
1 parent 6eef3ad commit 9b47f7d

4 files changed

Lines changed: 18 additions & 20 deletions

File tree

Source/OriginalRow.swift

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,17 @@ class OriginalRow {
1111
self.originalIndexPath = originalIndexPath
1212
}
1313

14-
var hiddenReal: Bool = false
14+
var hidden: Bool = false
1515

16-
var hiddenPlanned: Bool = false
16+
var hiding: Bool = false {
17+
willSet {
18+
if !hidden && newValue {
19+
batchOperation = .delete
20+
} else if hidden && !newValue {
21+
batchOperation = .insert
22+
}
23+
}
24+
}
1725

1826
var batchOperation: BatchOperation = .none
1927

@@ -24,19 +32,9 @@ class OriginalRow {
2432
var height: CGFloat = CGFloat.greatestFiniteMagnitude
2533

2634
func update() {
27-
if !hiddenPlanned && batchOperation == .none {
35+
if !hiding && batchOperation == .none {
2836
batchOperation = .update
2937
}
3038
}
3139

32-
func set(hidden: Bool) {
33-
if !hiddenReal && hidden {
34-
batchOperation = .delete
35-
} else if hiddenReal && !hidden {
36-
batchOperation = .insert
37-
}
38-
39-
hiddenPlanned = hidden
40-
}
41-
4240
}

Source/OriginalSection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class OriginalSection {
55
var rows: [OriginalRow] = []
66

77
func numberOfVissibleRows() -> Int {
8-
return rows.filter { !$0.hiddenPlanned }.count
8+
return rows.filter { !$0.hiding }.count
99
}
1010

1111
}

Source/OriginalTable.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class OriginalTable {
6060

6161
func vissibleOriginalRowWithIndexPath(_ indexPath: IndexPath) -> OriginalRow {
6262
let section = sections[indexPath.section]
63-
let visibleRows = section.rows.filter { !$0.hiddenPlanned }
63+
let visibleRows = section.rows.filter { !$0.hiding }
6464

6565
return visibleRows[indexPath.row]
6666
}
@@ -76,7 +76,7 @@ class OriginalTable {
7676
var indexRow = originalRow.originalIndexPath.row
7777

7878
let section = sections[indexSection]
79-
indexRow = section.rows[0..<indexRow].filter { !$0.hiddenPlanned }.count
79+
indexRow = section.rows[0..<indexRow].filter { !$0.hiding }.count
8080

8181
return IndexPath(row: indexRow, section: indexSection)
8282
}
@@ -86,7 +86,7 @@ class OriginalTable {
8686
var indexRow = originalRow.originalIndexPath.row
8787

8888
let section = sections[indexSection]
89-
indexRow = section.rows[0..<indexRow].filter { !$0.hiddenReal }.count
89+
indexRow = section.rows[0..<indexRow].filter { !$0.hidden }.count
9090

9191
return IndexPath(row: indexRow, section: indexSection)
9292
}
@@ -112,7 +112,7 @@ class OriginalTable {
112112
}
113113

114114
allRows.forEach { (row) in
115-
row.hiddenReal = row.hiddenPlanned
115+
row.hidden = row.hiding
116116
row.batchOperation = BatchOperation.none
117117
}
118118
}

Source/StaticTableViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ open class StaticTableViewController: UITableViewController, OriginalTableConfig
2626
open func set(cells: UITableViewCell..., hidden: Bool) {
2727
cells.forEach { cell in
2828
let row = originalTable!.originalRowWithTableViewCell(cell)
29-
row.set(hidden: hidden)
29+
row.hiding = hidden
3030
}
3131
}
3232

@@ -38,7 +38,7 @@ open class StaticTableViewController: UITableViewController, OriginalTableConfig
3838
}
3939

4040
open func isHidden(cell: UITableViewCell) -> Bool {
41-
return originalTable!.originalRowWithTableViewCell(cell).hiddenReal
41+
return originalTable!.originalRowWithTableViewCell(cell).hidden
4242
}
4343

4444
open func reloadData(animated: Bool) {

0 commit comments

Comments
 (0)