ios: fix small scroll on new message (#5721)

* ios: fix small scroll on new message

* added inset in calculation of offset
This commit is contained in:
Stanislav Dmitrenko 2025-03-07 16:19:37 +07:00 committed by GitHub
parent f53b21f8c6
commit ad4adf66ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 12 deletions

View file

@ -570,6 +570,14 @@ struct ChatView: View {
.onChange(of: im.reversedChatItems) { items in
mergedItems.boxedValue = MergedItems.create(items, revealedItems, im.chatState)
scrollView.updateItems(mergedItems.boxedValue.items)
if im.itemAdded {
im.itemAdded = false
if scrollView.listState.firstVisibleItemIndex < 2 {
scrollView.scrollToBottomAnimated()
} else {
scrollView.scroll(by: 34)
}
}
}
.onChange(of: revealedItems) { revealed in
mergedItems.boxedValue = MergedItems.create(im.reversedChatItems, revealed, im.chatState)
@ -589,16 +597,6 @@ struct ChatView: View {
searchTextChanged(s)
}
}
.onChange(of: im.itemAdded) { added in
if added {
im.itemAdded = false
if scrollView.listState.firstVisibleItemIndex < 2 {
scrollView.scrollToBottomAnimated()
} else {
scrollView.scroll(by: 34)
}
}
}
}
}

View file

@ -517,7 +517,7 @@ class EndlessScrollView<ScrollItem>: UIScrollView, UIScrollViewDelegate, UIGestu
let y = if top {
min(estimatedContentHeight.bottomOffsetY - bounds.height, item.view.frame.origin.y - insetTop)
} else {
max(estimatedContentHeight.topOffsetY - insetTop, item.view.frame.origin.y + item.view.bounds.height - bounds.height + insetBottom)
max(estimatedContentHeight.topOffsetY - insetTop - insetBottom, item.view.frame.origin.y + item.view.bounds.height - bounds.height + insetBottom)
}
setContentOffset(CGPointMake(contentOffset.x, y), animated: false)
scrollBarView.flashScrollIndicators()
@ -568,7 +568,7 @@ class EndlessScrollView<ScrollItem>: UIScrollView, UIScrollViewDelegate, UIGestu
let y = if top {
min(estimatedContentHeight.bottomOffsetY - bounds.height, item.view.frame.origin.y - insetTop)
} else {
max(estimatedContentHeight.topOffsetY - insetTop, item.view.frame.origin.y + item.view.bounds.height - bounds.height + insetBottom)
max(estimatedContentHeight.topOffsetY - insetTop - insetBottom, item.view.frame.origin.y + item.view.bounds.height - bounds.height + insetBottom)
}
setContentOffset(CGPointMake(contentOffset.x, y), animated: true)
scrollBarView.flashScrollIndicators()