From 78889d52cfa8ce43d1ee4486e6ca30525c776456 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 22 Aug 2017 20:55:26 -0600 Subject: Ensure we don't interfere with scrolling This used to be a problem with slow loading html mails, works now. --- framework/qml/ConversationListView.qml | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'framework/qml/ConversationListView.qml') diff --git a/framework/qml/ConversationListView.qml b/framework/qml/ConversationListView.qml index b00002b1..65f5bd02 100644 --- a/framework/qml/ConversationListView.qml +++ b/framework/qml/ConversationListView.qml @@ -31,6 +31,10 @@ FocusScope { property alias contentHeight: flickable.contentHeight property int currentIndex: -1 + //We want to avoid interfering with scrolling as soon as the user starts to scroll. This is important if i.e. an html mail loads slowly. + //However, we have to maintain position as the initial items expand, so we have to react to contentHeight changes. scrollToEnd ensures both. + property bool scrollToEnd: true + property var currentItem: null function setCurrentItem() { @@ -68,21 +72,27 @@ FocusScope { function scrollToIndex(index) { var item = repeater.itemAt(index) - var pos = item.y - var scrollToEndPos = (flickable.contentHeight - flickable.height) - //Avoid scrolling past the end - if (pos < scrollToEndPos) { - flickable.contentY = pos - } else { - flickable.contentY = scrollToEndPos + if (item) { + var pos = item.y + var scrollToEndPos = (flickable.contentHeight - flickable.height) + //Avoid scrolling past the end + if (pos < scrollToEndPos) { + flickable.contentY = pos + } else { + flickable.contentY = scrollToEndPos + } } } + onMovementStarted: { + root.scrollToEnd = false + } + onContentHeightChanged: { - if (repeater.count) { + if (repeater.count && root.scrollToEnd) { //Scroll to the last item - currentIndex = repeater.count - 1 - scrollToIndex(repeater.count - 1) + root.currentIndex = repeater.count - 1 + flickable.scrollToIndex(root.currentIndex) } } @@ -96,6 +106,8 @@ FocusScope { for (var i = 0; i < count; i++) { itemAt(i).index = i } + root.scrollToEnd = true + flickable.scrollToIndex(root.currentIndex) } } } -- cgit v1.2.3