Skip to content

Commit

Permalink
Minor fix for sections
Browse files Browse the repository at this point in the history
  • Loading branch information
ekazaev committed Apr 30, 2024
1 parent d26da55 commit 208039e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ChatLayout.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'ChatLayout'
s.version = '2.0.5'
s.version = '2.0.6'
s.summary = 'Chat UI Library. It uses custom UICollectionViewLayout to provide you full control over the presentation.'
s.swift_version = '5.8'

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 @@ -529,10 +529,10 @@ final class StateController<Layout: ChatLayoutRepresentation> {
var itemToRestore: ItemToRestore?
if layoutRepresentation.keepContentOffsetAtBottomOnBatchUpdates,
let lastVisibleAttribute = allAttributes(at: .beforeUpdate, visibleRect: layoutRepresentation.visibleBounds).last,
let item = item(for: lastVisibleAttribute.indexPath.itemPath, kind: lastVisibleAttribute.kind, at: .beforeUpdate) {
let itemFrame = itemFrame(for: lastVisibleAttribute.indexPath.itemPath, kind: lastVisibleAttribute.kind, at: .beforeUpdate) {
itemToRestore = ItemToRestore(globalIndex: globalIndexFor(lastVisibleAttribute.indexPath.itemPath, kind: lastVisibleAttribute.kind, state: .beforeUpdate),
kind: lastVisibleAttribute.kind,
offset: (item.frame.maxY - layoutRepresentation.visibleBounds.maxY).rounded())
offset: (itemFrame.maxY - layoutRepresentation.visibleBounds.maxY).rounded())
}
batchUpdateCompensatingOffset = 0
proposedCompensatingOffset = 0
Expand Down Expand Up @@ -811,9 +811,9 @@ final class StateController<Layout: ChatLayoutRepresentation> {
if layoutRepresentation.keepContentOffsetAtBottomOnBatchUpdates,
let itemToRestore,
let itemPath = itemPathFor(itemToRestore.globalIndex, kind: itemToRestore.kind, state: .model(afterUpdateModel)),
let item = item(for: itemPath, kind: itemToRestore.kind, at: .afterUpdate),
let itemFrame = itemFrame(for: itemPath, kind: itemToRestore.kind, at: .afterUpdate),
isLayoutBiggerThanVisibleBounds(at: .afterUpdate, visibleBounds: layoutRepresentation.visibleBounds) {
let newProposedCompensationOffset = (item.frame.maxY - itemToRestore.offset) - layoutRepresentation.visibleBounds.maxY
let newProposedCompensationOffset = (itemFrame.maxY - itemToRestore.offset) - layoutRepresentation.visibleBounds.maxY
proposedCompensatingOffset = newProposedCompensationOffset
}
totalProposedCompensatingOffset = proposedCompensatingOffset
Expand Down Expand Up @@ -1179,7 +1179,7 @@ final class StateController<Layout: ChatLayoutRepresentation> {
func numberOfItemsBeforeSection(_ sectionIndex: Int, state: GlobalIndexModel) -> Int {
let layout = state.layout ?? layout(at: .beforeUpdate)
var total = 0
for index in 0..<max(sectionIndex - 1, 0) {
for index in 0..<max(sectionIndex, 0) {
let section = layout.sections[index]
total += section.items.count
}
Expand Down

0 comments on commit 208039e

Please sign in to comment.