Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ios: ChatView performance improvements #4353

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

epoberezkin
Copy link
Member

No description provided.

@levitatingpineapple levitatingpineapple changed the title ios: better scrolling in chat view ios: ChatView performance improvements Jun 30, 2024
@levitatingpineapple
Copy link
Collaborator

ChatView performance improvements

This PR improves scrolling performance of chat items list by:

Introducing view reuse optimisation

Cell dequeuing is a standard scrolling optimisation used by UIKit.UITableView and its wrapper SwiftUI.List.
Since we can't use List due to context menu preview being glitched out after applying vertical invert,
a generic ReverseList<Item, Content> is added, which handles:

  • Vertically inverting and displaying chat items list
  • Requesting page load
  • Scrolling to items

Since current chatItemWithMenu implementation developed without consideration for view reuse,
additional changes where required:

  • Removal of async layout updates for chat items with media preview,
    since the async calls can update the cell after it has already been reused for another chat-item
  • Removal of .uiKitContextMenu workaround in favour of standard SwiftUI context menu,
    since it interferes with state updates

Reducing state updates, caused by tracking itemsInView

Tracking, which items are in view by simply storing it in @State will trigger ChatView body evaluation each time a cell appears or disappears.
This is solved by adding FloatingButtonsModel which:

  1. Consumes item appearance/disappearance events
  2. Resolves the floating button state in the background
  3. Updates ChatView only when state has changed

Filtering merged items.

Current implementation will render an empty cell for every merged item.
In group chats there can be many such merged items:

IMG_4275

This is resulting in scrolling and rendering glitches,
since UITableView has not been designed/optimised for displaying empty elements.

So empty merged chat items are filtered out before doing any rendering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants