Skip to content

Commit ec48ea3

Browse files
committed
Made CollectionViewChatLayout open
1 parent fa8bf8b commit ec48ea3

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

ChatLayout/Classes/Core/CollectionViewChatLayout.swift

+34-34
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ import UIKit
3535
/// `CollectionViewChatLayout.getContentOffsetSnapshot(...)`
3636
///
3737
/// `CollectionViewChatLayout.restoreContentOffset(...)`
38-
public final class CollectionViewChatLayout: UICollectionViewLayout {
38+
open class CollectionViewChatLayout: UICollectionViewLayout {
3939

4040
// MARK: Custom Properties
4141

4242
/// `CollectionViewChatLayout` delegate.
43-
public weak var delegate: ChatLayoutDelegate?
43+
open weak var delegate: ChatLayoutDelegate?
4444

4545
/// Additional settings for `CollectionViewChatLayout`.
4646
public var settings = ChatLayoutSettings() {
@@ -72,7 +72,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
7272
public var processOnlyVisibleItemsOnAnimatedBatchUpdates: Bool = true
7373

7474
/// Represent the currently visible rectangle.
75-
public var visibleBounds: CGRect {
75+
open var visibleBounds: CGRect {
7676
guard let collectionView else {
7777
return .zero
7878
}
@@ -83,7 +83,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
8383
}
8484

8585
/// Represent the rectangle where all the items are aligned.
86-
public var layoutFrame: CGRect {
86+
open var layoutFrame: CGRect {
8787
guard let collectionView else {
8888
return .zero
8989
}
@@ -97,12 +97,12 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
9797
// MARK: Inherited Properties
9898

9999
/// The direction of the language you used when designing `CollectionViewChatLayout` layout.
100-
public override var developmentLayoutDirection: UIUserInterfaceLayoutDirection {
100+
open override var developmentLayoutDirection: UIUserInterfaceLayoutDirection {
101101
.leftToRight
102102
}
103103

104104
/// 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 {
106106
_flipsHorizontallyInOppositeLayoutDirection
107107
}
108108

@@ -117,7 +117,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
117117
}
118118

119119
/// The width and height of the collection view’s contents.
120-
public override var collectionViewContentSize: CGSize {
120+
open override var collectionViewContentSize: CGSize {
121121
let contentSize: CGSize
122122
if state == .beforeUpdate {
123123
contentSize = controller.contentSize(for: .beforeUpdate)
@@ -243,7 +243,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
243243
/// Get current offset of the item closest to the provided edge.
244244
/// - Parameter edge: The edge of the `UICollectionView`
245245
/// - Returns: `ChatLayoutPositionSnapshot`
246-
public func getContentOffsetSnapshot(from edge: ChatLayoutPositionSnapshot.Edge) -> ChatLayoutPositionSnapshot? {
246+
open func getContentOffsetSnapshot(from edge: ChatLayoutPositionSnapshot.Edge) -> ChatLayoutPositionSnapshot? {
247247
guard let collectionView else {
248248
return nil
249249
}
@@ -281,7 +281,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
281281

282282
/// Invalidates layout of the `UICollectionView` and trying to keep the offset of the item provided in `ChatLayoutPositionSnapshot`
283283
/// - Parameter snapshot: `ChatLayoutPositionSnapshot`
284-
public func restoreContentOffset(with snapshot: ChatLayoutPositionSnapshot) {
284+
open func restoreContentOffset(with snapshot: ChatLayoutPositionSnapshot) {
285285
guard let collectionView else {
286286
return
287287
}
@@ -307,14 +307,14 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
307307
///
308308
/// NB: Reconfigure items is not exposed to the layout, it may behave strange and if you experience something like
309309
/// this - move to the `UICollectionView.reloadItems(..)` as a safer option.
310-
public func reconfigureItems(at indexPaths: [IndexPath]) {
310+
open func reconfigureItems(at indexPaths: [IndexPath]) {
311311
reconfigureItemsIndexPaths = indexPaths
312312
}
313313

314314
// MARK: Providing Layout Attributes
315315

316316
/// Tells the layout object to update the current layout.
317-
public override func prepare() {
317+
open override func prepare() {
318318
super.prepare()
319319

320320
guard let collectionView,
@@ -420,7 +420,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
420420
}
421421

422422
/// 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]? {
424424
// This early return prevents an issue that causes overlapping / misplaced elements after an
425425
// off-screen batch update occurs. The root cause of this issue is that `UICollectionView`
426426
// expects `layoutAttributesForElementsInRect:` to return post-batch-update layout attributes
@@ -452,7 +452,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
452452
}
453453

454454
/// 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? {
456456
guard !dontReturnAttributes else {
457457
return nil
458458
}
@@ -462,8 +462,8 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
462462
}
463463

464464
/// 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? {
467467
guard !dontReturnAttributes else {
468468
return nil
469469
}
@@ -477,7 +477,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
477477
// MARK: Coordinating Animated Changes
478478

479479
/// 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) {
481481
controller.isAnimatedBoundsChange = true
482482
controller.process(changeItems: [])
483483
state = .afterUpdate
@@ -494,7 +494,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
494494
}
495495

496496
/// 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() {
498498
if controller.isAnimatedBoundsChange {
499499
state = .beforeUpdate
500500
resetInvalidatedAttributes()
@@ -509,8 +509,8 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
509509
// MARK: Context Invalidation
510510

511511
/// 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 {
514514
let preferredAttributesItemPath = preferredAttributes.indexPath.itemPath
515515
guard let preferredMessageAttributes = preferredAttributes as? ChatLayoutAttributes,
516516
let item = controller.item(for: preferredAttributesItemPath, kind: preferredMessageAttributes.kind, at: state) else {
@@ -523,8 +523,8 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
523523
}
524524

525525
/// 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 {
528528
guard let preferredMessageAttributes = preferredAttributes as? ChatLayoutAttributes else {
529529
return super.invalidationContext(forPreferredLayoutAttributes: preferredAttributes, withOriginalAttributes: originalAttributes)
530530
}
@@ -601,7 +601,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
601601
}
602602

603603
/// 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 {
605605
let shouldInvalidateLayout = cachedCollectionViewSize != .some(newBounds.size) ||
606606
cachedCollectionViewInset != .some(adjustedContentInset) ||
607607
invalidationActions.contains(.shouldInvalidateOnBoundsChange)
@@ -611,14 +611,14 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
611611
}
612612

613613
/// 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 {
615615
let invalidationContext = super.invalidationContext(forBoundsChange: newBounds) as! ChatLayoutInvalidationContext
616616
invalidationContext.invalidateLayoutMetrics = false
617617
return invalidationContext
618618
}
619619

620620
/// 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) {
622622
guard let collectionView else {
623623
super.invalidateLayout(with: context)
624624
return
@@ -672,12 +672,12 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
672672
}
673673

674674
/// Invalidates the current layout and triggers a layout update.
675-
public override func invalidateLayout() {
675+
open override func invalidateLayout() {
676676
super.invalidateLayout()
677677
}
678678

679679
/// 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 {
681681
if controller.proposedCompensatingOffset != 0,
682682
let collectionView {
683683
let minPossibleContentOffset = -collectionView.adjustedContentInset.top
@@ -698,7 +698,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
698698
// MARK: Responding to Collection View Updates
699699

700700
/// 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]) {
702702
var changeItems = updateItems.compactMap { ChangeItem(with: $0) }
703703
changeItems.append(contentsOf: reconfigureItemsIndexPaths.map { .itemReconfigure(itemIndexPath: $0) })
704704
controller.process(changeItems: changeItems)
@@ -725,7 +725,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
725725
}
726726

727727
/// Performs any additional animations or clean up needed during a collection view update.
728-
public override func finalizeCollectionViewUpdates() {
728+
open override func finalizeCollectionViewUpdates() {
729729
controller.proposedCompensatingOffset = 0
730730

731731
if keepContentOffsetAtBottomOnBatchUpdates,
@@ -755,7 +755,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
755755
// MARK: - Cell Appearance Animation
756756

757757
/// 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? {
759759
var attributes: ChatLayoutAttributes?
760760

761761
let itemPath = itemIndexPath.itemPath
@@ -792,7 +792,7 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
792792
}
793793

794794
/// 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? {
796796
var attributes: ChatLayoutAttributes?
797797

798798
let itemPath = itemIndexPath.itemPath
@@ -843,8 +843,8 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
843843
// MARK: - Supplementary View Appearance Animation
844844

845845
/// 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? {
848848
var attributes: ChatLayoutAttributes?
849849

850850
let kind = ItemKind(elementKind)
@@ -883,8 +883,8 @@ public final class CollectionViewChatLayout: UICollectionViewLayout {
883883
}
884884

885885
/// 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? {
888888
var attributes: ChatLayoutAttributes?
889889

890890
let kind = ItemKind(elementKind)

0 commit comments

Comments
 (0)