From 07cb26f1fc4bd5188319b3eb4c39782632eace9f Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 4 Jul 2016 15:05:42 +0800 Subject: [PATCH 1/2] should remove listeners when child removed --- cocos2d/core/components/CCLayout.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/cocos2d/core/components/CCLayout.js b/cocos2d/core/components/CCLayout.js index f65b122062..6835bf6750 100644 --- a/cocos2d/core/components/CCLayout.js +++ b/cocos2d/core/components/CCLayout.js @@ -360,8 +360,8 @@ var Layout = cc.Class({ this.node.on('size-changed', this._resized, this); this.node.on('anchor-changed', this._doLayoutDirty, this); - this.node.on('child-added', this._childrenAddOrDeleted, this); - this.node.on('child-removed', this._childrenAddOrDeleted, this); + this.node.on('child-added', this._childAdded, this); + this.node.on('child-removed', this._childRemoved, this); this.node.on('child-reorder', this._doLayoutDirty, this); this._updateChildrenEventListener(); @@ -381,8 +381,23 @@ var Layout = cc.Class({ }.bind(this)); }, - _childrenAddOrDeleted: function() { - this._updateChildrenEventListener(); + _childAdded: function(event) { + var child = event.detail; + child.on('size-changed', this._doLayoutDirty, this); + child.on('position-changed', this._doLayoutDirty, this); + child.on('anchor-changed', this._doLayoutDirty, this); + child.on('active-in-hierarchy-changed', this._doLayoutDirty, this); + + this._doLayoutDirty(); + }, + + _childRemoved: function(event) { + var child = event.detail; + child.off('size-changed', this._doLayoutDirty, this); + child.off('position-changed', this._doLayoutDirty, this); + child.off('anchor-changed', this._doLayoutDirty, this); + child.off('active-in-hierarchy-changed', this._doLayoutDirty, this); + this._doLayoutDirty(); }, From 7fbd7364e5d831be8bfcd7584197a58196c0f230 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 4 Jul 2016 15:07:42 +0800 Subject: [PATCH 2/2] fix child active issue in none layout --- cocos2d/core/components/CCLayout.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cocos2d/core/components/CCLayout.js b/cocos2d/core/components/CCLayout.js index 6835bf6750..ccc5ba74cf 100644 --- a/cocos2d/core/components/CCLayout.js +++ b/cocos2d/core/components/CCLayout.js @@ -657,6 +657,10 @@ var Layout = cc.Class({ var allChildrenBoundingBox = null; children.forEach(function(child){ + if (!child.activeInHierarchy) { + return; + } + if(!allChildrenBoundingBox){ allChildrenBoundingBox = child.getBoundingBoxToWorld(); } else {