diff options
Diffstat (limited to 'framework/qml/ConversationListView.qml')
-rw-r--r-- | framework/qml/ConversationListView.qml | 32 |
1 files changed, 22 insertions, 10 deletions
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 { | |||
31 | property alias contentHeight: flickable.contentHeight | 31 | property alias contentHeight: flickable.contentHeight |
32 | property int currentIndex: -1 | 32 | property int currentIndex: -1 |
33 | 33 | ||
34 | //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. | ||
35 | //However, we have to maintain position as the initial items expand, so we have to react to contentHeight changes. scrollToEnd ensures both. | ||
36 | property bool scrollToEnd: true | ||
37 | |||
34 | property var currentItem: null | 38 | property var currentItem: null |
35 | 39 | ||
36 | function setCurrentItem() { | 40 | function setCurrentItem() { |
@@ -68,21 +72,27 @@ FocusScope { | |||
68 | 72 | ||
69 | function scrollToIndex(index) { | 73 | function scrollToIndex(index) { |
70 | var item = repeater.itemAt(index) | 74 | var item = repeater.itemAt(index) |
71 | var pos = item.y | 75 | if (item) { |
72 | var scrollToEndPos = (flickable.contentHeight - flickable.height) | 76 | var pos = item.y |
73 | //Avoid scrolling past the end | 77 | var scrollToEndPos = (flickable.contentHeight - flickable.height) |
74 | if (pos < scrollToEndPos) { | 78 | //Avoid scrolling past the end |
75 | flickable.contentY = pos | 79 | if (pos < scrollToEndPos) { |
76 | } else { | 80 | flickable.contentY = pos |
77 | flickable.contentY = scrollToEndPos | 81 | } else { |
82 | flickable.contentY = scrollToEndPos | ||
83 | } | ||
78 | } | 84 | } |
79 | } | 85 | } |
80 | 86 | ||
87 | onMovementStarted: { | ||
88 | root.scrollToEnd = false | ||
89 | } | ||
90 | |||
81 | onContentHeightChanged: { | 91 | onContentHeightChanged: { |
82 | if (repeater.count) { | 92 | if (repeater.count && root.scrollToEnd) { |
83 | //Scroll to the last item | 93 | //Scroll to the last item |
84 | currentIndex = repeater.count - 1 | 94 | root.currentIndex = repeater.count - 1 |
85 | scrollToIndex(repeater.count - 1) | 95 | flickable.scrollToIndex(root.currentIndex) |
86 | } | 96 | } |
87 | } | 97 | } |
88 | 98 | ||
@@ -96,6 +106,8 @@ FocusScope { | |||
96 | for (var i = 0; i < count; i++) { | 106 | for (var i = 0; i < count; i++) { |
97 | itemAt(i).index = i | 107 | itemAt(i).index = i |
98 | } | 108 | } |
109 | root.scrollToEnd = true | ||
110 | flickable.scrollToIndex(root.currentIndex) | ||
99 | } | 111 | } |
100 | } | 112 | } |
101 | } | 113 | } |