@@ -89,6 +89,8 @@ final class StateController<Layout: ChatLayoutRepresentation> {
89
89
90
90
private( set) var reloadedIndexes : Set < IndexPath > = [ ]
91
91
92
+ private( set) var reconfiguredIndexes : Set < IndexPath > = [ ]
93
+
92
94
private( set) var insertedIndexes : Set < IndexPath > = [ ]
93
95
94
96
private( set) var movedIndexes : Set < IndexPath > = [ ]
@@ -238,6 +240,7 @@ final class StateController<Layout: ChatLayoutRepresentation> {
238
240
attributes. indexPath = itemIndexPath
239
241
attributes. zIndex = 10
240
242
attributes. alignment = item. alignment
243
+ attributes. interItemSpacing = item. interItemSpacing
241
244
case . footer:
242
245
guard itemPath. section < layout. sections. count,
243
246
itemPath. item == 0 else {
@@ -265,6 +268,7 @@ final class StateController<Layout: ChatLayoutRepresentation> {
265
268
attributes. indexPath = itemIndexPath
266
269
attributes. zIndex = 10
267
270
attributes. alignment = item. alignment
271
+ attributes. interItemSpacing = item. interItemSpacing
268
272
case . cell:
269
273
guard itemPath. section < layout. sections. count,
270
274
itemPath. item < layout. sections [ itemPath. section] . items. count else {
@@ -292,6 +296,7 @@ final class StateController<Layout: ChatLayoutRepresentation> {
292
296
attributes. indexPath = itemIndexPath
293
297
attributes. zIndex = 0
294
298
attributes. alignment = item. alignment
299
+ attributes. interItemSpacing = item. interItemSpacing
295
300
}
296
301
attributes. viewSize = additionalAttributes. viewSize
297
302
attributes. adjustedContentInsets = additionalAttributes. adjustedContentInsets
@@ -489,6 +494,7 @@ final class StateController<Layout: ChatLayoutRepresentation> {
489
494
func process( changeItems: [ ChangeItem ] ) {
490
495
func applyConfiguration( _ configuration: ItemModel . Configuration , to item: inout ItemModel ) {
491
496
item. alignment = configuration. alignment
497
+ item. interItemSpacing = configuration. interItemSpacing
492
498
if let calculatedSize = configuration. calculatedSize {
493
499
item. calculatedSize = calculatedSize
494
500
item. calculatedOnce = true
@@ -600,6 +606,15 @@ final class StateController<Layout: ChatLayoutRepresentation> {
600
606
applyConfiguration ( configuration, to: & item)
601
607
afterUpdateModel. replaceItem ( item, at: indexPath)
602
608
reloadedIndexes. insert ( indexPath)
609
+ case let . itemReconfigure( itemIndexPath: indexPath) :
610
+ guard var item = item ( for: indexPath. itemPath, kind: . cell, at: . beforeUpdate) else {
611
+ assertionFailure ( " Item at index path ( \( indexPath. section) - \( indexPath. item) ) does not exist. " )
612
+ return
613
+ }
614
+ let configuration = layoutRepresentation. configuration ( for: . cell, at: indexPath)
615
+ applyConfiguration ( configuration, to: & item)
616
+ afterUpdateModel. replaceItem ( item, at: indexPath)
617
+ reconfiguredIndexes. insert ( indexPath)
603
618
case let . sectionMove( initialSectionIndex: initialSectionIndex, finalSectionIndex: finalSectionIndex) :
604
619
let section = layoutBeforeUpdate. sections [ initialSectionIndex]
605
620
movedSectionsIndexes. insert ( finalSectionIndex)
@@ -671,6 +686,22 @@ final class StateController<Layout: ChatLayoutRepresentation> {
671
686
newSpacing: newItem. interItemSpacing) ,
672
687
visibleBounds: visibleBounds)
673
688
}
689
+ reconfiguredIndexes. sorted ( by: { $0 < $1 } ) . forEach {
690
+ let newItemPath = $0. itemPath
691
+ guard let oldItem = item ( for: newItemPath, kind: . cell, at: . beforeUpdate) ,
692
+ let newItemIndexPath = itemPath ( by: oldItem. id, kind: . cell, at: . afterUpdate) ,
693
+ let newItem = item ( for: newItemIndexPath, kind: . cell, at: . afterUpdate) else {
694
+ assertionFailure ( " Internal inconsistency. " )
695
+ return
696
+ }
697
+ compensateOffsetIfNeeded ( for: newItemPath,
698
+ kind: . cell,
699
+ action: . frameUpdate( previousFrame: oldItem. frame,
700
+ newFrame: newItem. frame,
701
+ previousSpacing: oldItem. interItemSpacing,
702
+ newSpacing: newItem. interItemSpacing) ,
703
+ visibleBounds: visibleBounds)
704
+ }
674
705
insertedIndexes. sorted ( by: { $0 < $1 } ) . forEach {
675
706
let itemPath = $0. itemPath
676
707
guard let item = item ( for: itemPath, kind: . cell, at: . afterUpdate) else {
@@ -702,6 +733,7 @@ final class StateController<Layout: ChatLayoutRepresentation> {
702
733
insertedSectionsIndexes = [ ]
703
734
704
735
reloadedIndexes = [ ]
736
+ reconfiguredIndexes = [ ]
705
737
reloadedSectionsIndexes = [ ]
706
738
707
739
movedIndexes = [ ]
0 commit comments