@@ -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();