You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ah...@apache.org on 2020/01/15 05:25:38 UTC

[royale-asjs] branch develop updated: fix virtual scrolling. Should fix #664

This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new c571560  fix virtual scrolling.  Should fix #664
c571560 is described below

commit c57156062a5e849004dadea2ab0c4253a5b507a0
Author: Alex Harui <ah...@apache.org>
AuthorDate: Tue Jan 14 21:25:18 2020 -0800

    fix virtual scrolling.  Should fix #664
---
 .../beads/layouts/VirtualListVerticalLayout.as     | 34 +++++++++++++++++++++-
 .../listClasses/VirtualListVerticalLayout.as       | 12 +++++++-
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/layouts/VirtualListVerticalLayout.as b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/layouts/VirtualListVerticalLayout.as
index 0ea0a7b..c1c6784 100644
--- a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/layouts/VirtualListVerticalLayout.as
+++ b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/beads/layouts/VirtualListVerticalLayout.as
@@ -283,28 +283,43 @@ package org.apache.royale.html.beads.layouts
                     contentView.element.appendChild(topSpacer);
                 }
                 topSpacer.style.height = (startIndex * presentationModel.rowHeight).toString() + "px";
+                //trace("starting layout: startIndex = " + startIndex + " endIndex = " + endIndex);
                 if (visibleIndexes.length)
                 {
+                    //trace("visibleIndexes: " + visibleIndexes);
                     if (startIndex < visibleIndexes[0])
                     {
+                        //trace("startIndex < visibleIndex[0]");
                         // see if we can re-use any renderers
                         freeIndex = visibleIndexes.pop();
-                        while (freeIndex >= endIndex)
+                        //trace("freeIndex: " + freeIndex);
+                        while (freeIndex > endIndex)
                         {
+                            //trace("free: " + freeIndex);
                             factory.freeItemRendererForIndex(freeIndex);
                             if (visibleIndexes.length == 0)
                                 break;
                             freeIndex = visibleIndexes.pop();
                         }
+                        // we popped it off at the end of loop but if we didn't
+                        // use it, then push it back on
+                        if (freeIndex == endIndex)
+                            visibleIndexes.push(freeIndex);
                         if (visibleIndexes.length)
+                        {
                             endIndex = visibleIndexes[visibleIndexes.length - 1];
+                            //trace("changing endIndex: " + endIndex);
+                        }
                     }
                     else if (startIndex > visibleIndexes[0])
                     {
+                        //trace("startIndex > visibleIndex[0]");
                         // see if we can re-use any renderers
                         freeIndex = visibleIndexes.shift();
+                        //trace("freeIndex: " + freeIndex);
                         while (freeIndex < startIndex)
                         {
+                            //trace("free: " + freeIndex);
                             factory.freeItemRendererForIndex(freeIndex);
                             if (visibleIndexes.length == 0)
                                 break;
@@ -313,14 +328,18 @@ package org.apache.royale.html.beads.layouts
                     }
                     else
                     {
+                        //trace("startIndex == visibleIndex[0]");
                         // see if rows got added or removed because height changed
                         lastIndex = visibleIndexes[visibleIndexes.length - 1];
+                        //trace("lastIndex: " + lastIndex);
                         if (lastIndex > endIndex)
                         {
                             // see if we can re-use any renderers
                             freeIndex = visibleIndexes.pop();
+                            //trace("freeIndex: " + freeIndex);
                             while (freeIndex > endIndex)
                             {
+                                //trace("free: " + freeIndex);
                                 factory.freeItemRendererForIndex(freeIndex);
                                 if (visibleIndexes.length == 0)
                                     break;
@@ -332,11 +351,13 @@ package org.apache.royale.html.beads.layouts
                     }
                     firstIndex = visibleIndexes[0];
                     lastIndex = visibleIndexes[visibleIndexes.length - 1];
+                    //trace("done freeing: firstIndex = " + firstIndex + " lastIndex = " + lastIndex);
                 }
                 else
                 {
                     firstIndex = dp.length;
                     lastIndex = 0;
+                    //trace("no freeing: firstIndex = " + firstIndex + " lastIndex = " + lastIndex);
                 }
                 for (var i:int = startIndex; i < endIndex; i++)
                 {
@@ -345,25 +366,36 @@ package org.apache.royale.html.beads.layouts
                     var ir:ISelectableItemRenderer;
                     if (i < firstIndex)
                     {
+                       //trace("i < firstIndex: creating: i = " + i);
                        ir  = factory.getItemRendererForIndex(i, i - startIndex + 1);
                        ir.element.style.display = "block";
                        visibleIndexes.push(i);
                     }
                     else if (i > lastIndex)
                     {
+                        //trace("i > lastIndex: creating: i = " + i);
                         ir  = factory.getItemRendererForIndex(i, i - startIndex + 1);
                         ir.element.style.display = "block";
                         visibleIndexes.push(i);
                     }
                 }
                 visibleIndexes = visibleIndexes.sort(numberSort);
+                //trace("visibleIndexes: " + visibleIndexes);
                 if (!bottomSpacer)
                 {
                     bottomSpacer = document.createElement("div") as HTMLDivElement;
                     contentView.element.appendChild(bottomSpacer);
                 }
+                else
+                {
+                    // ensure bottom spacer is at the bottom!
+                    contentView.element.removeChild(bottomSpacer);                    
+                    contentView.element.appendChild(bottomSpacer);                    
+                }
+                
                 var numBottomRows:int = dp.length - endIndex;
                 bottomSpacer.style.height = (numBottomRows > 0) ? (numBottomRows * presentationModel.rowHeight).toString() + "px" : "0px";  
+                //trace("ENDING LAYOUT: bottom spacer = " + bottomSpacer.style.height);
                 inLayout = false;
 				return true;
 			}
diff --git a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/listClasses/VirtualListVerticalLayout.as b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/listClasses/VirtualListVerticalLayout.as
index 496defa..58e87b1 100644
--- a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/listClasses/VirtualListVerticalLayout.as
+++ b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/listClasses/VirtualListVerticalLayout.as
@@ -287,13 +287,17 @@ package mx.controls.listClasses
                     {
                         // see if we can re-use any renderers
                         freeIndex = visibleIndexes.pop();
-                        while (freeIndex >= endIndex)
+                        while (freeIndex > endIndex)
                         {
                             factory.freeItemRendererForIndex(freeIndex);
                             if (visibleIndexes.length == 0)
                                 break;
                             freeIndex = visibleIndexes.pop();
                         }
+                        // we popped it off at the end of loop but if we didn't
+                        // use it, then push it back on
+                        if (freeIndex == endIndex)
+                            visibleIndexes.push(freeIndex);
                         if (visibleIndexes.length)
                             endIndex = visibleIndexes[visibleIndexes.length - 1];
                     }
@@ -358,6 +362,12 @@ package mx.controls.listClasses
                     bottomSpacer = document.createElement("div") as HTMLDivElement;
                     contentView.element.appendChild(bottomSpacer);
                 }
+                else
+                {
+                    // ensure bottom spacer is at the bottom!
+                    contentView.element.removeChild(bottomSpacer);                    
+                    contentView.element.appendChild(bottomSpacer);                    
+                }
                 bottomSpacer.style.height = ((dp.length - endIndex) * presentationModel.rowHeight).toString() + "px";  
                 inLayout = false;
 				return true;