diff --git a/platforms/minigame/common/engine/Editbox.js b/platforms/minigame/common/engine/Editbox.js index 9c04ca35cc..619439a445 100644 --- a/platforms/minigame/common/engine/Editbox.js +++ b/platforms/minigame/common/engine/Editbox.js @@ -57,7 +57,7 @@ return; } this._ensureKeyboardHide(() => { - let delegate = this._delegate; + const delegate = this._delegate; this._showKeyboard(); this._registerKeyboardEvent(); this._editing = true; @@ -68,33 +68,36 @@ endEditing () { this._hideKeyboard(); - let cbs = this._eventListeners; + const cbs = this._eventListeners; cbs.onKeyboardComplete && cbs.onKeyboardComplete(); }, _registerKeyboardEvent () { - let self = this; - let delegate = this._delegate; - let cbs = this._eventListeners; + const self = this; + const delegate = this._delegate; + const cbs = this._eventListeners; cbs.onKeyboardInput = function (res) { if (delegate._string !== res.value) { delegate._editBoxTextChanged(res.value); } - } + }; cbs.onKeyboardConfirm = function (res) { res && res.value ? delegate._editBoxEditingReturn(res.value) : delegate._editBoxEditingReturn(); - let cbs = self._eventListeners; + const cbs = self._eventListeners; cbs.onKeyboardComplete && cbs.onKeyboardComplete(); - } + }; cbs.onKeyboardComplete = function (res) { self._editing = false; _currentEditBoxImpl = null; - self._unregisterKeyboardEvent(); + // wechat program do not have offKeyboard related callback + if (cc.sys.platform !== cc.sys.Platform.WECHAT_MINI_PROGRAM) { + self._unregisterKeyboardEvent(); + } res && res.value ? delegate._editBoxEditingDidEnded(res.value) : delegate._editBoxEditingDidEnded(); - } + }; __globalAdapter.onKeyboardInput(cbs.onKeyboardInput); __globalAdapter.onKeyboardConfirm(cbs.onKeyboardConfirm); @@ -102,7 +105,7 @@ }, _unregisterKeyboardEvent () { - let cbs = this._eventListeners; + const cbs = this._eventListeners; if (cbs.onKeyboardInput) { __globalAdapter.offKeyboardInput(cbs.onKeyboardInput); @@ -123,7 +126,7 @@ }, _ensureKeyboardHide (cb) { - let otherEditing = this._otherEditing(); + const otherEditing = this._otherEditing(); if (!otherEditing && !_hideKeyboardTimeout) { return cb(); } @@ -140,8 +143,8 @@ }, _showKeyboard () { - let delegate = this._delegate; - let multiline = (delegate.inputMode === EditBoxComp.InputMode.ANY); + const delegate = this._delegate; + const multiline = (delegate.inputMode === EditBoxComp.InputMode.ANY); __globalAdapter.showKeyboard({ defaultValue: delegate.string, maxLength: delegate.maxLength < 0 ? MAX_VALUE : delegate.maxLength, @@ -153,7 +156,7 @@ }, fail (res) { cc.warn(res.errMsg); - } + }, }); }, @@ -168,5 +171,4 @@ }); }, }); -})(); - +}()); diff --git a/templates/wechatprogram/app.js b/templates/wechatprogram/app.js index 73830e582b..b5bc1b4052 100755 --- a/templates/wechatprogram/app.js +++ b/templates/wechatprogram/app.js @@ -23,6 +23,11 @@ App({ _touchMove: undefined, _touchEnd: undefined, _touchCancel: undefined, + showInput: false, + indexThis: undefined, + _onKeyboardInput: undefined, + _onKeyboardConfirm: undefined, + _onKeyboardComplete: undefined, }, onLaunch() { }, diff --git a/templates/wechatprogram/game.ejs b/templates/wechatprogram/game.ejs index f4d4a7a342..ab5a5d6ed4 100644 --- a/templates/wechatprogram/game.ejs +++ b/templates/wechatprogram/game.ejs @@ -2,6 +2,7 @@ globalThis.__wxRequire = require; var GameGlobal = getApp().GameGlobal; Page({ onReady() { + GameGlobal.indexThis = this; const query = wx.createSelectorQuery() query.select('#myCanvas').node().exec(async (res) => { const canvas = res[0].node; @@ -67,6 +68,20 @@ Page({ }) }, + onKeyboardInput: function (event) { + GameGlobal._onKeyboardInput && GameGlobal._onKeyboardInput(event); + }, + + onKeyboardConfirm: function (event) { + console.log(event.detail.value); + GameGlobal._onKeyboardConfirm && GameGlobal._onKeyboardConfirm(event); + }, + + onKeyboardComplete: function (event) { + console.log(event.detail.value); + GameGlobal._onKeyboardComplete && GameGlobal._onKeyboardComplete(event); + }, + touchStart(event) { GameGlobal._touchStart && GameGlobal._touchStart(event); }, diff --git a/templates/wechatprogram/index.wxml b/templates/wechatprogram/index.wxml index 45731f249c..08154ba88a 100755 --- a/templates/wechatprogram/index.wxml +++ b/templates/wechatprogram/index.wxml @@ -1,5 +1,17 @@ + + +