@@ -35,12 +35,12 @@ import UIKit
35
35
/// `CollectionViewChatLayout.getContentOffsetSnapshot(...)`
36
36
///
37
37
/// `CollectionViewChatLayout.restoreContentOffset(...)`
38
- public final class CollectionViewChatLayout : UICollectionViewLayout {
38
+ open class CollectionViewChatLayout : UICollectionViewLayout {
39
39
40
40
// MARK: Custom Properties
41
41
42
42
/// `CollectionViewChatLayout` delegate.
43
- public weak var delegate : ChatLayoutDelegate ?
43
+ open weak var delegate : ChatLayoutDelegate ?
44
44
45
45
/// Additional settings for `CollectionViewChatLayout`.
46
46
public var settings = ChatLayoutSettings ( ) {
@@ -72,7 +72,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
72
72
public var processOnlyVisibleItemsOnAnimatedBatchUpdates : Bool = true
73
73
74
74
/// Represent the currently visible rectangle.
75
- public var visibleBounds : CGRect {
75
+ open var visibleBounds : CGRect {
76
76
guard let collectionView else {
77
77
return . zero
78
78
}
@@ -83,7 +83,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
83
83
}
84
84
85
85
/// Represent the rectangle where all the items are aligned.
86
- public var layoutFrame : CGRect {
86
+ open var layoutFrame : CGRect {
87
87
guard let collectionView else {
88
88
return . zero
89
89
}
@@ -97,12 +97,12 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
97
97
// MARK: Inherited Properties
98
98
99
99
/// The direction of the language you used when designing `CollectionViewChatLayout` layout.
100
- public override var developmentLayoutDirection : UIUserInterfaceLayoutDirection {
100
+ open override var developmentLayoutDirection : UIUserInterfaceLayoutDirection {
101
101
. leftToRight
102
102
}
103
103
104
104
/// A Boolean value that indicates whether the horizontal coordinate system is automatically flipped at appropriate times.
105
- public override var flipsHorizontallyInOppositeLayoutDirection : Bool {
105
+ open override var flipsHorizontallyInOppositeLayoutDirection : Bool {
106
106
_flipsHorizontallyInOppositeLayoutDirection
107
107
}
108
108
@@ -117,7 +117,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
117
117
}
118
118
119
119
/// The width and height of the collection view’s contents.
120
- public override var collectionViewContentSize : CGSize {
120
+ open override var collectionViewContentSize : CGSize {
121
121
let contentSize : CGSize
122
122
if state == . beforeUpdate {
123
123
contentSize = controller. contentSize ( for: . beforeUpdate)
@@ -243,7 +243,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
243
243
/// Get current offset of the item closest to the provided edge.
244
244
/// - Parameter edge: The edge of the `UICollectionView`
245
245
/// - Returns: `ChatLayoutPositionSnapshot`
246
- public func getContentOffsetSnapshot( from edge: ChatLayoutPositionSnapshot . Edge ) -> ChatLayoutPositionSnapshot ? {
246
+ open func getContentOffsetSnapshot( from edge: ChatLayoutPositionSnapshot . Edge ) -> ChatLayoutPositionSnapshot ? {
247
247
guard let collectionView else {
248
248
return nil
249
249
}
@@ -281,7 +281,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
281
281
282
282
/// Invalidates layout of the `UICollectionView` and trying to keep the offset of the item provided in `ChatLayoutPositionSnapshot`
283
283
/// - Parameter snapshot: `ChatLayoutPositionSnapshot`
284
- public func restoreContentOffset( with snapshot: ChatLayoutPositionSnapshot ) {
284
+ open func restoreContentOffset( with snapshot: ChatLayoutPositionSnapshot ) {
285
285
guard let collectionView else {
286
286
return
287
287
}
@@ -307,14 +307,14 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
307
307
///
308
308
/// NB: Reconfigure items is not exposed to the layout, it may behave strange and if you experience something like
309
309
/// this - move to the `UICollectionView.reloadItems(..)` as a safer option.
310
- public func reconfigureItems( at indexPaths: [ IndexPath ] ) {
310
+ open func reconfigureItems( at indexPaths: [ IndexPath ] ) {
311
311
reconfigureItemsIndexPaths = indexPaths
312
312
}
313
313
314
314
// MARK: Providing Layout Attributes
315
315
316
316
/// Tells the layout object to update the current layout.
317
- public override func prepare( ) {
317
+ open override func prepare( ) {
318
318
super. prepare ( )
319
319
320
320
guard let collectionView,
@@ -420,7 +420,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
420
420
}
421
421
422
422
/// Retrieves the layout attributes for all of the cells and views in the specified rectangle.
423
- public override func layoutAttributesForElements( in rect: CGRect ) -> [ UICollectionViewLayoutAttributes ] ? {
423
+ open override func layoutAttributesForElements( in rect: CGRect ) -> [ UICollectionViewLayoutAttributes ] ? {
424
424
// This early return prevents an issue that causes overlapping / misplaced elements after an
425
425
// off-screen batch update occurs. The root cause of this issue is that `UICollectionView`
426
426
// expects `layoutAttributesForElementsInRect:` to return post-batch-update layout attributes
@@ -452,7 +452,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
452
452
}
453
453
454
454
/// Retrieves layout information for an item at the specified index path with a corresponding cell.
455
- public override func layoutAttributesForItem( at indexPath: IndexPath ) -> UICollectionViewLayoutAttributes ? {
455
+ open override func layoutAttributesForItem( at indexPath: IndexPath ) -> UICollectionViewLayoutAttributes ? {
456
456
guard !dontReturnAttributes else {
457
457
return nil
458
458
}
@@ -462,8 +462,8 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
462
462
}
463
463
464
464
/// Retrieves the layout attributes for the specified supplementary view.
465
- public override func layoutAttributesForSupplementaryView( ofKind elementKind: String ,
466
- at indexPath: IndexPath ) -> UICollectionViewLayoutAttributes ? {
465
+ open override func layoutAttributesForSupplementaryView( ofKind elementKind: String ,
466
+ at indexPath: IndexPath ) -> UICollectionViewLayoutAttributes ? {
467
467
guard !dontReturnAttributes else {
468
468
return nil
469
469
}
@@ -477,7 +477,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
477
477
// MARK: Coordinating Animated Changes
478
478
479
479
/// Prepares the layout object for animated changes to the view’s bounds or the insertion or deletion of items.
480
- public override func prepare( forAnimatedBoundsChange oldBounds: CGRect ) {
480
+ open override func prepare( forAnimatedBoundsChange oldBounds: CGRect ) {
481
481
controller. isAnimatedBoundsChange = true
482
482
controller. process ( changeItems: [ ] )
483
483
state = . afterUpdate
@@ -494,7 +494,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
494
494
}
495
495
496
496
/// Cleans up after any animated changes to the view’s bounds or after the insertion or deletion of items.
497
- public override func finalizeAnimatedBoundsChange( ) {
497
+ open override func finalizeAnimatedBoundsChange( ) {
498
498
if controller. isAnimatedBoundsChange {
499
499
state = . beforeUpdate
500
500
resetInvalidatedAttributes ( )
@@ -509,8 +509,8 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
509
509
// MARK: Context Invalidation
510
510
511
511
/// Asks the layout object if changes to a self-sizing cell require a layout update.
512
- public override func shouldInvalidateLayout( forPreferredLayoutAttributes preferredAttributes: UICollectionViewLayoutAttributes ,
513
- withOriginalAttributes originalAttributes: UICollectionViewLayoutAttributes ) -> Bool {
512
+ open override func shouldInvalidateLayout( forPreferredLayoutAttributes preferredAttributes: UICollectionViewLayoutAttributes ,
513
+ withOriginalAttributes originalAttributes: UICollectionViewLayoutAttributes ) -> Bool {
514
514
let preferredAttributesItemPath = preferredAttributes. indexPath. itemPath
515
515
guard let preferredMessageAttributes = preferredAttributes as? ChatLayoutAttributes ,
516
516
let item = controller. item ( for: preferredAttributesItemPath, kind: preferredMessageAttributes. kind, at: state) else {
@@ -523,8 +523,8 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
523
523
}
524
524
525
525
/// Retrieves a context object that identifies the portions of the layout that should change in response to dynamic cell changes.
526
- public override func invalidationContext( forPreferredLayoutAttributes preferredAttributes: UICollectionViewLayoutAttributes ,
527
- withOriginalAttributes originalAttributes: UICollectionViewLayoutAttributes ) -> UICollectionViewLayoutInvalidationContext {
526
+ open override func invalidationContext( forPreferredLayoutAttributes preferredAttributes: UICollectionViewLayoutAttributes ,
527
+ withOriginalAttributes originalAttributes: UICollectionViewLayoutAttributes ) -> UICollectionViewLayoutInvalidationContext {
528
528
guard let preferredMessageAttributes = preferredAttributes as? ChatLayoutAttributes else {
529
529
return super. invalidationContext ( forPreferredLayoutAttributes: preferredAttributes, withOriginalAttributes: originalAttributes)
530
530
}
@@ -601,7 +601,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
601
601
}
602
602
603
603
/// Asks the layout object if the new bounds require a layout update.
604
- public override func shouldInvalidateLayout( forBoundsChange newBounds: CGRect ) -> Bool {
604
+ open override func shouldInvalidateLayout( forBoundsChange newBounds: CGRect ) -> Bool {
605
605
let shouldInvalidateLayout = cachedCollectionViewSize != . some( newBounds. size) ||
606
606
cachedCollectionViewInset != . some( adjustedContentInset) ||
607
607
invalidationActions. contains ( . shouldInvalidateOnBoundsChange)
@@ -611,14 +611,14 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
611
611
}
612
612
613
613
/// Retrieves a context object that defines the portions of the layout that should change when a bounds change occurs.
614
- public override func invalidationContext( forBoundsChange newBounds: CGRect ) -> UICollectionViewLayoutInvalidationContext {
614
+ open override func invalidationContext( forBoundsChange newBounds: CGRect ) -> UICollectionViewLayoutInvalidationContext {
615
615
let invalidationContext = super. invalidationContext ( forBoundsChange: newBounds) as! ChatLayoutInvalidationContext
616
616
invalidationContext. invalidateLayoutMetrics = false
617
617
return invalidationContext
618
618
}
619
619
620
620
/// Invalidates the current layout using the information in the provided context object.
621
- public override func invalidateLayout( with context: UICollectionViewLayoutInvalidationContext ) {
621
+ open override func invalidateLayout( with context: UICollectionViewLayoutInvalidationContext ) {
622
622
guard let collectionView else {
623
623
super. invalidateLayout ( with: context)
624
624
return
@@ -672,12 +672,12 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
672
672
}
673
673
674
674
/// Invalidates the current layout and triggers a layout update.
675
- public override func invalidateLayout( ) {
675
+ open override func invalidateLayout( ) {
676
676
super. invalidateLayout ( )
677
677
}
678
678
679
679
/// Retrieves the content offset to use after an animated layout update or change.
680
- public override func targetContentOffset( forProposedContentOffset proposedContentOffset: CGPoint ) -> CGPoint {
680
+ open override func targetContentOffset( forProposedContentOffset proposedContentOffset: CGPoint ) -> CGPoint {
681
681
if controller. proposedCompensatingOffset != 0 ,
682
682
let collectionView {
683
683
let minPossibleContentOffset = - collectionView. adjustedContentInset. top
@@ -698,7 +698,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
698
698
// MARK: Responding to Collection View Updates
699
699
700
700
/// Notifies the layout object that the contents of the collection view are about to change.
701
- public override func prepare( forCollectionViewUpdates updateItems: [ UICollectionViewUpdateItem ] ) {
701
+ open override func prepare( forCollectionViewUpdates updateItems: [ UICollectionViewUpdateItem ] ) {
702
702
var changeItems = updateItems. compactMap { ChangeItem ( with: $0) }
703
703
changeItems. append ( contentsOf: reconfigureItemsIndexPaths. map { . itemReconfigure( itemIndexPath: $0) } )
704
704
controller. process ( changeItems: changeItems)
@@ -725,7 +725,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
725
725
}
726
726
727
727
/// Performs any additional animations or clean up needed during a collection view update.
728
- public override func finalizeCollectionViewUpdates( ) {
728
+ open override func finalizeCollectionViewUpdates( ) {
729
729
controller. proposedCompensatingOffset = 0
730
730
731
731
if keepContentOffsetAtBottomOnBatchUpdates,
@@ -755,7 +755,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
755
755
// MARK: - Cell Appearance Animation
756
756
757
757
/// Retrieves the starting layout information for an item being inserted into the collection view.
758
- public override func initialLayoutAttributesForAppearingItem( at itemIndexPath: IndexPath ) -> UICollectionViewLayoutAttributes ? {
758
+ open override func initialLayoutAttributesForAppearingItem( at itemIndexPath: IndexPath ) -> UICollectionViewLayoutAttributes ? {
759
759
var attributes : ChatLayoutAttributes ?
760
760
761
761
let itemPath = itemIndexPath. itemPath
@@ -792,7 +792,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
792
792
}
793
793
794
794
/// Retrieves the final layout information for an item that is about to be removed from the collection view.
795
- public override func finalLayoutAttributesForDisappearingItem( at itemIndexPath: IndexPath ) -> UICollectionViewLayoutAttributes ? {
795
+ open override func finalLayoutAttributesForDisappearingItem( at itemIndexPath: IndexPath ) -> UICollectionViewLayoutAttributes ? {
796
796
var attributes : ChatLayoutAttributes ?
797
797
798
798
let itemPath = itemIndexPath. itemPath
@@ -843,8 +843,8 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
843
843
// MARK: - Supplementary View Appearance Animation
844
844
845
845
/// Retrieves the starting layout information for a supplementary view being inserted into the collection view.
846
- public override func initialLayoutAttributesForAppearingSupplementaryElement( ofKind elementKind: String ,
847
- at elementIndexPath: IndexPath ) -> UICollectionViewLayoutAttributes ? {
846
+ open override func initialLayoutAttributesForAppearingSupplementaryElement( ofKind elementKind: String ,
847
+ at elementIndexPath: IndexPath ) -> UICollectionViewLayoutAttributes ? {
848
848
var attributes : ChatLayoutAttributes ?
849
849
850
850
let kind = ItemKind ( elementKind)
@@ -883,8 +883,8 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
883
883
}
884
884
885
885
/// Retrieves the final layout information for a supplementary view that is about to be removed from the collection view.
886
- public override func finalLayoutAttributesForDisappearingSupplementaryElement( ofKind elementKind: String ,
887
- at elementIndexPath: IndexPath ) -> UICollectionViewLayoutAttributes ? {
886
+ open override func finalLayoutAttributesForDisappearingSupplementaryElement( ofKind elementKind: String ,
887
+ at elementIndexPath: IndexPath ) -> UICollectionViewLayoutAttributes ? {
888
888
var attributes : ChatLayoutAttributes ?
889
889
890
890
let kind = ItemKind ( elementKind)
0 commit comments