on xenial help sign in
Work around the bug where Dash changed currentIndex when resize
097c240Daniel d'Andrada
qml/Dash/DashContent.qml+52−2
@@ -94,20 +94,70 @@ Item {
94 width: parent.width
94 width: parent.width
95 height: parent.height
95 height: parent.height
96
96
97+ Timer {
98+ id: resizeTimer
99+ interval: 100
100+ repeat: false
101+ onTriggered: {
102+ dashContentList.currentIndex = dashContentList.currentIndexBeforeResize;
103+ resetCurrentIndexTimer.stop();
104+ dashContentList.currentIndexBeforeResize = -1;
105+ }
106+ }
107+ Timer {
108+ id: resetCurrentIndexTimer
109+ interval: 1
110+ repeat: false
111+ onTriggered: {
112+ dashContentList.currentIndex = dashContentList.currentIndexBeforeResize;
113+ }
114+ }
115+
116+ function onSizeChanged() {
117+ if (!resizeTimer.running) {
118+ dashContentList.currentIndexBeforeResize = dashContentList.currentIndex;
119+ resizeTimer.start();
120+ } else {
121+ resizeTimer.restart();
122+ }
123+ }
124+
125+ onWidthChanged: {
126+ onSizeChanged();
127+ dashContentList.width = dashContentListHolder.width;
128+ }
129+
130+ onHeightChanged: {
131+ onSizeChanged();
132+ dashContentList.height = dashContentListHolder.height;
133+ }
134+
97 ListView {
135 ListView {
98 id: dashContentList
136 id: dashContentList
99 objectName: "dashContentList"
137 objectName: "dashContentList"
100
138
101 interactive: dashContent.scopes.loaded && !previewListView.open && currentItem && !currentItem.moving
139 interactive: dashContent.scopes.loaded && !previewListView.open && currentItem && !currentItem.moving
140+ && !resizeTimer.running
141+
142+ property int currentIndexBeforeResize: -1
143+ onCurrentIndexChanged: {
144+ if (resizeTimer.running && currentIndex != currentIndexBeforeResize) {
145+ // Bogus ListView currentIndex change caused by the resize.
146+ // Work around this bug by resetting it to its value before the resize
147+ // took place.
148+ // But we have to do it outside its own onChanged slot, hence the timer.
149+ resetCurrentIndexTimer.start();
150+ }
151+ }
102
152
103− anchors.fill: parent
153+ //anchors.fill: parent /* working around the "currentIndex change due to resize" bug */
104 model: dashContent.model
154 model: dashContent.model
105 orientation: ListView.Horizontal
155 orientation: ListView.Horizontal
106 boundsBehavior: Flickable.DragAndOvershootBounds
156 boundsBehavior: Flickable.DragAndOvershootBounds
107 flickDeceleration: units.gu(625)
157 flickDeceleration: units.gu(625)
108 maximumFlickVelocity: width * 5
158 maximumFlickVelocity: width * 5
109 snapMode: ListView.SnapOneItem
159 snapMode: ListView.SnapOneItem
110− highlightMoveDuration: 250
160+ highlightMoveDuration: 0 //250 /* working around the "currentIndex change due to resize" bug */
111 highlightRangeMode: ListView.StrictlyEnforceRange
161 highlightRangeMode: ListView.StrictlyEnforceRange
112 // TODO Investigate if we can switch to a smaller cache buffer when/if UbuntuShape gets more performant
162 // TODO Investigate if we can switch to a smaller cache buffer when/if UbuntuShape gets more performant
113 cacheBuffer: 1073741823
163 cacheBuffer: 1073741823