From 66c8bb6dcaea2bd67628e9b1d5473d38cfe140c1 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 10 Jan 2017 11:55:17 +0100 Subject: [PATCH] fix(ui/modules/Linphone/Chat/Chat): workaround to scroll correctly at chat end --- tests/src/components/chat/ChatModel.cpp | 4 +- .../Common/View/ScrollableListView.qml | 4 + tests/ui/modules/Linphone/Chat/Chat.qml | 79 ++++++++++++------- 3 files changed, 56 insertions(+), 31 deletions(-) diff --git a/tests/src/components/chat/ChatModel.cpp b/tests/src/components/chat/ChatModel.cpp index a9194bfba..906c8ba29 100644 --- a/tests/src/components/chat/ChatModel.cpp +++ b/tests/src/components/chat/ChatModel.cpp @@ -17,9 +17,7 @@ class ChatModel::MessageHandlers : public linphone::ChatMessageListener { public: MessageHandlers (ChatModel *chat_model) : m_chat_model(chat_model) {} - ~MessageHandlers () { - qDebug() << "handlers"; - } + ~MessageHandlers () = default; private: diff --git a/tests/ui/modules/Common/View/ScrollableListView.qml b/tests/ui/modules/Common/View/ScrollableListView.qml index fcf813109..22a2e75cb 100644 --- a/tests/ui/modules/Common/View/ScrollableListView.qml +++ b/tests/ui/modules/Common/View/ScrollableListView.qml @@ -6,8 +6,12 @@ import Common 1.0 // ============================================================================= ListView { + id: listView + ScrollBar.vertical: ForceScrollBar { id: scrollBar + + onPressedChanged: pressed ? listView.movementStarted() : listView.movementEnded() } boundsBehavior: Flickable.StopAtBounds diff --git a/tests/ui/modules/Linphone/Chat/Chat.qml b/tests/ui/modules/Linphone/Chat/Chat.qml index ded310c7b..db70875cd 100644 --- a/tests/ui/modules/Linphone/Chat/Chat.qml +++ b/tests/ui/modules/Linphone/Chat/Chat.qml @@ -25,16 +25,23 @@ ColumnLayout { ScrollableListView { id: chat + // ------------------------------------------------------------------------- + + property bool _bindToEnd: false property bool _tryToLoadMoreEntries: true + // ------------------------------------------------------------------------- + function _loadMoreEntries () { if (atYBeginning && !_tryToLoadMoreEntries) { _tryToLoadMoreEntries = true - positionViewAtIndex(0, ListView.Beginning) + positionViewAtBeginning() proxyModel.loadMoreEntries() } } + // ------------------------------------------------------------------------- + Layout.fillHeight: true Layout.fillWidth: true @@ -44,6 +51,49 @@ ColumnLayout { property: '$sectionDate' } + // ------------------------------------------------------------------------- + + Component.onCompleted: { + function goToEnd () { + return Utils.setTimeout(chat, 100, function () { + if (_bindToEnd) { + positionViewAtEnd() + } + + return goToEnd() + }) + } + goToEnd() + + var initView = function () { + _tryToLoadMoreEntries = false + _bindToEnd = true + } + + // Received only if more entries were loaded. + proxyModel.moreEntriesLoaded.connect(function (n) { + positionViewAtIndex(n - 1, ListView.Beginning) + _tryToLoadMoreEntries = false + }) + + // When the view is changed (for example `Calls` -> `Messages`), + // the position is set at end and it can be possible to load + // more entries. + proxyModel.entryTypeFilterChanged.connect(initView) + + // First render. + initView() + } + + onMovementStarted: _bindToEnd = false + onMovementEnded: { + if (atYEnd) { + _bindToEnd = true + } + } + + onContentYChanged: _loadMoreEntries() + // ------------------------------------------------------------------------- // Heading. // ------------------------------------------------------------------------- @@ -178,33 +228,6 @@ ColumnLayout { } } } - - Component.onCompleted: { - var initView = function () { - positionViewAtEnd() - _tryToLoadMoreEntries = false - - // TODO: Remove these lines when this issue will not be longer valid : - // https://bugreports.qt.io/browse/QTBUG-49989 - Utils.setTimeout(chat, 10, positionViewAtEnd) - } - - // Received only if more entries were loaded. - proxyModel.moreEntriesLoaded.connect(function (n) { - positionViewAtIndex(n - 1, ListView.Beginning) - _tryToLoadMoreEntries = false - }) - - // When the view is changed (for example `Calls` -> `Messages`), - // the position is set at end and it can be possible to load - // more entries. - proxyModel.entryTypeFilterChanged.connect(initView) - - // First render. - initView() - } - - onContentYChanged: _loadMoreEntries() } // ---------------------------------------------------------------------------