@@ -152,10 +152,50 @@ FocusScope {
152 interactive: !navigationShown
152 interactive: !navigationShown
154 property string expandedCategoryId: ""
154 property string expandedCategoryId: ""
155+ property bool needMaximizeAfterExpand: false
156 readonly property bool pageHeaderTotallyVisible: scopeView.showPageHeader &&
157 readonly property bool pageHeaderTotallyVisible: scopeView.showPageHeader &&
157 ((headerItemShownHeight == 0 && categoryView.contentY <= categoryView.originY) || (headerItemShownHeight == pageHeaderLoader.item.height))
158 ((headerItemShownHeight == 0 && categoryView.contentY <= categoryView.originY) || (headerItemShownHeight == pageHeaderLoader.item.height))
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) {
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;
177+ if (!shouldExpand) {
178+ shrinkingAny = true;
179+ shrinkHeightDifference = baseItem.item.expandedHeight - baseItem.item.collapsedHeight;
182+ if (shouldExpand && !previewListView.open) {
183+ if (!shrinkingAny) {
184+ categoryView.maximizeVisibleArea(firstCreated + i, baseItem.item.expandedHeight + baseItem.seeAll.height);
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;
193+ baseItem.expand(shouldExpand, animate);
159 delegate: ListItems.Base {
199 delegate: ListItems.Base {
160 id: baseItem
200 id: baseItem
161 objectName: "dashCategory" + category
201 objectName: "dashCategory" + category
@@ -172,6 +212,7 @@ FocusScope {
172 readonly property string category: categoryId
212 readonly property string category: categoryId
173 readonly property string headerLink: model.headerLink
213 readonly property string headerLink: model.headerLink
174 readonly property var item: rendererLoader.item
214 readonly property var item: rendererLoader.item
215+ readonly property var seeAll: seeAll
176 function expand(expand, animate) {
217 function expand(expand, animate) {
177 heightBehaviour.enabled = animate;
218 heightBehaviour.enabled = animate;
@@ -212,9 +253,14 @@ FocusScope {
212 id: heightBehaviour
253 id: heightBehaviour
213 enabled: false
254 enabled: false
214 animation: UbuntuNumberAnimation {
255 animation: UbuntuNumberAnimation {
256+ duration: categoryView.needMaximizeAfterExpand ? UbuntuAnimation.FastDuration / 2 : UbuntuAnimation.FastDuration
215 onRunningChanged: {
257 onRunningChanged: {
216 if (!running) {
258 if (!running) {
217 heightBehaviour.enabled = false
259 heightBehaviour.enabled = false
260+ if (categoryView.needMaximizeAfterExpand && baseItem.category === categoryView.expandedCategoryId) {
261+ categoryView.maximizeVisibleArea(index, item.expandedHeight + seeAll.height);
262+ categoryView.needMaximizeAfterExpand = false;
@@ -279,27 +325,6 @@ FocusScope {
280 Connections {
326 Connections {
281 target: categoryView
327 target: categoryView
282− onExpandedCategoryIdChanged: {
283− collapseAllButExpandedCategory();
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);
303 onOriginYChanged: rendererLoader.updateDelegateCreationRange();
328 onOriginYChanged: rendererLoader.updateDelegateCreationRange();
304 onContentYChanged: rendererLoader.updateDelegateCreationRange();
329 onContentYChanged: rendererLoader.updateDelegateCreationRange();
305 onHeightChanged: rendererLoader.updateDelegateCreationRange();
330 onHeightChanged: rendererLoader.updateDelegateCreationRange();