Skip to content

Commit

Permalink
remove __orientationChanged listener on editbox destroyed (cocos#3464)
Browse files Browse the repository at this point in the history
  • Loading branch information
PPpro authored and pandamicro committed Nov 5, 2018
1 parent 7b574ee commit ef745b9
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions cocos2d/core/components/editbox/CCEditBoxImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ef745b9

Please sign in to comment.