You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ca...@apache.org on 2020/04/17 00:49:52 UTC
[royale-asjs] branch develop updated: jewel-scrollToIndex: add
method to List and simplify in ListView
This is an automated email from the ASF dual-hosted git repository.
carlosrovira 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 3bb95a5 jewel-scrollToIndex: add method to List and simplify in ListView
3bb95a5 is described below
commit 3bb95a5995ae4ec086c43d9432b1e241bf564836
Author: Carlos Rovira <ca...@apache.org>
AuthorDate: Fri Apr 17 02:49:47 2020 +0200
jewel-scrollToIndex: add method to List and simplify in ListView
---
.../org/apache/royale/html/beads/IListView.as | 3 +-
.../main/royale/org/apache/royale/jewel/List.as | 18 +++++
.../apache/royale/jewel/beads/views/ListView.as | 91 +++++++++++++++++++++-
3 files changed, 106 insertions(+), 6 deletions(-)
diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/html/beads/IListView.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/html/beads/IListView.as
index 40d15b4..94b4296 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/html/beads/IListView.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/html/beads/IListView.as
@@ -20,8 +20,7 @@ package org.apache.royale.html.beads
{
import org.apache.royale.core.IBeadView;
import org.apache.royale.core.IItemRendererOwnerView;
- import org.apache.royale.core.IStrand;
-
+
/**
* The IListView interface provides the protocol for any bead that
* creates the visual parts for a org.apache.royale.html.List control.
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/List.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/List.as
index ce46fc2..8c49850 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/List.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/List.as
@@ -27,6 +27,7 @@ package org.apache.royale.jewel
import org.apache.royale.jewel.beads.models.ListPresentationModel;
import org.apache.royale.jewel.supportClasses.container.DataContainerBase;
import org.apache.royale.jewel.supportClasses.list.IListPresentationModel;
+ import org.apache.royale.jewel.beads.views.IScrollToIndexView;
/**
* Indicates that the initialization of the list is complete.
@@ -258,5 +259,22 @@ package org.apache.royale.jewel
}
return presModel;
}
+
+ /**
+ * Ensures that the data provider item at the given index is visible.
+ *
+ * @param index The index of the item in the data provider.
+ *
+ * @return <code>true</code> if the scroll changed.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Royale 0.9.7
+ */
+ public function scrollToIndex(index:int):Boolean
+ {
+ return (view as IScrollToIndexView).scrollToIndex(index);
+ }
}
}
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/views/ListView.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/views/ListView.as
index 4e23b08..77989a0 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/views/ListView.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/views/ListView.as
@@ -37,7 +37,8 @@ package org.apache.royale.jewel.beads.views
import org.apache.royale.events.Event;
import org.apache.royale.events.KeyboardEvent;
import org.apache.royale.html.beads.DataContainerView;
- import org.apache.royale.jewel.beads.controls.list.scrollToIndex;
+ import org.apache.royale.jewel.beads.models.ListPresentationModel;
+ import org.apache.royale.jewel.supportClasses.list.IListPresentationModel;
import org.apache.royale.utils.getSelectionRenderBead;
/**
@@ -52,7 +53,7 @@ package org.apache.royale.jewel.beads.views
* @productversion Royale 0.9.4
*/
COMPILE::JS
- public class ListView extends DataContainerView
+ public class ListView extends DataContainerView implements IScrollToIndexView
{
public function ListView()
{
@@ -119,7 +120,7 @@ package org.apache.royale.jewel.beads.views
if(prevIndex != listModel.selectedIndex)
{
selectionChangeHandler(null);
- scrollToIndex(_strand, listModel.selectedIndex);
+ scrollToIndex(listModel.selectedIndex);
}
}
@@ -183,10 +184,66 @@ package org.apache.royale.jewel.beads.views
}
lastRollOverIndex = (listModel as IRollOverModel).rollOverIndex;
}
+
+ /**
+ * Ensures that the data provider item at the given index is visible.
+ *
+ * If the item is visible, the <code>verticalScrollPosition</code>
+ * property is left unchanged even if the item is not the first visible
+ * item. If the item is not currently visible, the
+ * <code>verticalScrollPosition</code>
+ * property is changed make the item the first visible item, unless there
+ * aren't enough rows to do so because the
+ * <code>verticalScrollPosition</code> value is limited by the
+ * <code>maxVerticalScrollPosition</code> property.
+ *
+ * @param index The index of the item in the data provider.
+ *
+ * @return <code>true</code> if <code>verticalScrollPosition</code> changed.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Royale 0.9.7
+ */
+ public function scrollToIndex(index:int):Boolean
+ {
+ var scrollArea:HTMLElement = (_strand as IRenderedObject).element;
+ var oldScroll:Number = scrollArea.scrollTop;
+
+ var totalHeight:Number = 0;
+ var pm:IListPresentationModel = _strand.getBeadByType(IListPresentationModel) as IListPresentationModel;
+
+ if(pm.variableRowHeight)
+ {
+ //each item render can have its own height
+ var n:int = listModel.dataProvider.length;
+ var irHeights:Array = [];
+ for (var i:int = 0; i <= index; i++)
+ {
+ var ir:IItemRenderer = dataGroup.getItemRendererForIndex(i) as IItemRenderer;
+ totalHeight += ir.element.clientHeight;
+ irHeights.push(totalHeight + ir.element.clientHeight - scrollArea.clientHeight);
+ }
+
+ scrollArea.scrollTop = Math.min(irHeights[index], totalHeight);
+
+ } else
+ {
+ var rowHeight:Number;
+ // all items renderers with same height
+ rowHeight = isNaN(pm.rowHeight) ? ListPresentationModel.DEFAULT_ROW_HEIGHT : rowHeight;
+ totalHeight = listModel.dataProvider.length * rowHeight - scrollArea.clientHeight;
+
+ scrollArea.scrollTop = Math.min(index * rowHeight, totalHeight);
+ }
+
+ return oldScroll != scrollArea.scrollTop;
+ }
}
COMPILE::SWF
- public class ListView extends DataContainerView
+ public class ListView extends DataContainerView implements IScrollToIndexView
{
public function ListView()
{
@@ -281,5 +338,31 @@ package org.apache.royale.jewel.beads.views
}
lastRollOverIndex = IRollOverModel(listModel).rollOverIndex;
}
+
+ /**
+ * Ensures that the data provider item at the given index is visible.
+ *
+ * If the item is visible, the <code>verticalScrollPosition</code>
+ * property is left unchanged even if the item is not the first visible
+ * item. If the item is not currently visible, the
+ * <code>verticalScrollPosition</code>
+ * property is changed make the item the first visible item, unless there
+ * aren't enough rows to do so because the
+ * <code>verticalScrollPosition</code> value is limited by the
+ * <code>maxVerticalScrollPosition</code> property.
+ *
+ * @param index The index of the item in the data provider.
+ *
+ * @return <code>true</code> if <code>verticalScrollPosition</code> changed.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 9
+ * @playerversion AIR 1.1
+ * @productversion Royale 0.9.7
+ */
+ public function scrollToIndex(index:int):Boolean
+ {
+ return false;
+ }
}
}