Skip to content

Instantly share code, notes, and snippets.

@esidegallery
Last active June 26, 2017 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esidegallery/b51caba8fc6094b33bb8f305d406be51 to your computer and use it in GitHub Desktop.
Save esidegallery/b51caba8fc6094b33bb8f305d406be51 to your computer and use it in GitHub Desktop.
Adds an iconProperties function to DefaultListItemRenderer, which returns an object of properties to be applied to the ImageLoader created by iconLoaderFactory. The function is expected to have the following signature: function(item:Object):Object
package feathers.controls.renderers
{
import starling.display.DisplayObject;
public class ExtendedListItemRenderer extends DefaultListItemRenderer
{
private var _iconPropertiesFunction:Function;
public function get iconPropertiesFunction():Function
{
return _iconPropertiesFunction;
}
public function set iconPropertiesFunction(value:Function):void
{
if (_iconPropertiesFunction != value)
{
_iconPropertiesFunction = value;
invalidate(INVALIDATION_FLAG_DATA);
}
}
override protected function itemToIcon(item:Object):DisplayObject
{
if (_iconPropertiesFunction != null)
{
refreshIconSource(null);
var properties:Object;
if (_iconPropertiesFunction.length == 2)
properties = _iconPropertiesFunction(item, IListItemRenderer(this).index);
else
properties = _iconPropertiesFunction(item);
for (var propertyName:String in properties)
{
var propertyValue:Object = properties[propertyName];
iconLoader[propertyName] = propertyValue;
}
return iconLoader;
}
else
return super.itemToIcon(item);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment