fix(chat): allow Xiaomi Facebook keyboard fallback

This commit is contained in:
2026-06-24 16:14:10 +08:00
parent 3624c08387
commit a68dfbfa99
+12 -4
View File
@@ -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;