@@ -32,8 +32,6 @@ protocol ChatLayoutRepresentation: AnyObject {
32
32
33
33
func configuration( for element: ItemKind , at itemPath: ItemPath ) -> ItemModel . Configuration
34
34
35
- func alignment( for element: ItemKind , at itemPath: ItemPath ) -> ChatItemAlignment
36
-
37
35
func shouldPresentHeader( at sectionIndex: Int ) -> Bool
38
36
39
37
func shouldPresentFooter( at sectionIndex: Int ) -> Bool
@@ -401,6 +399,16 @@ final class StateController {
401
399
}
402
400
403
401
func process( changeItems: [ ChangeItem ] ) {
402
+ func applyConfiguration( _ configuration: ItemModel . Configuration , to item: inout ItemModel ) {
403
+ item. alignment = configuration. alignment
404
+ if let calculatedSize = configuration. calculatedSize {
405
+ item. calculatedSize = calculatedSize
406
+ item. calculatedOnce = true
407
+ } else {
408
+ item. resetSize ( )
409
+ }
410
+ }
411
+
404
412
batchUpdateCompensatingOffset = 0
405
413
proposedCompensatingOffset = 0
406
414
let changeItems = changeItems. sorted ( )
@@ -451,11 +459,10 @@ final class StateController {
451
459
var header : ItemModel ?
452
460
if layoutRepresentation. shouldPresentHeader ( at: sectionIndex) == true {
453
461
let headerIndexPath = IndexPath ( item: 0 , section: sectionIndex)
454
- header = section. header ?? ItemModel ( with: layoutRepresentation. configuration ( for: . header, at: headerIndexPath. itemPath) )
455
- header? . resetSize ( )
456
- if section. header != nil {
457
- header? . alignment = layoutRepresentation. alignment ( for: . cell, at: headerIndexPath. itemPath)
458
- }
462
+ var newHeader = section. header ?? ItemModel ( with: layoutRepresentation. configuration ( for: . header, at: headerIndexPath. itemPath) )
463
+ let configuration = layoutRepresentation. configuration ( for: . header, at: headerIndexPath. itemPath)
464
+ applyConfiguration ( configuration, to: & newHeader)
465
+ header = newHeader
459
466
} else {
460
467
header = nil
461
468
}
@@ -464,11 +471,10 @@ final class StateController {
464
471
var footer : ItemModel ?
465
472
if layoutRepresentation. shouldPresentFooter ( at: sectionIndex) == true {
466
473
let footerIndexPath = IndexPath ( item: 0 , section: sectionIndex)
467
- footer = section. footer ?? ItemModel ( with: layoutRepresentation. configuration ( for: . footer, at: footerIndexPath. itemPath) )
468
- footer? . resetSize ( )
469
- if section. footer != nil {
470
- footer? . alignment = layoutRepresentation. alignment ( for: . cell, at: footerIndexPath. itemPath)
471
- }
474
+ var newFooter = section. footer ?? ItemModel ( with: layoutRepresentation. configuration ( for: . footer, at: footerIndexPath. itemPath) )
475
+ let configuration = layoutRepresentation. configuration ( for: . footer, at: footerIndexPath. itemPath)
476
+ applyConfiguration ( configuration, to: & newFooter)
477
+ footer = newFooter
472
478
} else {
473
479
footer = nil
474
480
}
@@ -480,11 +486,11 @@ final class StateController {
480
486
let itemIndexPath = IndexPath ( item: index, section: sectionIndex)
481
487
if index < oldItems. count {
482
488
newItem = oldItems [ index]
483
- newItem. alignment = layoutRepresentation. alignment ( for: . cell, at: itemIndexPath. itemPath)
489
+ let configuration = layoutRepresentation. configuration ( for: . cell, at: itemIndexPath. itemPath)
490
+ applyConfiguration ( configuration, to: & newItem)
484
491
} else {
485
492
newItem = ItemModel ( with: layoutRepresentation. configuration ( for: . cell, at: itemIndexPath. itemPath) )
486
493
}
487
- newItem. resetSize ( )
488
494
return newItem
489
495
}
490
496
section. set ( items: ContiguousArray ( items) )
@@ -495,8 +501,8 @@ final class StateController {
495
501
assertionFailure ( " Item at index path ( \( indexPath. section) - \( indexPath. item) ) does not exist. " )
496
502
return
497
503
}
498
- item . resetSize ( )
499
- item . alignment = layoutRepresentation . alignment ( for : . cell , at : indexPath . itemPath )
504
+ let configuration = layoutRepresentation . configuration ( for : . cell , at : indexPath . itemPath )
505
+ applyConfiguration ( configuration , to : & item )
500
506
afterUpdateModel. replaceItem ( item, at: indexPath)
501
507
reloadedIndexes. insert ( indexPath)
502
508
case let . sectionMove( initialSectionIndex: initialSectionIndex, finalSectionIndex: finalSectionIndex) :
0 commit comments