This is an automated email from the ASF dual-hosted git repository. aharui pushed a commit to branch ChildResize in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
commit 8ccfa56c28f457f725c7025b1779025d27060f64 Author: Alex Harui <[email protected]> AuthorDate: Mon Dec 7 19:50:57 2020 -0800 listen for child size changing --- .../layouts/supportClasses/SparkLayoutBead.as | 43 +++++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/frameworks/projects/SparkRoyale/src/main/royale/spark/layouts/supportClasses/SparkLayoutBead.as b/frameworks/projects/SparkRoyale/src/main/royale/spark/layouts/supportClasses/SparkLayoutBead.as index e1ed277..96a59ab 100644 --- a/frameworks/projects/SparkRoyale/src/main/royale/spark/layouts/supportClasses/SparkLayoutBead.as +++ b/frameworks/projects/SparkRoyale/src/main/royale/spark/layouts/supportClasses/SparkLayoutBead.as @@ -36,6 +36,7 @@ import org.apache.royale.core.LayoutBase; import org.apache.royale.core.UIBase; import org.apache.royale.events.Event; import org.apache.royale.events.EventDispatcher; +import org.apache.royale.events.IEventDispatcher; import org.apache.royale.utils.MXMLDataInterpreter; import org.apache.royale.utils.loadBeadFromValuesManager; @@ -78,9 +79,14 @@ public class SparkLayoutBead extends org.apache.royale.core.LayoutBase sawSizeChanged = true; super.handleSizeChange(event); } - + + private var ranLayout:Boolean; + private var inUpdateDisplayList:Boolean; + override public function layout():Boolean { + ranLayout = true; + var n:int = target.numChildren; if (n == 0) return false; @@ -107,7 +113,9 @@ public class SparkLayoutBead extends org.apache.royale.core.LayoutBase h = target.measuredHeight; if (target.layout.isWidthSizedToContent()) w = target.measuredWidth; + inUpdateDisplayList = true; target.layout.updateDisplayList(w, h); + inUpdateDisplayList = false; // update the target's actual size if needed. if (target.layout.isWidthSizedToContent() && target.layout.isHeightSizedToContent()) { @@ -136,7 +144,10 @@ public class SparkLayoutBead extends org.apache.royale.core.LayoutBase var host:UIBase = value as UIBase; _target = (host.view as ILayoutHost).contentView as GroupBase; super.strand = value; - + // The main layout may not get put on the strand until + // after children are added so listen here as well + if (target.parent) + listenToChildren(); } private var _target:GroupBase; @@ -151,5 +162,33 @@ public class SparkLayoutBead extends org.apache.royale.core.LayoutBase _target = value; } + override protected function handleChildrenAdded(event:Event):void + { + COMPILE::JS { + super.handleChildrenAdded(event); + listenToChildren(); + } + } + + private function listenToChildren():void + { + var n:Number = layoutView.numElements; + for(var i:int=0; i < n; i++) { + var child:IEventDispatcher = layoutView.getElementAt(i) as IEventDispatcher; + child.addEventListener("widthChanged", childResizeHandler); + child.addEventListener("heightChanged", childResizeHandler); + child.addEventListener("sizeChanged", childResizeHandler); + } + } + + override protected function childResizeHandler(event:Event):void + { + if (inUpdateDisplayList) return; + ranLayout = false; + super.childResizeHandler(event); // will set ranLayout if it did + if (!ranLayout) + performLayout(); + } + } }
