diff --git a/packages/uni-components/src/helpers/useKeyboard.ts b/packages/uni-components/src/helpers/useKeyboard.ts index a56db1346b094eb9593d6fc5e6bb2542e8531791..4dbba6c78d2a9475be9fd99c9a2f18a49a406095 100644 --- a/packages/uni-components/src/helpers/useKeyboard.ts +++ b/packages/uni-components/src/helpers/useKeyboard.ts @@ -7,6 +7,7 @@ let isAndroid: boolean let osVersion: string let keyboardHeight: number let keyboardChangeCallback: Function | null +let webviewStyle: PlusWebviewWebviewStyles interface KeyboardChangeEvent extends Event { height: number } @@ -40,7 +41,7 @@ function setSoftinputTemporary( const MODE_ADJUSTPAN = 'adjustPan' const MODE_NOTHING = 'nothing' const currentWebview = plus.webview.currentWebview() - const style = currentWebview.getStyle() || {} + const style = webviewStyle || currentWebview.getStyle() || {} const options = { mode: reset || style.softinputMode === MODE_ADJUSTRESIZE @@ -176,24 +177,35 @@ export function useKeyboard( if (__PLATFORM__ === 'app') { // 安卓单独隐藏键盘后点击输入框不会触发 focus 事件 - el.addEventListener('click', () => { - if ( - !props.disabled && - !props.readOnly && - focus && - keyboardHeight === 0 - ) { - setSoftinputTemporary(props, el) - } - }) - if (!isAndroid && parseInt(osVersion) < 12) { - // iOS12 以下系统 focus 事件设置较迟,改在 touchstart 设置 - el.addEventListener('touchstart', () => { - if (!props.disabled && !props.readOnly && !focus) { + if (isAndroid) { + el.addEventListener('click', () => { + if ( + !props.disabled && + !props.readOnly && + focus && + keyboardHeight === 0 + ) { setSoftinputTemporary(props, el) } }) } + if (!isAndroid) { + if (parseInt(osVersion) < 12) { + // iOS12 以下系统 focus 事件设置较迟,改在 touchstart 设置 + el.addEventListener('touchstart', () => { + if (!props.disabled && !props.readOnly && !focus) { + setSoftinputTemporary(props, el) + } + }) + } + // iOS 14.6 调用同步方法导致键盘弹卡顿 + if (parseFloat(osVersion) >= 14.6 && !webviewStyle) { + plusReady(() => { + const currentWebview = plus.webview.currentWebview() + webviewStyle = currentWebview.getStyle() || {} + }) + } + } } const onKeyboardHide = () => {