From ef745b9bc8ab12e1e84879ce5b3f4b45e0b79fd7 Mon Sep 17 00:00:00 2001 From: PP Date: Mon, 5 Nov 2018 16:56:18 +0800 Subject: [PATCH] remove __orientationChanged listener on editbox destroyed (#3464) --- .../core/components/editbox/CCEditBoxImpl.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/cocos2d/core/components/editbox/CCEditBoxImpl.js b/cocos2d/core/components/editbox/CCEditBoxImpl.js index 6fd60f2b113..624e402e419 100644 --- a/cocos2d/core/components/editbox/CCEditBoxImpl.js +++ b/cocos2d/core/components/editbox/CCEditBoxImpl.js @@ -245,6 +245,10 @@ let EditBoxImpl = cc.Class({ this._node = null; this.setDelegate(null); this.removeDom(); + if (this.__orientationChanged) { + window.removeEventListener('orientationchange', this.__orientationChanged); + this.__orientationChanged = null; + } }, _onTouchBegan (touch) { @@ -433,10 +437,12 @@ _p.createInput = function() { // Called before editbox focus to register cc.view status _p._beginEditingOnMobile = function () { let self = this; - this.__orientationChanged = function () { - self._adjustEditBoxPosition(); - }; - window.addEventListener('orientationchange', this.__orientationChanged); + if (!this.__orientationChanged) { + this.__orientationChanged = function () { + self._adjustEditBoxPosition(); + }; + window.addEventListener('orientationchange', this.__orientationChanged); + } if (cc.view.isAutoFullScreenEnabled()) { this.__fullscreen = true; @@ -465,7 +471,10 @@ _p._endEditingOnMobile = function () { this.__rotateScreen = false; } - window.removeEventListener('orientationchange', this.__orientationChanged); + if (this.__orientationChanged) { + window.removeEventListener('orientationchange', this.__orientationChanged); + this.__orientationChanged = null; + } if(this.__fullscreen) { cc.view.enableAutoFullScreen(true);