From d3607e0b77d4128507ea3aed8e9d7a7c0a1cd367 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Thu, 8 Mar 2018 21:49:24 +0200 Subject: 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 --- mobile-widgets/qml/DiveList.qml | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'mobile-widgets/qml') diff --git a/mobile-widgets/qml/DiveList.qml b/mobile-widgets/qml/DiveList.qml index b724bdf3c..dbadda062 100644 --- a/mobile-widgets/qml/DiveList.qml +++ b/mobile-widgets/qml/DiveList.qml @@ -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) + } + } } -- cgit v1.2.3-70-g09d2