feathersui-starling icon indicating copy to clipboard operation
feathersui-starling copied to clipboard

VerticalLayout without virtual layout throws error on drag/drop

Open esidegallery opened this issue 1 year ago • 2 comments

When dragging an item to the end of a list with a non-virtual vertical layout, the following error is thrown:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at feathers.layout::VerticalLayout/getDropIndex()[C:\Users\josht\Development\feathersui\feathersui-starling-sdk\frameworks\projects\feathers\feathers\source\feathers\layout\VerticalLayout.as:1643]

In VirticalLayout.as, item.y is accessed without testing for the existence of item.

Below is an example to recrate the issue:

<f:Application xmlns:f="library://ns.feathersui.com/mxml"
               xmlns:fx="http://ns.adobe.com/mxml/2009"
               theme="feathers.themes.MetalWorksMobileTheme">

    <fx:Script>
        <![CDATA[
            import feathers.data.ListCollection;
            import feathers.layout.VerticalLayout;
            
            override protected function initialize():void
            {
                super.initialize();
            
                list.dataProvider = new ListCollection([
                        "Item 1",
                        "Item 2",
                        "Item 3",
                        "Item 4"
                    ]);
                (list.layout as VerticalLayout).useVirtualLayout = false;
            }
        ]]>
    </fx:Script>

    <f:List id="list"
            dragEnabled="true"
            dropEnabled="true"/>

</f:Application>

esidegallery avatar Aug 10 '22 13:08 esidegallery

@joshtynjala I have the same issue + two more. All issues are related to drag and drop.

First, with useVirtualLayout = true and hasVariableItemDimensions = true I got this: In VirtualLayout.as in function positionDropIndicator() lines 1550-1551 items[indexMinusOffset] results null.

image

Since the items are virtual, not all of them are constructed and somehow this gives an error. This prompted me to stop using a virtual layout.

Second, with useVirtualLayout = false I got this: In VirtualLayout.as in function getDropIndex() lines 1636 positionY = item.y; item is null and get Err:1009

This I managed to debug a bit:

	var itemCount:int = items.length;
	var totalItemCount:int = itemCount;
	if(this._useVirtualLayout && !this._hasVariableItemDimensions)
	{
		totalItemCount += this._beforeVirtualizedItemCount + this._afterVirtualizedItemCount;
		indexOffset = this._beforeVirtualizedItemCount;
	}
	var secondToLastIndex:int = totalItemCount - 2;
	for(var i:int = 0; i <= totalItemCount; i++)
	{
		var item:DisplayObject = null;
		var indexMinusOffset:int = i - indexOffset;
		if(indexMinusOffset >= 0 && indexMinusOffset < itemCount)
		{
			item = items[indexMinusOffset];
		}

In the for, i <= totalItemCount and totalItemCount = items.length and it's running out of bounds. Apparently by fixing the sign the problem goes away.

Third, while testing on the List in the component explorer, the item being dragged, changed text. I think data is still being referenced from the initial object and that changes with the virtual layout.

Adrian-S avatar Sep 21 '22 11:09 Adrian-S

This is a fix for the first and second problem.

DragVerticalLayout.txt

Adrian-S avatar Sep 21 '22 12:09 Adrian-S