divelist.qml: add the setCurrentDiveListIndex() helper

Add the setCurrentDiveListIndex() wrapper for:
  diveListView.currentIndex = idx
wich also makes it possible to disable the scroll animation when
selecting dive list indexes which are too far apart.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
Lubomir I. Ivanov 2018-03-08 21:49:24 +02:00 committed by Dirk Hohndel
parent fbbb6ba4fb
commit d3607e0b77

View file

@ -364,4 +364,16 @@ Kirigami.ScrollablePage {
event.accepted = true
}
}
function setCurrentDiveListIndex(idx, noScroll) {
diveListView.currentIndex = idx
// updating the index of the ListView triggers a non-linear scroll
// animation that can be very slow. the fix is to stop this animation
// by setting contentY to itself and then using positionViewAtIndex().
// the downside is that the view jumps to the index immediately.
if (noScroll) {
diveListView.contentY = diveListView.contentY
diveListView.positionViewAtIndex(idx, ListView.Center)
}
}
}