@@ -283,38 +283,43 @@ class GridContentView: UIScrollView {
283
283
recalculateCellBounds ( )
284
284
}
285
285
286
- private func recalculateCellBounds( ) {
286
+ private func recalculateCellBounds( initiatingCell : GridCell ? = nil ) {
287
287
frozenRowsConstraints. forEach { $0. isActive = false }
288
288
frozenColumnsConstraints. forEach { $0. isActive = false }
289
289
removeConstraints ( frozenRowsConstraints + frozenColumnsConstraints)
290
290
291
- for c in grid. cells. reversed ( ) {
291
+ var cells = grid. cells
292
+ if let initiatingCell {
293
+ cells = [ initiatingCell]
294
+ }
295
+
296
+ for cell in cells {
292
297
// TODO: Optimize to recalculate frames for affected cells only i.e. row>=current
293
298
294
299
// Set the frame of the cell before adding to superview
295
300
// This is required to avoid breaking layout constraints
296
301
// as default size is 0
297
- let frame = grid. frameForCell ( c , basedOn: bounds. size)
298
- c . frame = frame
299
- c . contentView. frame = frame
300
- c . widthAnchorConstraint. constant = frame. width
301
- c . heightAnchorConstraint. constant = frame. height
302
+ let frame = grid. frameForCell ( cell , basedOn: bounds. size)
303
+ cell . frame = frame
304
+ cell . contentView. frame = frame
305
+ cell . widthAnchorConstraint. constant = frame. width
306
+ cell . heightAnchorConstraint. constant = frame. height
302
307
303
308
// Add to grid if this is a newly inserted cell after initial setup.
304
309
// A new cell may exist as a result of inserting a new row/column
305
310
// or splitting an existing merged cell
306
- if c . contentView. superview == nil {
307
- addSubview ( c . contentView)
308
- c . topAnchorConstraint = c . contentView. topAnchor. constraint ( equalTo: topAnchor, constant: frame. minY)
309
- c . leadingAnchorConstraint = c . contentView. leadingAnchor. constraint ( equalTo: leadingAnchor, constant: frame. minX)
311
+ if cell . contentView. superview == nil {
312
+ addSubview ( cell . contentView)
313
+ cell . topAnchorConstraint = cell . contentView. topAnchor. constraint ( equalTo: topAnchor, constant: frame. minY)
314
+ cell . leadingAnchorConstraint = cell . contentView. leadingAnchor. constraint ( equalTo: leadingAnchor, constant: frame. minX)
310
315
} else {
311
- c . topAnchorConstraint? . constant = frame. minY
312
- c . leadingAnchorConstraint? . constant = frame. minX
316
+ cell . topAnchorConstraint? . constant = frame. minY
317
+ cell . leadingAnchorConstraint? . constant = frame. minX
313
318
}
314
319
315
- freezeColumnCellIfRequired ( c )
316
- freezeRowCellIfRequired ( c )
317
- gridContentViewDelegate? . gridContentView ( self , didLayoutCell: c )
320
+ freezeColumnCellIfRequired ( cell )
321
+ freezeRowCellIfRequired ( cell )
322
+ gridContentViewDelegate? . gridContentView ( self , didLayoutCell: cell )
318
323
}
319
324
320
325
boundsObserver? . didChangeBounds ( CGRect ( origin: bounds. origin, size: frame. size) , oldBounds: bounds)
@@ -404,7 +409,7 @@ extension GridContentView: GridCellDelegate {
404
409
grid. rowHeights [ row] . currentHeight = grid. maxContentHeightCellForRow ( at: row) ? . contentSize. height ?? 0
405
410
}
406
411
407
- recalculateCellBounds ( )
412
+ recalculateCellBounds ( initiatingCell : cell )
408
413
gridContentViewDelegate? . gridContentView ( self , didChangeBounds: cell. frame, in: cell)
409
414
}
410
415
0 commit comments