Reduce timeline flickering

This commit is contained in:
Konstantinos Sideris 2017-10-09 01:32:25 +03:00
parent 76ddfb792b
commit ac8e42b926
2 changed files with 24 additions and 18 deletions

View file

@ -140,10 +140,9 @@ private:
bool isPaginationInProgress_ = false; bool isPaginationInProgress_ = false;
// Keeps track whether or not the user has visited the view. // Keeps track whether or not the user has visited the view.
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 = 400; const int SCROLL_BAR_GAP = 400;

View file

@ -85,19 +85,15 @@ 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_) { int currentHeight = scroll_widget_->size().height();
isPaginationScrollPending_ = false; int diff = currentHeight - oldHeight_;
int newPosition = oldPosition_ + diff;
int currentHeight = scroll_widget_->size().height(); // Keep the scroll bar to the bottom if it hasn't been activated yet.
int diff = currentHeight - oldHeight_; if (oldPosition_ == 0 && !scroll_area_->verticalScrollBar()->isVisible())
int newPosition = oldPosition_ + diff; newPosition = max;
// Keep the scroll bar to the bottom if it hasn't been activated yet. scroll_area_->verticalScrollBar()->setValue(newPosition);
if (oldPosition_ == 0 && !scroll_area_->verticalScrollBar()->isVisible())
newPosition = max;
scroll_area_->verticalScrollBar()->setValue(newPosition);
}
} }
void void
@ -173,6 +169,9 @@ TimelineView::addBackwardsEvents(const QString &room_id, const RoomMessages &msg
isTimelineFinished = false; isTimelineFinished = false;
QList<TimelineItem *> items; QList<TimelineItem *> items;
scroll_widget_->adjustSize();
scroll_widget_->update();
// Parse in reverse order to determine where we should not show sender's // Parse in reverse order to determine where we should not show sender's
// name. // name.
auto ii = msgs.chunk().size(); auto ii = msgs.chunk().size();
@ -195,9 +194,8 @@ TimelineView::addBackwardsEvents(const QString &room_id, const RoomMessages &msg
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;
// Exclude the top stretch. // Exclude the top stretch.
if (!msgs.chunk().isEmpty() && scroll_layout_->count() > 1) if (!msgs.chunk().isEmpty() && scroll_layout_->count() > 1)
@ -465,6 +463,9 @@ TimelineView::addTimelineItem(TimelineItem *item, TimelineDirection direction)
scroll_layout_->addWidget(item); scroll_layout_->addWidget(item);
else else
scroll_layout_->insertWidget(1, item); scroll_layout_->insertWidget(1, item);
scroll_widget_->adjustSize();
scroll_widget_->update();
} }
void void
@ -488,6 +489,9 @@ TimelineView::addUserMessage(matrix::events::MessageEventType ty, const QString
TimelineItem *view_item = new TimelineItem(ty, user_id, body, with_sender, scroll_widget_); TimelineItem *view_item = new TimelineItem(ty, user_id, body, with_sender, scroll_widget_);
scroll_layout_->addWidget(view_item); scroll_layout_->addWidget(view_item);
scroll_widget_->adjustSize();
scroll_widget_->update();
lastSender_ = user_id; lastSender_ = user_id;
PendingMessage message(txn_id, body, "", view_item); PendingMessage message(txn_id, body, "", view_item);
@ -506,6 +510,9 @@ TimelineView::addUserMessage(const QString &url, const QString &filename, int tx
TimelineItem *view_item = new TimelineItem(image, user_id, with_sender, scroll_widget_); TimelineItem *view_item = new TimelineItem(image, user_id, with_sender, scroll_widget_);
scroll_layout_->addWidget(view_item); scroll_layout_->addWidget(view_item);
scroll_widget_->adjustSize();
scroll_widget_->update();
lastSender_ = user_id; lastSender_ = user_id;
PendingMessage message(txn_id, url, "", view_item); PendingMessage message(txn_id, url, "", view_item);