mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
0a836ac458
* optimize sys info init in adapters update * update sys init update sys * fix sys access * optimize isWebIOS14OrIPadOS14Env * update * update * update QTT adapter * update sys.capacities update sys * update common && qtt * add downloadFile to job module * update engine-adapter * update DeviceMotionEvent adaption * remove legacy qtt * add link-sure adaption * fix some bug * update vivo adaption && fs-utils * remove legacy link-sure * remove dom-adapter * remove HTMLCanvas appended to document * update vivo * support COCOS_PLAY * update adapters to platforms * remove test code * add OPPO adapter * add huawei adapter * remove test code * rename folder oppo-mini-game * rename folder huawei-quick-game * rename folder vivo-mini-game
173 lines
5.2 KiB
JavaScript
173 lines
5.2 KiB
JavaScript
(function () {
|
|
if (!(cc && cc.EditBoxComponent)) {
|
|
return;
|
|
}
|
|
|
|
const EditBoxComp = cc.EditBoxComponent;
|
|
const js = cc.js;
|
|
const KeyboardReturnType = EditBoxComp.KeyboardReturnType;
|
|
const MAX_VALUE = 65535;
|
|
const KEYBOARD_HIDE_TIME = 600;
|
|
let _hideKeyboardTimeout = null;
|
|
let _currentEditBoxImpl = null;
|
|
|
|
function getKeyboardReturnType (type) {
|
|
switch (type) {
|
|
case KeyboardReturnType.DEFAULT:
|
|
case KeyboardReturnType.DONE:
|
|
return 'done';
|
|
case KeyboardReturnType.SEND:
|
|
return 'send';
|
|
case KeyboardReturnType.SEARCH:
|
|
return 'search';
|
|
case KeyboardReturnType.GO:
|
|
return 'go';
|
|
case KeyboardReturnType.NEXT:
|
|
return 'next';
|
|
}
|
|
return 'done';
|
|
}
|
|
|
|
function MiniGameEditBoxImpl () {
|
|
this._delegate = null;
|
|
this._editing = false;
|
|
|
|
this._eventListeners = {
|
|
onKeyboardInput: null,
|
|
onKeyboardConfirm: null,
|
|
onKeyboardComplete: null,
|
|
};
|
|
}
|
|
|
|
js.extend(MiniGameEditBoxImpl, EditBoxComp._EditBoxImpl);
|
|
EditBoxComp._EditBoxImpl = MiniGameEditBoxImpl;
|
|
|
|
Object.assign(MiniGameEditBoxImpl.prototype, {
|
|
init (delegate) {
|
|
if (!delegate) {
|
|
cc.error('EditBox init failed');
|
|
return;
|
|
}
|
|
this._delegate = delegate;
|
|
},
|
|
|
|
beginEditing () {
|
|
// In case multiply register events
|
|
if (this._editing) {
|
|
return;
|
|
}
|
|
this._ensureKeyboardHide(() => {
|
|
let delegate = this._delegate;
|
|
this._showKeyboard();
|
|
this._registerKeyboardEvent();
|
|
this._editing = true;
|
|
_currentEditBoxImpl = this;
|
|
delegate.editBoxEditingDidBegan();
|
|
});
|
|
},
|
|
|
|
endEditing () {
|
|
this._hideKeyboard();
|
|
let cbs = this._eventListeners;
|
|
cbs.onKeyboardComplete && cbs.onKeyboardComplete();
|
|
},
|
|
|
|
_registerKeyboardEvent () {
|
|
let self = this;
|
|
let delegate = this._delegate;
|
|
let cbs = this._eventListeners;
|
|
|
|
cbs.onKeyboardInput = function (res) {
|
|
if (delegate._string !== res.value) {
|
|
delegate._editBoxTextChanged(res.value);
|
|
}
|
|
}
|
|
|
|
cbs.onKeyboardConfirm = function (res) {
|
|
delegate._editBoxEditingReturn();
|
|
let cbs = self._eventListeners;
|
|
cbs.onKeyboardComplete && cbs.onKeyboardComplete();
|
|
}
|
|
|
|
cbs.onKeyboardComplete = function () {
|
|
self._editing = false;
|
|
_currentEditBoxImpl = null;
|
|
self._unregisterKeyboardEvent();
|
|
delegate._editBoxEditingDidEnded();
|
|
}
|
|
|
|
jsb.onKeyboardInput(cbs.onKeyboardInput);
|
|
jsb.onKeyboardConfirm(cbs.onKeyboardConfirm);
|
|
jsb.onKeyboardComplete(cbs.onKeyboardComplete);
|
|
},
|
|
|
|
_unregisterKeyboardEvent () {
|
|
let cbs = this._eventListeners;
|
|
|
|
if (cbs.onKeyboardInput) {
|
|
jsb.offKeyboardInput(cbs.onKeyboardInput);
|
|
cbs.onKeyboardInput = null;
|
|
}
|
|
if (cbs.onKeyboardConfirm) {
|
|
jsb.offKeyboardConfirm(cbs.onKeyboardConfirm);
|
|
cbs.onKeyboardConfirm = null;
|
|
}
|
|
if (cbs.onKeyboardComplete) {
|
|
jsb.offKeyboardComplete(cbs.onKeyboardComplete);
|
|
cbs.onKeyboardComplete = null;
|
|
}
|
|
},
|
|
|
|
_otherEditing () {
|
|
return !!_currentEditBoxImpl && _currentEditBoxImpl !== this && _currentEditBoxImpl._editing;
|
|
},
|
|
|
|
_ensureKeyboardHide (cb) {
|
|
let otherEditing = this._otherEditing();
|
|
if (!otherEditing && !_hideKeyboardTimeout) {
|
|
return cb();
|
|
}
|
|
if (_hideKeyboardTimeout) {
|
|
clearTimeout(_hideKeyboardTimeout);
|
|
}
|
|
if (otherEditing) {
|
|
_currentEditBoxImpl.endEditing();
|
|
}
|
|
_hideKeyboardTimeout = setTimeout(() => {
|
|
_hideKeyboardTimeout = null;
|
|
cb();
|
|
}, KEYBOARD_HIDE_TIME);
|
|
},
|
|
|
|
_showKeyboard () {
|
|
let delegate = this._delegate;
|
|
let multiline = (delegate.inputMode === EditBoxComp.InputMode.ANY);
|
|
jsb.showKeyboard({
|
|
defaultValue: delegate.string,
|
|
maxLength: delegate.maxLength < 0 ? MAX_VALUE : delegate.maxLength,
|
|
multiple: multiline,
|
|
confirmHold: false,
|
|
confirmType: getKeyboardReturnType(delegate.returnType),
|
|
success (res) {
|
|
|
|
},
|
|
fail (res) {
|
|
cc.warn(res.errMsg);
|
|
}
|
|
});
|
|
},
|
|
|
|
_hideKeyboard () {
|
|
jsb.hideKeyboard({
|
|
success (res) {
|
|
|
|
},
|
|
fail (res) {
|
|
cc.warn(res.errMsg);
|
|
},
|
|
});
|
|
},
|
|
});
|
|
})();
|
|
|