From a68dfbfa99000fd45048bd395a1c6c00f27746fa Mon Sep 17 00:00:00 2001 From: chenhang Date: Wed, 24 Jun 2026 16:14:10 +0800 Subject: [PATCH] fix(chat): allow Xiaomi Facebook keyboard fallback --- src/hooks/use-keyboard-height.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/hooks/use-keyboard-height.ts b/src/hooks/use-keyboard-height.ts index b5f09b2a..de509c3b 100644 --- a/src/hooks/use-keyboard-height.ts +++ b/src/hooks/use-keyboard-height.ts @@ -65,8 +65,9 @@ export function useKeyboardHeight({ rafId = null; const metrics = readViewportMetrics(); + const activeNow = isKeyboardTargetActive(targetRef?.current, activeRef.current); if ( - activeRef.current && + activeNow && fallbackAllowedRef.current && lastMayBeKeyboardClose && shouldReleaseFallback(metrics, focusedAtRef.current) @@ -86,7 +87,7 @@ export function useKeyboardHeight({ ? computeFallbackLift(metrics) : 0; const inputLift = Math.round( - activeRef.current + activeNow ? Math.max( computeTargetOverlap(targetRef?.current, metrics.visibleBottom), fallbackLift, @@ -118,7 +119,8 @@ export function useKeyboardHeight({ ); log.debug("[keyboard] apply", { environment, - active: activeRef.current, + active: activeNow, + reactActive: activeRef.current, inputLift, fallbackLift, fallbackAllowed: fallbackAllowedRef.current, @@ -232,7 +234,6 @@ function computeTargetOverlap( function computeFallbackLift(metrics: ViewportMetrics): number { if (!shouldUseInAppKeyboardFallback()) return 0; - if (metrics.hasVirtualKeyboard && metrics.keyboardHeight <= 0) return 0; const viewportAlreadyShrank = metrics.visibleHeight < metrics.layoutHeight * 0.82; const keyboardAlreadyDetected = metrics.keyboardHeight > 80; @@ -265,6 +266,13 @@ function isPossibleKeyboardCloseEvent(event: Event): boolean { return event.type === "resize" || event.type === "geometrychange"; } +function isKeyboardTargetActive( + target: HTMLElement | null | undefined, + reactActive: boolean, +): boolean { + return reactActive || (target != null && document.activeElement === target); +} + function shouldUseInAppKeyboardFallback(): boolean { if (typeof navigator === "undefined") return false; const ua = navigator.userAgent;