Created
November 7, 2018 16:07
-
-
Save roipeker/abfbe83e1f973fa9fad519f96e55a950 to your computer and use it in GitHub Desktop.
FeathersUtils.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ================================================================================================= | |
// | |
// Created by Rodrigo Lopez [roipeker™] on 07/11/2018. | |
// | |
// ================================================================================================= | |
package com.roipeker.feathers { | |
import feathers.core.FeathersControl; | |
import flash.utils.Dictionary; | |
import starling.events.Event; | |
public class FeathersUtils { | |
//============================================ | |
// Toggles FeatherControl layout resize. | |
// Useful for UI animations without breaking | |
// layout. | |
//============================================ | |
private static var _controlResizeMap:Dictionary = new Dictionary(true); | |
/** | |
* Add a FeathersControl to be captured. | |
* Do it as soon as you initialize the component so the RESIZE | |
* callback gets priority. | |
* | |
* @param control FeatherControl | |
*/ | |
public static function addControlResize(control:FeathersControl):void { | |
if (control in _controlResizeMap) return; | |
_controlResizeMap[control] = false; | |
control.addEventListener(Event.RESIZE, handleControlResize); | |
} | |
public static function isControlResizeBlocked(control:FeathersControl):Boolean { | |
return _controlResizeMap[control]; | |
} | |
public static function hasControlResize(control:FeathersControl):Boolean { | |
return control in _controlResizeMap; | |
} | |
/** | |
* When you don't need to animate the control anymore. | |
* Call before disposing. | |
* | |
* @param control | |
*/ | |
public static function removeControlResize(control:FeathersControl):void { | |
control.removeEventListener(Event.RESIZE, handleControlResize); | |
delete _controlResizeMap[control]; | |
} | |
/** | |
* Block/Unblocks the Resize event propagation to avoid unwanted layout | |
* changes when animating size. | |
* | |
* @param control FeathersControl | |
* @param blockResize Boolean flag that indicates if the Layout resize gets blocked. | |
*/ | |
public static function blockControlResize(control:FeathersControl, blockResize:Boolean):void { | |
if (!_controlResizeMap[control]) { | |
addControlResize(control); | |
} | |
_controlResizeMap[control] = blockResize; | |
} | |
private static function handleControlResize(event:Event):void { | |
if (_controlResizeMap[event.currentTarget]) { | |
event.stopImmediatePropagation(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment