summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2017-06-05 19:21:19 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2017-06-05 19:21:19 +0300
commit36d25951dc147efc032bb0390b3b65c0c43ef129 (patch)
tree17c40c46acbb1490afdc79a10bccae313e18b4a7 /src
parentExperimental support for user avatars in timeline (diff)
downloadnheko-36d25951dc147efc032bb0390b3b65c0c43ef129.tar.xz
Fix scrolling flickering on backwards pagination
Diffstat (limited to 'src')
-rw-r--r--src/TimelineView.cc22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/TimelineView.cc b/src/TimelineView.cc

index 5cd59fe5..412b9520 100644 --- a/src/TimelineView.cc +++ b/src/TimelineView.cc
@@ -58,6 +58,15 @@ void TimelineView::sliderRangeChanged(int min, int max) if (max - scroll_area_->verticalScrollBar()->value() < SCROLL_BAR_GAP) scroll_area_->verticalScrollBar()->setValue(max); + + if (isPaginationScrollPending_) { + isPaginationScrollPending_ = false; + + int currentHeight = scroll_widget_->size().height(); + int diff = currentHeight - oldHeight_; + + scroll_area_->verticalScrollBar()->setValue(oldPosition_ + diff); + } } void TimelineView::scrollDown() @@ -88,17 +97,14 @@ void TimelineView::sliderMoved(int position) return; // Prevent user from moving up when there is pagination in progress. - if (isPaginationInProgress_) { - scroll_area_->verticalScrollBar()->setValue(SCROLL_BAR_GAP); + // TODO: Keep a map of the event ids to filter out duplicates. + if (isPaginationInProgress_) return; - } isPaginationInProgress_ = true; - scroll_height_ = scroll_area_->verticalScrollBar()->value(); - previous_max_height_ = scroll_area_->verticalScrollBar()->maximum(); // FIXME: Maybe move this to TimelineViewManager to remove the extra calls? - client_.data()->messages(room_id_, prev_batch_token_); + client_->messages(room_id_, prev_batch_token_); } } @@ -130,11 +136,15 @@ void TimelineView::addBackwardsEvents(const QString &room_id, const RoomMessages // Reverse again to render them. std::reverse(items.begin(), items.end()); + oldPosition_ = scroll_area_->verticalScrollBar()->value(); + oldHeight_ = scroll_widget_->size().height(); + for (const auto &item : items) addTimelineItem(item, TimelineDirection::Top); prev_batch_token_ = msgs.end(); isPaginationInProgress_ = false; + isPaginationScrollPending_ = true; } TimelineItem *TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection direction)