Fix scrolling flickering on backwards pagination
This commit is contained in:
parent
95c492bad8
commit
36d25951dc
@ -111,12 +111,16 @@ private:
|
|||||||
bool isInitialized = false;
|
bool isInitialized = false;
|
||||||
bool isTimelineFinished = false;
|
bool isTimelineFinished = false;
|
||||||
bool isInitialSync = true;
|
bool isInitialSync = true;
|
||||||
|
bool isPaginationScrollPending_ = false;
|
||||||
|
|
||||||
const int SCROLL_BAR_GAP = 300;
|
const int SCROLL_BAR_GAP = 400;
|
||||||
|
|
||||||
int scroll_height_ = 0;
|
int scroll_height_ = 0;
|
||||||
int previous_max_height_ = 0;
|
int previous_max_height_ = 0;
|
||||||
|
|
||||||
|
int oldPosition_;
|
||||||
|
int oldHeight_;
|
||||||
|
|
||||||
QList<PendingMessage> pending_msgs_;
|
QList<PendingMessage> pending_msgs_;
|
||||||
QSharedPointer<MatrixClient> client_;
|
QSharedPointer<MatrixClient> client_;
|
||||||
};
|
};
|
||||||
|
@ -58,6 +58,15 @@ void TimelineView::sliderRangeChanged(int min, int max)
|
|||||||
|
|
||||||
if (max - scroll_area_->verticalScrollBar()->value() < SCROLL_BAR_GAP)
|
if (max - scroll_area_->verticalScrollBar()->value() < SCROLL_BAR_GAP)
|
||||||
scroll_area_->verticalScrollBar()->setValue(max);
|
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()
|
void TimelineView::scrollDown()
|
||||||
@ -88,17 +97,14 @@ void TimelineView::sliderMoved(int position)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Prevent user from moving up when there is pagination in progress.
|
// Prevent user from moving up when there is pagination in progress.
|
||||||
if (isPaginationInProgress_) {
|
// TODO: Keep a map of the event ids to filter out duplicates.
|
||||||
scroll_area_->verticalScrollBar()->setValue(SCROLL_BAR_GAP);
|
if (isPaginationInProgress_)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
isPaginationInProgress_ = true;
|
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?
|
// 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.
|
// Reverse again to render them.
|
||||||
std::reverse(items.begin(), items.end());
|
std::reverse(items.begin(), items.end());
|
||||||
|
|
||||||
|
oldPosition_ = scroll_area_->verticalScrollBar()->value();
|
||||||
|
oldHeight_ = scroll_widget_->size().height();
|
||||||
|
|
||||||
for (const auto &item : items)
|
for (const auto &item : items)
|
||||||
addTimelineItem(item, TimelineDirection::Top);
|
addTimelineItem(item, TimelineDirection::Top);
|
||||||
|
|
||||||
prev_batch_token_ = msgs.end();
|
prev_batch_token_ = msgs.end();
|
||||||
isPaginationInProgress_ = false;
|
isPaginationInProgress_ = false;
|
||||||
|
isPaginationScrollPending_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TimelineItem *TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection direction)
|
TimelineItem *TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection direction)
|
||||||
|
Loading…
Reference in New Issue
Block a user