on xenial help sign in
Fix seeAll expansion

Don't do the shrking/grown animations and the maximizeArea animations at the same time if there are two items involved and the first one in the list is the one shrinking and the other growing

commit6306f7515e38c927f681f00ca1e1e021b150e30a authorAlbert Astals <albert.astals@canonical.com> dateTue 19 Aug 2014, 16:04 (12 years ago) parentf605473
3 files changed+58−21
plugins/Dash/listviewwithpageheader.cpp+10 plugins/Dash/listviewwithpageheader.h+2 qml/Dash/GenericScopeView.qml+46−21
plugins/Dash/listviewwithpageheader.cpp+10
@@ -409,6 +409,16 @@ void ListViewWithPageHeader::showHeader()
409409 }
410410}
411411
412+Q_INVOKABLE int ListViewWithPageHeader::firstCreatedIndex() const
413+{
414+ return m_firstVisibleIndex;
415+}
416+
417+Q_INVOKABLE int ListViewWithPageHeader::createdItemCount() const
418+{
419+ return m_visibleItems.count();
420+}
421+
412422QQuickItem *ListViewWithPageHeader::item(int modelIndex) const
413423{
414424 ListItem *item = itemAtIndex(modelIndex);
plugins/Dash/listviewwithpageheader.h+2
@@ -86,6 +86,8 @@ public:
8686
8787 Q_INVOKABLE void positionAtBeginning();
8888 Q_INVOKABLE void showHeader();
89+ Q_INVOKABLE int firstCreatedIndex() const;
90+ Q_INVOKABLE int createdItemCount() const;
8991 Q_INVOKABLE QQuickItem *item(int modelIndex) const;
9092
9193 // The index has to be created for this to try to do something
qml/Dash/GenericScopeView.qml+46−21
@@ -152,10 +152,50 @@ FocusScope {
152152 interactive: !navigationShown
153153
154154 property string expandedCategoryId: ""
155+ property bool needMaximizeAfterExpand: false
155156
156157 readonly property bool pageHeaderTotallyVisible: scopeView.showPageHeader &&
157158 ((headerItemShownHeight == 0 && categoryView.contentY <= categoryView.originY) || (headerItemShownHeight == pageHeaderLoader.item.height))
158159
160+ onExpandedCategoryIdChanged: {
161+ var firstCreated = firstCreatedIndex();
162+ var shrinkingAny = false;
163+ var shrinkHeightDifference = 0;
164+ for (var i = 0; i < createdItemCount(); ++i) {
165+ var baseItem = item(firstCreated + i);
166+ if (baseItem.expandable) {
167+ var shouldExpand = baseItem.category === expandedCategoryId;
168+ if (shouldExpand != baseItem.expanded) {
169+
170+ var animate = false;
171+ if (!previewListView.open) {
172+ var animateShrinking = !shouldExpand && baseItem.y + baseItem.item.collapsedHeight + baseItem.seeAll.height < categoryView.height;
173+ var animateGrowing = shouldExpand && baseItem.y + baseItem.height < categoryView.height;
174+ animate = shrinkingAny || animateShrinking || animateGrowing;
175+ }
176+
177+ if (!shouldExpand) {
178+ shrinkingAny = true;
179+ shrinkHeightDifference = baseItem.item.expandedHeight - baseItem.item.collapsedHeight;
180+ }
181+
182+ if (shouldExpand && !previewListView.open) {
183+ if (!shrinkingAny) {
184+ categoryView.maximizeVisibleArea(firstCreated + i, baseItem.item.expandedHeight + baseItem.seeAll.height);
185+ } else {
186+ // If the space that shrkinking is smaller than the one we need to grow we'll call maximizeVisibleArea
187+ // after the shrink/grow animation ends
188+ var growHeightDifference = baseItem.item.expandedHeight - baseItem.item.collapsedHeight;
189+ needMaximizeAfterExpand = growHeightDifference > shrinkHeightDifference;
190+ }
191+ }
192+
193+ baseItem.expand(shouldExpand, animate);
194+ }
195+ }
196+ }
197+ }
198+
159199 delegate: ListItems.Base {
160200 id: baseItem
161201 objectName: "dashCategory" + category
@@ -172,6 +212,7 @@ FocusScope {
172212 readonly property string category: categoryId
173213 readonly property string headerLink: model.headerLink
174214 readonly property var item: rendererLoader.item
215+ readonly property var seeAll: seeAll
175216
176217 function expand(expand, animate) {
177218 heightBehaviour.enabled = animate;
@@ -212,9 +253,14 @@ FocusScope {
212253 id: heightBehaviour
213254 enabled: false
214255 animation: UbuntuNumberAnimation {
256+ duration: categoryView.needMaximizeAfterExpand ? UbuntuAnimation.FastDuration / 2 : UbuntuAnimation.FastDuration
215257 onRunningChanged: {
216258 if (!running) {
217259 heightBehaviour.enabled = false
260+ if (categoryView.needMaximizeAfterExpand && baseItem.category === categoryView.expandedCategoryId) {
261+ categoryView.maximizeVisibleArea(index, item.expandedHeight + seeAll.height);
262+ categoryView.needMaximizeAfterExpand = false;
263+ }
218264 }
219265 }
220266 }
@@ -279,27 +325,6 @@ FocusScope {
279325 }
280326 Connections {
281327 target: categoryView
282− onExpandedCategoryIdChanged: {
283− collapseAllButExpandedCategory();
284− }
285− function collapseAllButExpandedCategory() {
286− var item = rendererLoader.item;
287− if (baseItem.expandable) {
288− var shouldExpand = categoryId === categoryView.expandedCategoryId;
289− if (shouldExpand != baseItem.expanded) {
290− // If the filter animation will be seen start it, otherwise, just flip the switch
291− var shrinkingVisible = !shouldExpand && y + item.collapsedHeight + seeAll.height < categoryView.height;
292− var growingVisible = shouldExpand && y + height < categoryView.height;
293− if (!previewListView.open || shouldExpand) {
294− var animate = shrinkingVisible || growingVisible;
295− baseItem.expand(shouldExpand, animate)
296− if (shouldExpand && !previewListView.open) {
297− categoryView.maximizeVisibleArea(index, item.expandedHeight + seeAll.height);
298− }
299− }
300− }
301− }
302− }
303328 onOriginYChanged: rendererLoader.updateDelegateCreationRange();
304329 onContentYChanged: rendererLoader.updateDelegateCreationRange();
305330 onHeightChanged: rendererLoader.updateDelegateCreationRange();