You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
941 B
38 lines
941 B
import {
|
|
onMethod
|
|
} from '../../../../../core/service/platform'
|
|
|
|
const isAndroid = plus.os.name.toLowerCase() === 'android'
|
|
const FOCUS_TIMEOUT = isAndroid ? 300 : 700
|
|
let keyboardHeight = 0
|
|
let onKeyboardShow
|
|
let focusTimer
|
|
|
|
export function hookKeyboardEvent (event, callback) {
|
|
onKeyboardShow = null
|
|
focusTimer && clearTimeout(focusTimer)
|
|
if (event.type === 'focus') {
|
|
if (keyboardHeight > 0) {
|
|
event.detail.height = keyboardHeight
|
|
} else {
|
|
focusTimer = setTimeout(function () {
|
|
event.detail.height = keyboardHeight
|
|
callback(event)
|
|
}, FOCUS_TIMEOUT)
|
|
onKeyboardShow = function () {
|
|
clearTimeout(focusTimer)
|
|
event.detail.height = keyboardHeight
|
|
callback(event)
|
|
}
|
|
return
|
|
}
|
|
}
|
|
callback(event)
|
|
}
|
|
|
|
onMethod('onKeyboardHeightChange', res => {
|
|
keyboardHeight = res.height
|
|
if (keyboardHeight > 0) {
|
|
onKeyboardShow && onKeyboardShow()
|
|
}
|
|
})
|
|
|