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 8c7fcc5 Flex sets selectedIndex to -1 when selectedIndex is removed.
8c7fcc5 is described below
commit 8c7fcc50c655abbdcee01119ebd3eff0c8ed12da
Author: Alex Harui <[email protected]>
AuthorDate: Fri Feb 21 11:31:10 2020 -0800
Flex sets selectedIndex to -1 when selectedIndex is removed.
---
.../models/SingleSelectionICollectionViewModel.as | 7 +-
.../mx/controls/listClasses/AdvancedListBase.as | 75 +++++++++++++---------
2 files changed, 50 insertions(+), 32 deletions(-)
diff --git
a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/models/SingleSelectionICollectionViewModel.as
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/models/SingleSelectionICollectionViewModel.as
index d9080d0..e7966cb 100644
---
a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/models/SingleSelectionICollectionViewModel.as
+++
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/models/SingleSelectionICollectionViewModel.as
@@ -306,6 +306,7 @@ package mx.controls.beads.models
if (event.location <= _selectedIndex)
{
_selectedIndex++;
+ dispatchEvent(new
Event("selectedIndexChanged"));
}
}
else if (event.kind == CollectionEventKind.REMOVE)
@@ -313,10 +314,14 @@ package mx.controls.beads.models
if (event.location < _selectedIndex)
{
_selectedIndex--;
+ dispatchEvent(new
Event("selectedIndexChanged"));
}
else if (event.location == _selectedIndex)
{
- _selectedItem =
getItemAt(_selectedIndex);
+ _selectedItem = null;
+ _selectedIndex = -1;
+ dispatchEvent(new
Event("selectedItemChanged"));
+ dispatchEvent(new
Event("selectedIndexChanged"));
}
}
}
diff --git
a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/listClasses/AdvancedListBase.as
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/listClasses/AdvancedListBase.as
index 7e8352d..df291af 100644
---
a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/listClasses/AdvancedListBase.as
+++
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/listClasses/AdvancedListBase.as
@@ -63,8 +63,8 @@ import org.apache.royale.core.ISelectionModel;
import org.apache.royale.core.IUIBase;
import org.apache.royale.events.Event;
import org.apache.royale.events.MouseEvent;
-import org.apache.royale.utils.loadBeadFromValuesManager;
-
+import org.apache.royale.utils.loadBeadFromValuesManager;
+
use namespace mx_internal;
@@ -550,10 +550,18 @@ public class AdvancedListBase extends ListBase /* extends
UIComponent
*/
override public function set dataProvider(value:Object):void
{
+ if (collection)
+ collection.removeEventListener(CollectionEvent.COLLECTION_CHANGE,
collectionChangeHandler);
+
+ collection = value as ICollectionView;
+ if (collection)
+ {
+
collection.addEventListener(CollectionEvent.COLLECTION_CHANGE,
collectionChangeHandler);
+ iterator = collection.createCursor();
+ collectionIterator = collection.createCursor();
//IViewCursor(collection);
+ }
super.dataProvider = value;
- collection = super.dataProvider as ICollectionView;
- iterator = collection.createCursor();
- collectionIterator = collection.createCursor();
//IViewCursor(collection);
+
}
override public function addedToParent():void
@@ -8252,7 +8260,7 @@ public class AdvancedListBase extends ListBase /* extends
UIComponent
var len:int;
var i:int;
var n:int;
- //var data:ListBaseSelectionData;
+ var data:ListBaseSelectionData;
var p:String;
var selectedUID:String;
@@ -8260,13 +8268,13 @@ public class AdvancedListBase extends ListBase /*
extends UIComponent
{
var ce:CollectionEvent = CollectionEvent(event);
- /*
// trace("ListBase collectionEvent", ce.kind);
if (ce.kind == CollectionEventKind.ADD)
{
- prepareDataEffect(ce);
+ //prepareDataEffect(ce);
// trace("ListBase collectionEvent ADD", ce.location,
verticalScrollPosition);
// special case when we have less than a screen full of stuff
+ /*
if (ce.location == 0 && verticalScrollPosition == 0)
{
try
@@ -8287,7 +8295,7 @@ public class AdvancedListBase extends ListBase /* extends
UIComponent
else if (listType == "vertical" && verticalScrollPosition >=
ce.location)
{
super.verticalScrollPosition =
super.verticalScrollPosition + ce.items.length;
- }
+ }*/
len = ce.items.length;
for (p in selectedData)
@@ -8296,14 +8304,14 @@ public class AdvancedListBase extends ListBase /*
extends UIComponent
if (data.index > ce.location)
data.index += len;
}
-
+ /* model will handle this
if (_selectedIndex >= ce.location)
{
_selectedIndex += len;
dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
- }
+ }*/
}
-
+ /*
else if (ce.kind == CollectionEventKind.REPLACE)
{
// trace("ListBase collectionEvent REPLACE");
@@ -8328,27 +8336,29 @@ public class AdvancedListBase extends ListBase /*
extends UIComponent
}
prepareDataEffect(ce);
- }
+ }*/
else if (ce.kind == CollectionEventKind.REMOVE)
{
- prepareDataEffect(ce);
+ //prepareDataEffect(ce);
var requiresValueCommit:Boolean = false;
// trace("ListBase collectionEvent REMOVE", ce.location,
verticalScrollPosition);
// make sure we've generated rows for the actual data
// at startup time we might just have blank rows
+ /*
if (listItems.length && listItems[lockedRowCount].length)
{
// special case when we have less than a screen full of
stuff
var firstUID:String =
rowMap[listItems[lockedRowCount][0].name].uid;
selectedUID = selectedItem ? itemToUID(selectedItem) :
null;
-
+ */
n = ce.items.length;
for (i = 0; i < n; i++)
{
var uid:String = itemToUID(ce.items[i]);
+ /*
if (uid == firstUID && verticalScrollPosition == 0)
{
try
@@ -8364,21 +8374,22 @@ public class AdvancedListBase extends ListBase /*
extends UIComponent
iteratorValid = false;
// do nothing, we'll repaint when the data
arrives
}
- }
+ }*/
if (selectedData[uid])
removeSelectionData(uid);
+ /* model should take care of
this
if (selectedUID == uid)
{
_selectedItem = null;
_selectedIndex = -1;
requiresValueCommit = true;
- }
+ }*/
- removeIndicators(uid);
+ //removeIndicators(uid);
}
-
+ /*
// Decrement verticalScrollPosition by the number of items
that have
// been removed from the top.
if (listType == "vertical" && verticalScrollPosition >=
ce.location)
@@ -8412,13 +8423,13 @@ public class AdvancedListBase extends ListBase /*
extends UIComponent
// do nothing, we'll repaint when the data arrives
}
}
-
+ */
var emitEvent:Boolean = adjustAfterRemove(ce.items,
ce.location, requiresValueCommit);
if (emitEvent)
dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
- }
+ /*}*/
}
-
+ /*
else if (ce.kind == CollectionEventKind.MOVE)
{
if (ce.oldLocation < ce.location)
@@ -8477,9 +8488,9 @@ public class AdvancedListBase extends ListBase /* extends
UIComponent
else if ((ce.location <= verticalScrollPosition) &&
(ce.oldLocation > verticalScrollPosition))
seekPreviousSafely(iterator,verticalScrollPosition);
- }
+ }*/
- else*/ if (ce.kind == CollectionEventKind.REFRESH)
+ else if (ce.kind == CollectionEventKind.REFRESH)
{
/*
if (anchorBookmark)
@@ -8700,7 +8711,7 @@ public class AdvancedListBase extends ListBase /* extends
UIComponent
/**
* @private
*/
- /* protected function adjustAfterRemove(items:Array, location:int,
emitEvent:Boolean):Boolean
+ protected function adjustAfterRemove(items:Array, location:int,
emitEvent:Boolean):Boolean
{
var data:ListBaseSelectionData;
var requiresValueCommit:Boolean = emitEvent;
@@ -8714,31 +8725,33 @@ public class AdvancedListBase extends ListBase /*
extends UIComponent
data.index -= length;
}
+ /* model should handle this on it sown
if (_selectedIndex > location)
{
_selectedIndex -= length;
requiresValueCommit = true;
- }
+ }*/
// selected the last thing if the selected item
// got removed.
- if (i > 0 && _selectedIndex == -1)
+ if (i > 0 && /*_*/selectedIndex == -1)
{
- _selectedIndex = data.index;
- _selectedItem = data.data;
+ /*_*/selectedIndex = data.index;
+ /*_selectedItem = data.data;*/
requiresValueCommit = true;
}
+ /* model should handle this on it sown
if (i == 0)
{
_selectedIndex = -1;
bSelectionChanged = true;
bSelectedIndexChanged = true;
invalidateDisplayList();
- }
+ }*/
return requiresValueCommit;
- } */
+ }
/**
* Handles <code>MouseEvent.MOUSE_OVER</code> events from any mouse