@@ -24,11 +24,18 @@ import UIKit
24
24
25
25
class GridRowDimension {
26
26
var currentHeight : CGFloat
27
+ var isCollapsed : Bool
27
28
let rowConfiguration : GridRowConfiguration
28
29
29
- init ( rowConfiguration: GridRowConfiguration ) {
30
+ var calculatedHeight : CGFloat {
31
+ guard !isCollapsed else { return 2 }
32
+ return currentHeight
33
+ }
34
+
35
+ init ( rowConfiguration: GridRowConfiguration , isCollapsed: Bool = false ) {
30
36
self . rowConfiguration = rowConfiguration
31
37
currentHeight = rowConfiguration. initialHeight
38
+ self . isCollapsed = isCollapsed
32
39
}
33
40
}
34
41
@@ -46,7 +53,7 @@ class Grid {
46
53
weak var delegate : GridDelegate ?
47
54
48
55
var currentRowHeights : [ CGFloat ] {
49
- rowHeights. map { $0. currentHeight }
56
+ rowHeights. map { $0. calculatedHeight }
50
57
}
51
58
52
59
var cells : [ GridCell ] {
@@ -65,7 +72,7 @@ class Grid {
65
72
self . config = config
66
73
67
74
for column in config. columnsConfiguration {
68
- self . columnWidths. append ( column. dimension )
75
+ self . columnWidths. append ( GridColumnDimension ( width : column. width ) )
69
76
}
70
77
71
78
for row in config. rowsConfiguration {
@@ -152,7 +159,7 @@ class Grid {
152
159
let proposedWidth = columnWidths [ index] . value ( basedOn: totalWidth) + delta
153
160
guard index < columnWidths. count,
154
161
delegate? . grid ( self , shouldChangeColumnWidth: proposedWidth, for: index) ?? true else { return }
155
- columnWidths [ index] = . fixed( columnWidths [ index] . value ( basedOn: totalWidth) + delta)
162
+ columnWidths [ index] . width = . fixed( columnWidths [ index] . value ( basedOn: totalWidth) + delta)
156
163
}
157
164
158
165
func changeRowHeight( index: Int , delta: CGFloat ) {
@@ -271,7 +278,7 @@ class Grid {
271
278
if sanitizedIndex < numberOfColumns {
272
279
cellStore. moveCellColumnIndex ( from: sanitizedIndex, by: 1 )
273
280
}
274
- columnWidths. insert ( config. dimension , at: sanitizedIndex)
281
+ columnWidths. insert ( GridColumnDimension ( width : config. width ) , at: sanitizedIndex)
275
282
276
283
var cells = [ GridCell] ( )
277
284
for r in 0 ..< numberOfRows {
@@ -347,6 +354,41 @@ class Grid {
347
354
}
348
355
349
356
}
357
+
358
+ func collapseRow( at index: Int ) {
359
+ rowHeights [ index] . isCollapsed = true
360
+ }
361
+
362
+ func expandRow( at index: Int ) {
363
+ rowHeights [ index] . isCollapsed = false
364
+ }
365
+
366
+ func collapseColumn( at index: Int ) {
367
+ columnWidths [ index] . isCollapsed = true
368
+ // Hide editor failing which resizing column ends up elongating column based on content in cell
369
+ cells. forEach {
370
+ if $0. columnSpan. contains ( index) {
371
+ $0. hideEditor ( )
372
+ }
373
+ }
374
+ }
375
+
376
+ func expandColumn( at index: Int ) {
377
+ columnWidths [ index] . isCollapsed = false
378
+ cells. forEach {
379
+ if $0. columnSpan. contains ( index) {
380
+ $0. showEditor ( )
381
+ }
382
+ }
383
+ }
384
+
385
+ func getCollapsedRowIndices( ) -> [ Int ] {
386
+ return rowHeights. indices. filter { rowHeights [ $0] . isCollapsed }
387
+ }
388
+
389
+ func getCollapsedColumnIndices( ) -> [ Int ] {
390
+ return columnWidths. indices. filter { columnWidths [ $0] . isCollapsed }
391
+ }
350
392
}
351
393
352
394
public enum GridViewError : Error {
0 commit comments