Commit 66c8bb6d authored by Ronan Abhamon's avatar Ronan Abhamon

fix(ui/modules/Linphone/Chat/Chat): workaround to scroll correctly at chat end

parent 6a91163a
...@@ -17,9 +17,7 @@ class ChatModel::MessageHandlers : public linphone::ChatMessageListener { ...@@ -17,9 +17,7 @@ class ChatModel::MessageHandlers : public linphone::ChatMessageListener {
public: public:
MessageHandlers (ChatModel *chat_model) : m_chat_model(chat_model) {} MessageHandlers (ChatModel *chat_model) : m_chat_model(chat_model) {}
~MessageHandlers () { ~MessageHandlers () = default;
qDebug() << "handlers";
}
private: private:
......
...@@ -6,8 +6,12 @@ import Common 1.0 ...@@ -6,8 +6,12 @@ import Common 1.0
// ============================================================================= // =============================================================================
ListView { ListView {
id: listView
ScrollBar.vertical: ForceScrollBar { ScrollBar.vertical: ForceScrollBar {
id: scrollBar id: scrollBar
onPressedChanged: pressed ? listView.movementStarted() : listView.movementEnded()
} }
boundsBehavior: Flickable.StopAtBounds boundsBehavior: Flickable.StopAtBounds
......
...@@ -25,16 +25,23 @@ ColumnLayout { ...@@ -25,16 +25,23 @@ ColumnLayout {
ScrollableListView { ScrollableListView {
id: chat id: chat
// -------------------------------------------------------------------------
property bool _bindToEnd: false
property bool _tryToLoadMoreEntries: true property bool _tryToLoadMoreEntries: true
// -------------------------------------------------------------------------
function _loadMoreEntries () { function _loadMoreEntries () {
if (atYBeginning && !_tryToLoadMoreEntries) { if (atYBeginning && !_tryToLoadMoreEntries) {
_tryToLoadMoreEntries = true _tryToLoadMoreEntries = true
positionViewAtIndex(0, ListView.Beginning) positionViewAtBeginning()
proxyModel.loadMoreEntries() proxyModel.loadMoreEntries()
} }
} }
// -------------------------------------------------------------------------
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
...@@ -44,6 +51,49 @@ ColumnLayout { ...@@ -44,6 +51,49 @@ ColumnLayout {
property: '$sectionDate' 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. // Heading.
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
...@@ -178,33 +228,6 @@ ColumnLayout { ...@@ -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()
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment