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 {
public:
MessageHandlers (ChatModel *chat_model) : m_chat_model(chat_model) {}
~MessageHandlers () {
qDebug() << "handlers";
}
~MessageHandlers () = default;
private:
......
......@@ -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
......
......@@ -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()
}
// ---------------------------------------------------------------------------
......
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