diff --git a/cocos2d/core/components/editbox/CCEditBoxImpl.js b/cocos2d/core/components/editbox/CCEditBoxImpl.js index a05efabb02..f198c565d7 100644 --- a/cocos2d/core/components/editbox/CCEditBoxImpl.js +++ b/cocos2d/core/components/editbox/CCEditBoxImpl.js @@ -45,6 +45,8 @@ let _matrix = math.mat4.create(); let _matrix_temp = math.mat4.create(); let _vec3 = cc.v3(); +let _currentEditBoxImpl = null; + // polyfill let polyfill = { zoomInvalid: false @@ -254,6 +256,11 @@ let EditBoxImpl = cc.Class({ }, _beginEditing () { + if (cc.sys.isMobile && !this._editing) { + // Pre adaptation + this._beginEditingOnMobile(); + } + if (this._edTxt) { this._edTxt.style.display = ''; @@ -273,10 +280,6 @@ let EditBoxImpl = cc.Class({ } } - if (cc.sys.isMobile && !this._editing) { - // Pre adaptation and - this._beginEditingOnMobile(); - } this._editing = true; }, @@ -444,6 +447,7 @@ _p._beginEditingOnMobile = function () { } this.__autoResize = cc.view._resizeWithBrowserSize; cc.view.resizeWithBrowserSize(false); + _currentEditBoxImpl = this; }; // Called after keyboard disappeared to readapte the game view @@ -463,11 +467,15 @@ _p._endEditingOnMobile = function () { window.removeEventListener('orientationchange', this.__orientationChanged); - window.scrollTo && window.scrollTo(0, 0); if(this.__fullscreen) { cc.view.enableAutoFullScreen(true); } - if (this.__autoResize) { + + // In case focus on editBox A from editBox B + // A disable resizeWithBrowserSize + // whilte B enable resizeWithBrowserSize + // Only _currentEditBoxImpl can enable resizeWithBrowserSize + if (this.__autoResize && _currentEditBoxImpl === this) { cc.view.resizeWithBrowserSize(true); } }; @@ -515,7 +523,7 @@ function registerInputEventListener (tmpEdTxt, editBoxImpl, isTextarea) { } if (cc.sys.isMobile) { - editBoxImpl._onFocusOnMobile(); + editBoxImpl._beginEditingOnMobile(); } if (editBoxImpl._delegate && editBoxImpl._delegate.editBoxEditingDidBegan) { @@ -550,24 +558,6 @@ function registerInputEventListener (tmpEdTxt, editBoxImpl, isTextarea) { editBoxImpl._addDomToGameContainer(); } -// Called after editbox focus to readapte the game view -_p._onFocusOnMobile = function (editBox) { - if (cc.view._isRotated) { - cc.game.container.style['-webkit-transform'] = 'rotate(0deg)'; - cc.game.container.style.transform = 'rotate(0deg)'; - cc.view._isRotated = false; - let policy = cc.view.getResolutionPolicy(); - policy.apply(cc.view, cc.view.getDesignResolutionSize()); - cc.view._isRotated = true; - //use window scrollTo to adjust the input area - window.scrollTo(35, 35); - this.__rotateScreen = true; - } else { - this.__rotateScreen = false; - } - this._adjustEditBoxPosition(); -}; - _p._createDomInput = function () { this.removeDom();