on xenial help sign in
Dash: Set delegate creation range for inner itemviewss

If it's above the list viewport we set it to the end of the list to precache the last items It it's below the list viewport we set it to the beginning to precache the first items Otherwise we set it to the part of the viewport in the view Approved by: Michał Sawicz.

commitcee3cecaded28ba05674d94b7cfbc4896c01bc6e authorAlbert Astals <albert.astals@canonical.com> dateFri 11 Oct 2013, 10:43 (13 years ago) parentcd1018253e220e
3 files changed+33
Components/FilterGrid.qml+2 Components/ResponsiveGridView.qml+2 Dash/GenericScopeView.qml+29
Components/FilterGrid.qml+2
@@ -57,6 +57,8 @@ Item {
5757 property alias delegate: iconTileGrid.delegate
5858 property alias cellWidth: iconTileGrid.cellWidth
5959 property alias cellHeight: iconTileGrid.cellHeight
60+ property alias delegateCreationBegin: iconTileGrid.delegateCreationBegin
61+ property alias delegateCreationEnd: iconTileGrid.delegateCreationEnd
6062 readonly property alias flicking: iconTileGrid.flicking
6163 readonly property alias moving: iconTileGrid.moving
6264 readonly property alias pressDelay: iconTileGrid.pressDelay
Components/ResponsiveGridView.qml+2
@@ -39,6 +39,8 @@ Item {
3939 readonly property alias flicking: gridView.flicking
4040 readonly property alias moving: gridView.moving
4141 readonly property alias pressDelay: gridView.pressDelay
42+ property alias delegateCreationBegin: gridView.delegateCreationBegin
43+ property alias delegateCreationEnd: gridView.delegateCreationEnd
4244
4345 function contentHeightForRows(rows) {
4446 return rows * cellHeight + verticalSpacing
Dash/GenericScopeView.qml+29
@@ -72,6 +72,7 @@ ScopeView {
7272 property string expandedCategoryId: ""
7373
7474 delegate: ListItems.Base {
75+ id: baseItem
7576 highlightWhenPressed: false
7677
7778 readonly property bool expandable: rendererLoader.item ? rendererLoader.item.expandable : false
@@ -108,6 +109,7 @@ ScopeView {
108109 item.filter = shouldFilter;
109110 }
110111 }
112+ updateDelegateCreationRange();
111113 }
112114
113115 Component.onDestruction: {
@@ -164,6 +166,33 @@ ScopeView {
164166 }
165167 }
166168 }
169+ onContentYChanged: rendererLoader.updateDelegateCreationRange();
170+ onHeightChanged: rendererLoader.updateDelegateCreationRange();
171+ }
172+
173+ function updateDelegateCreationRange() {
174+ // Do not update the range if we are overshooting up or down, since we'll come back
175+ // to the stable position and delete/create items without any reason
176+ if (categoryView.contentY < categoryView.originY) {
177+ return;
178+ } else if (categoryView.contentY + categoryView.height > categoryView.contentHeight) {
179+ return;
180+ }
181+
182+ if (item.hasOwnProperty("delegateCreationBegin")) {
183+ if (baseItem.y + baseItem.height <= 0) {
184+ // Not visible (item at top of the list)
185+ item.delegateCreationBegin = baseItem.height
186+ item.delegateCreationEnd = baseItem.height
187+ } else if (baseItem.y >= categoryView.height) {
188+ // Not visible (item at bottom of the list)
189+ item.delegateCreationBegin = 0
190+ item.delegateCreationEnd = 0
191+ } else {
192+ item.delegateCreationBegin = Math.max(-baseItem.y, 0)
193+ item.delegateCreationEnd = Math.min(categoryView.height + item.delegateCreationBegin, baseItem.height)
194+ }
195+ }
167196 }
168197 }
169198 }