diff --git a/apps/ios/Shared/Views/Chat/ChatView.swift b/apps/ios/Shared/Views/Chat/ChatView.swift index ef343d1fb8..2b59a2aaa2 100644 --- a/apps/ios/Shared/Views/Chat/ChatView.swift +++ b/apps/ios/Shared/Views/Chat/ChatView.swift @@ -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) - } - } - } } } diff --git a/apps/ios/Shared/Views/Chat/EndlessScrollView.swift b/apps/ios/Shared/Views/Chat/EndlessScrollView.swift index 39cc84a71d..9756489628 100644 --- a/apps/ios/Shared/Views/Chat/EndlessScrollView.swift +++ b/apps/ios/Shared/Views/Chat/EndlessScrollView.swift @@ -517,7 +517,7 @@ class EndlessScrollView: 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: 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()