From ce2e117136cc056412f9e4bb67feab721b06584f Mon Sep 17 00:00:00 2001 From: qiang Date: Tue, 13 Aug 2019 19:58:11 +0800 Subject: [PATCH] feat: app-plus add uni.onKeyboardHeightChange --- lib/apis.js | 3 ++- lib/modules.json | 3 ++- src/core/service/api/ui/keyboard.js | 19 +++++++++++++++++++ .../app-plus/service/framework/app.js | 6 ++++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/core/service/api/ui/keyboard.js diff --git a/lib/apis.js b/lib/apis.js index 4a40ae5fb..dc6fb851f 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 5f1a2b1d9..2ec88debb 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 000000000..e01c47313 --- /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 c5630b07a..532b8693e 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 + }) }) } -- GitLab