diff --git a/haxe/ui/containers/ScrollView.hx b/haxe/ui/containers/ScrollView.hx index 0fd59bc8d..88de7793a 100644 --- a/haxe/ui/containers/ScrollView.hx +++ b/haxe/ui/containers/ScrollView.hx @@ -1363,29 +1363,38 @@ class ScrollViewBuilder extends CompositeBuilder { } var containsEmptyContentsComponent = _scrollview.containsChildComponent(emptyContentsComponent); - if (contentsComponent.numComponents == 0) { - if (!containsEmptyContentsComponent) { - emptyContentsComponent.addClass("empty-contents-component"); - _scrollview.addComponent(emptyContentsComponent); - } - - if (_scrollview.emptyContentsText != null) { - if ((emptyContentsComponent is Label)) { - emptyContentsComponent.text = _scrollview.emptyContentsText; - } else { - var label = emptyContentsComponent.findComponent(Label, true); - if (label != null) { - label.text = _scrollview.emptyContentsText; - } - } - } - - emptyContentsComponent.show(); + if (!containsContent(contentsComponent)) { + showEmptyContentsComponent(); } else if (containsEmptyContentsComponent) { emptyContentsComponent.hide(); } } + private function showEmptyContentsComponent() { + var emptyContentsComponent:Component = _scrollview.emptyContentsComponent; + if (emptyContentsComponent == null) { + return; + } + var containsEmptyContentsComponent = _scrollview.containsChildComponent(emptyContentsComponent); + if (!containsEmptyContentsComponent) { + emptyContentsComponent.addClass("empty-contents-component"); + _scrollview.addComponent(emptyContentsComponent); + } + + if (_scrollview.emptyContentsText != null) { + if ((emptyContentsComponent is Label)) { + emptyContentsComponent.text = _scrollview.emptyContentsText; + } else { + var label = emptyContentsComponent.findComponent(Label, true); + if (label != null) { + label.text = _scrollview.emptyContentsText; + } + } + } + + emptyContentsComponent.show(); + } + private override function get_numComponents():Null { return _contents.numComponents; } @@ -1406,10 +1415,9 @@ class ScrollViewBuilder extends CompositeBuilder { if ((child is HorizontalScroll) == false && (child is VerticalScroll) == false && child.hasClass("scrollview-contents") == false) { var contentsComponent = null; if ((child is Box)) { - child.registerEvent(UIEvent.COMPONENT_ADDED, onContentsChanged); - child.registerEvent(UIEvent.COMPONENT_REMOVED, onContentsChanged); contentsComponent = child; } + registerEventForChildrenBoxes(child); var r = _contents.addComponent(child); checkEmptyContentsComponent(contentsComponent); return r; @@ -1417,10 +1425,33 @@ class ScrollViewBuilder extends CompositeBuilder { return null; } + private function registerEventForChildrenBoxes(b:Component) { + if ((b is Box)||(b is ScrollView)){ + b.registerEvent(UIEvent.COMPONENT_ADDED, onContentsChanged); + b.registerEvent(UIEvent.COMPONENT_REMOVED, onContentsChanged); + for ( c in b.childComponents) { + registerEventForChildrenBoxes(c); + } + } + } + + private function containsContent(b:Component) { + if (!(b is Box) && !(b is ScrollView)) { + return true; + } else { + for ( c in b.childComponents) { + if (containsContent(c)) return true; + } + } + return false; + } + public override function addComponentAt(child:Component, index:Int):Component { if ((child is HorizontalScroll) == false && (child is VerticalScroll) == false && child.hasClass("scrollview-contents") == false) { var r = _contents.addComponentAt(child, index); - checkEmptyContentsComponent(); + if ( _scrollview.emptyContentsComponent != null && !_scrollview.emptyContentsComponent.hidden && containsContent(child)) { + checkEmptyContentsComponent(); + } return r; } return null; @@ -1432,7 +1463,9 @@ class ScrollViewBuilder extends CompositeBuilder { } if ((child is HorizontalScroll) == false && (child is VerticalScroll) == false && child.hasClass("scrollview-contents") == false) { var r = _contents.removeComponent(child, dispose, invalidate); - checkEmptyContentsComponent(); + if (containsContent(child)) { + checkEmptyContentsComponent(); + } return r; } return null; @@ -1478,8 +1511,16 @@ class ScrollViewBuilder extends CompositeBuilder { } } - private function onContentsChanged(event:UIEvent) { - checkEmptyContentsComponent(event.target); + private function onContentsChanged(event:UIEvent) { + var child = event.relatedComponent; + registerEventForChildrenBoxes(child); + if (event.type == UIEvent.COMPONENT_ADDED) { + if ( _scrollview.emptyContentsComponent != null && !_scrollview.emptyContentsComponent.hidden && containsContent(child)) { + _scrollview.emptyContentsComponent.hide(); + } + } else if ( _scrollview.emptyContentsComponent != null && _scrollview.emptyContentsComponent.hidden && containsContent(child)) { + checkEmptyContentsComponent(); + } } private function horizontalConstraintModifier():Float {