Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VerticalLayout without virtual layout throws error on drag/drop #1819

Open
esidegallery opened this issue Aug 10, 2022 · 2 comments
Open

VerticalLayout without virtual layout throws error on drag/drop #1819

esidegallery opened this issue Aug 10, 2022 · 2 comments

Comments

@esidegallery
Copy link
Contributor

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>
@Adrian-S
Copy link

@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
Copy link

This is a fix for the first and second problem.

DragVerticalLayout.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants