提交 3f1132e3 编写于 作者: Q qiang

fix: input, textarea event use keyboardHeight (question/142253)

上级 c0c7c5d0
......@@ -10,6 +10,7 @@ import { initAppLaunch } from './initAppLaunch'
import { clearTempFile } from './clearTempFile'
import { initSubscribeHandlers } from './subscriber'
import { initVueApp } from './vueApp'
import { initKeyboardEvent } from '../dom/keyboard'
let appCtx: ComponentPublicInstance
const defaultApp = {
......@@ -60,6 +61,7 @@ export function registerApp(appVm: ComponentPublicInstance) {
initEntry()
initTabBar()
initGlobalEvent()
initKeyboardEvent()
initSubscribeHandlers()
initAppLaunch(appVm)
......
import { UniEvent, ON_KEYBOARD_HEIGHT_CHANGE } from '@dcloudio/uni-shared'
let focusTimeout = 0
let keyboardHeight = 0
let onKeyboardShow: (() => void) | null = null
let focusTimer: ReturnType<typeof setTimeout> | null = null
export function hookKeyboardEvent(
event: UniEvent,
callback: (event: UniEvent) => void
) {
onKeyboardShow = null
if (focusTimer) {
clearTimeout(focusTimer)
focusTimer = null
}
if (event.type === 'onFocus') {
if (keyboardHeight > 0) {
event.detail!.height = keyboardHeight
} else {
focusTimer = setTimeout(function () {
event.detail!.height = keyboardHeight
callback(event)
}, focusTimeout)
onKeyboardShow = function () {
if (focusTimer) {
clearTimeout(focusTimer)
focusTimer = null
}
event.detail!.height = keyboardHeight
callback(event)
}
return
}
}
callback(event)
}
export function initKeyboardEvent() {
const isAndroid = plus.os.name!.toLowerCase() === 'android'
focusTimeout = isAndroid ? 300 : 700
UniServiceJSBridge.on(
ON_KEYBOARD_HEIGHT_CHANGE,
(res: { height: number }) => {
keyboardHeight = res.height
if (keyboardHeight > 0) {
const callback = onKeyboardShow
onKeyboardShow = null
if (callback) {
callback()
}
}
}
)
}
import { ACTION_TYPE_EVENT, UniEvent } from '@dcloudio/uni-shared'
import UniPageNode from './Page'
import { hookKeyboardEvent } from './keyboard'
export type EventAction = [
typeof ACTION_TYPE_EVENT,
......@@ -12,5 +13,12 @@ export function onNodeEvent(
evt: UniEvent,
pageNode: UniPageNode
) {
pageNode.fireEvent(nodeId, evt)
const type = evt.type
if (type === 'onFocus' || type === 'onBlur') {
hookKeyboardEvent(evt, (evt) => {
pageNode.fireEvent(nodeId, evt)
})
} else {
pageNode.fireEvent(nodeId, evt)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册