on xenial help sign in
Require some lateral movement before engaging scrolling
5a7a6f5Nick Dedekind
qml/Components/ScrollCalculator.qml+19−3
@@ -20,8 +20,9 @@ import Ubuntu.Components 1.3
20Item {
20Item {
21 id: scrollArea
21 id: scrollArea
22
22
23− readonly property bool areaActive: lateralPosition >= 0
23+ readonly property bool areaActive: lateralPosition >= 0 && progressThreshold * width
24 property real stopScrollThreshold: units.gu(2)
24 property real stopScrollThreshold: units.gu(2)
25+ property real progressThreshold: units.dp(4)
25 property int direction: Qt.LeftToRight
26 property int direction: Qt.LeftToRight
26 property real baseScrollAmount: units.dp(3)
27 property real baseScrollAmount: units.dp(3)
27 property real maximumScrollAmount: units.dp(8)
28 property real maximumScrollAmount: units.dp(8)
@@ -38,6 +39,8 @@ Item {
38 function handleEnter() {
39 function handleEnter() {
39 d.thresholdAreaX = -scrollArea.stopScrollThreshold;
40 d.thresholdAreaX = -scrollArea.stopScrollThreshold;
40 scrollTimer.restart();
41 scrollTimer.restart();
42+ d.init = true;
43+ d.passedProgressThreshold = false;
41 }
44 }
42
45
43 function handleExit() {
46 function handleExit() {
@@ -59,6 +62,10 @@ Item {
59 }
62 }
60
63
61 d.progression = lateralPosition / width;
64 d.progression = lateralPosition / width;
65+ if (d.init) {
66+ d.startingProgression = d.progression;
67+ d.init = false;
68+ }
62 }
69 }
63 }
70 }
64
71
@@ -68,14 +75,23 @@ Item {
68 repeat: true
75 repeat: true
69
76
70 onTriggered: {
77 onTriggered: {
78+ if (d.passedProgressThreshold ||
79+ Math.abs(d.progression - d.startingProgression) * scrollArea.width > scrollArea.progressThreshold) {
80+ d.passedProgressThreshold = true;
81+
71− var scrollAmount = scrollArea.baseScrollAmount + scrollArea.maximumScrollAmount * d.progression;
82+ var scrollAmount = scrollArea.baseScrollAmount + scrollArea.maximumScrollAmount * d.progression;
72− scrollArea.scroll(scrollAmount);
83+ scrollArea.scroll(scrollAmount);
84+ }
73 }
85 }
74 }
86 }
75
87
76 QtObject {
88 QtObject {
77 id: d
89 id: d
90+ property real startingProgression: 0
91+ property bool init: true
92+
78 property real progression: 0
93 property real progression: 0
79 property real thresholdAreaX: -scrollArea.stopScrollThreshold
94 property real thresholdAreaX: -scrollArea.stopScrollThreshold
95+ property bool passedProgressThreshold: false
80 }
96 }
81}
97}