Skip to content

Commit

Permalink
Fix code style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
heoblitz committed Oct 25, 2024
1 parent 9cc1504 commit 5791b05
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions ChatLayout/Classes/Core/ChatLayoutDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public protocol ChatLayoutDelegate: AnyObject {
/// - Returns: `Bool`.
func shouldPresentFooter(_ chatLayout: CollectionViewChatLayout,
at sectionIndex: Int) -> Bool

/// `CollectionViewChatLayout` will call this method to ask if it should pin (stick) the header to the visible bounds in the current layout.
/// - Parameters:
/// - chatLayout: `CollectionViewChatLayout` reference.
/// - sectionIndex: Index of the section.
/// - Returns: `Bool`.
func shouldPinHeaderToVisibleBounds(_ chatLayout: CollectionViewChatLayout,
at sectionIndex: Int) -> Bool

/// `CollectionViewChatLayout` will call this method to ask if it should pin (stick) the footer to the visible bounds in the current layout.
/// - Parameters:
/// - chatLayout: `CollectionViewChatLayout` reference.
Expand Down
2 changes: 1 addition & 1 deletion ChatLayout/Classes/Core/CollectionViewChatLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ open class CollectionViewChatLayout: UICollectionViewLayout {
cachedCollectionViewInset != .some(adjustedContentInset) ||
invalidationActions.contains(.shouldInvalidateOnBoundsChange)
|| (isUserInitiatedScrolling && state == .beforeUpdate)

invalidationActions.remove(.shouldInvalidateOnBoundsChange)
return shouldInvalidateLayout || hasPinnedHeaderOrFooter
}
Expand Down
4 changes: 2 additions & 2 deletions ChatLayout/Classes/Core/Model/SectionModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ struct SectionModel<Layout: ChatLayoutRepresentation> {
mutating func set(items: ContiguousArray<ItemModel>) {
self.items = items
}

mutating func set(footer: ItemModel?) {
self.footer = footer
}

mutating func set(isPinHeaderToVisibleBounds: Bool) {
self.isPinHeaderToVisibleBounds = isPinHeaderToVisibleBounds
}
Expand Down
10 changes: 5 additions & 5 deletions ChatLayout/Classes/Core/Model/StateController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,14 @@ final class StateController<Layout: ChatLayoutRepresentation> {

if kind == .header && section.isPinHeaderToVisibleBounds == true {
layoutRepresentation.hasPinnedHeaderOrFooter = true
let dy = max(min(visibleBounds.minY - section.offsetY, section.height - (section.footer?.size.height ?? 0) - item.size.height), 0)
itemFrame.offsettingBy(dx: 0, dy: dy)
let offsetY = max(min(visibleBounds.minY - section.offsetY, section.height - (section.footer?.size.height ?? 0) - item.size.height), 0)
itemFrame.offsettingBy(dx: 0, dy: offsetY)
}

if kind == .footer && section.isPinFooterToVisibleBounds == true {
layoutRepresentation.hasPinnedHeaderOrFooter = true
let dy = max(min(0, visibleBounds.maxY - item.size.height - itemFrame.minY), section.offsetY + (section.header?.size.height ?? 0) - itemFrame.minY)
itemFrame.offsettingBy(dx: 0, dy: dy)
let offsetY = max(min(0, visibleBounds.maxY - item.size.height - itemFrame.minY), section.offsetY + (section.header?.size.height ?? 0) - itemFrame.minY)
itemFrame.offsettingBy(dx: 0, dy: offsetY)
}

if isFinal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,11 @@ extension DefaultChatCollectionDataSource: ChatLayoutDelegate {
public func shouldPresentFooter(_ chatLayout: CollectionViewChatLayout, at sectionIndex: Int) -> Bool {
true
}

public func shouldPinFooterToVisibleBounds(_ chatLayout: CollectionViewChatLayout, at sectionIndex: Int) -> Bool {
true
false
}

public func shouldPinHeaderToVisibleBounds(_ chatLayout: CollectionViewChatLayout, at sectionIndex: Int) -> Bool {
true
}
Expand Down
6 changes: 3 additions & 3 deletions Example/Tests/MockCollectionLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ class MockCollectionLayout: ChatLayoutRepresentation, ChatLayoutDelegate {
let keepContentOffsetAtBottomOnBatchUpdates: Bool = true

let keepContentAtBottomOfVisibleArea: Bool = false

let processOnlyVisibleItemsOnAnimatedBatchUpdates: Bool = true

var hasPinnedHeaderOrFooter: Bool = false

func numberOfItems(in section: Int) -> Int {
numberOfItemsInSection[section] ?? 0
}
Expand Down
2 changes: 1 addition & 1 deletion Example/Tests/PerformanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ final class PerformanceTests: XCTestCase {
layout.settings.interSectionSpacing = 0
layout.controller.set(layout.getPreparedSections(), at: .beforeUpdate)
layout.hasPinnedHeaderOrFooter = true

let rect = CGRect(origin: CGPoint(x: 0, y: 99999), size: CGSize(width: 300, height: 2))
let attributes = layout.controller.layoutAttributesForElements(in: rect, state: .beforeUpdate, ignoreCache: true)
XCTAssertEqual(attributes.count, 2)
Expand Down
2 changes: 1 addition & 1 deletion Example/Tests/StateControllerProcessUpdatesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class StateControllerProcessUpdatesTests: XCTestCase {
let item = layout.controller.itemAttributes(for: ItemPath(item: 0, section: 0), kind: .header, at: .beforeUpdate)
XCTAssertEqual(item?.frame.minY, scrollOffsetY)
}

func testPinnedFooter() {
let layout = MockCollectionLayout()
layout.shouldPinFooterToVisibleBoundsAtSection[0] = true
Expand Down

0 comments on commit 5791b05

Please sign in to comment.