Skip to content

Commit

Permalink
feat(my-alipay): uni.onKeyboardHeightChange 支持支付宝小程序
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenyuWang committed Oct 24, 2022
1 parent c6cfc7c commit 56769ee
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/platforms/mp-alipay/runtime/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import {
hasOwn
} from 'uni-shared'

import { $on, $off } from 'uni-core/runtime/event-bus'

let onKeyboardHeightChangeCallback

export {
setStorageSync,
getStorageSync,
Expand Down Expand Up @@ -104,6 +108,21 @@ export function createIntersectionObserver (component, options) {
return my.createIntersectionObserver(options)
}

export function onKeyboardHeightChange (callback) {
// 与微信小程序一致仅保留最后一次监听
if (onKeyboardHeightChangeCallback) {
$off('uni:keyboardHeightChange', onKeyboardHeightChangeCallback)
}
onKeyboardHeightChangeCallback = callback
$on('uni:keyboardHeightChange', onKeyboardHeightChangeCallback)
}

export function offKeyboardHeightChange () {
// 与微信小程序一致移除最后一次监听
$off('uni:keyboardHeightChange', onKeyboardHeightChangeCallback)
onKeyboardHeightChangeCallback = null
}

export {
createMediaQueryObserver
}
5 changes: 5 additions & 0 deletions src/platforms/mp-alipay/runtime/wrapper/page-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
initSpecialMethods
} from './util'

import { $emit } from 'uni-core/runtime/event-bus'

const hooks = [
'onShow',
'onHide',
Expand Down Expand Up @@ -84,6 +86,9 @@ export default function parsePage (vuePageOptions) {
// 支付宝小程序有些页面事件只能放在events下
onBack () {
this.$vm.__call_hook('onBackPress')
},
onKeyboardHeight (res) {
$emit('uni:keyboardHeightChange', res)
}
},
__r: handleRef,
Expand Down

0 comments on commit 56769ee

Please sign in to comment.