diff --git a/lib/apis.js b/lib/apis.js index 4a40ae5fb0624c347927103b069d39a584f8232b..dc6fb851f886e164847ed605a6755ce2f5a9a22e 100644 --- a/lib/apis.js +++ b/lib/apis.js @@ -115,7 +115,8 @@ const device = [ ] const keyboard = [ - 'hideKeyboard' + 'hideKeyboard', + 'onKeyboardHeightChange' ] const ui = [ diff --git a/lib/modules.json b/lib/modules.json index 5f1a2b1d948cdb590c2b5778a62aa311cd6b930b..2ec88debba4789cd2e9a28bc3356af69e20838af 100644 --- a/lib/modules.json +++ b/lib/modules.json @@ -152,7 +152,8 @@ "uni.stopPullDownRefresh": true, "uni.createSelectorQuery": true, "uni.createIntersectionObserver": true, - "uni.hideKeyboard": true + "uni.hideKeyboard": true, + "uni.onKeyboardHeightChange": true } }, { "name": "event", diff --git a/src/core/service/api/ui/keyboard.js b/src/core/service/api/ui/keyboard.js new file mode 100644 index 0000000000000000000000000000000000000000..e01c473139553537933c2baf50874385d7667c2b --- /dev/null +++ b/src/core/service/api/ui/keyboard.js @@ -0,0 +1,19 @@ +import { + invoke +} from 'uni-core/service/bridge' + +import { + onMethod +} from '../../platform' + +const callbacks = [] + +onMethod('onKeyboardHeightChange', res => { + callbacks.forEach(callbackId => { + invoke(callbackId, res) + }) +}) + +export function onKeyboardHeightChange (callbackId) { + callbacks.push(callbackId) +} diff --git a/src/platforms/app-plus/service/framework/app.js b/src/platforms/app-plus/service/framework/app.js index c5630b07ae377b1276c7debf562d77dd33d86bf9..532b8693e982de628a09cdd025cac0b835d693b0 100644 --- a/src/platforms/app-plus/service/framework/app.js +++ b/src/platforms/app-plus/service/framework/app.js @@ -62,6 +62,12 @@ function initGlobalListeners () { isConnected: networkType !== 'none', networkType }) + }) + + plus.globalEvent.addEventListener('KeyboardHeightChange', function (event) { + publish('onKeyboardHeightChange', { + height: event.height + }) }) }