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; rafId = null;
const metrics = readViewportMetrics(); const metrics = readViewportMetrics();
const activeNow = isKeyboardTargetActive(targetRef?.current, activeRef.current);
if ( if (
activeRef.current && activeNow &&
fallbackAllowedRef.current && fallbackAllowedRef.current &&
lastMayBeKeyboardClose && lastMayBeKeyboardClose &&
shouldReleaseFallback(metrics, focusedAtRef.current) shouldReleaseFallback(metrics, focusedAtRef.current)
@@ -86,7 +87,7 @@ export function useKeyboardHeight({
? computeFallbackLift(metrics) ? computeFallbackLift(metrics)
: 0; : 0;
const inputLift = Math.round( const inputLift = Math.round(
activeRef.current activeNow
? Math.max( ? Math.max(
computeTargetOverlap(targetRef?.current, metrics.visibleBottom), computeTargetOverlap(targetRef?.current, metrics.visibleBottom),
fallbackLift, fallbackLift,
@@ -118,7 +119,8 @@ export function useKeyboardHeight({
); );
log.debug("[keyboard] apply", { log.debug("[keyboard] apply", {
environment, environment,
active: activeRef.current, active: activeNow,
reactActive: activeRef.current,
inputLift, inputLift,
fallbackLift, fallbackLift,
fallbackAllowed: fallbackAllowedRef.current, fallbackAllowed: fallbackAllowedRef.current,
@@ -232,7 +234,6 @@ function computeTargetOverlap(
function computeFallbackLift(metrics: ViewportMetrics): number { function computeFallbackLift(metrics: ViewportMetrics): number {
if (!shouldUseInAppKeyboardFallback()) return 0; if (!shouldUseInAppKeyboardFallback()) return 0;
if (metrics.hasVirtualKeyboard && metrics.keyboardHeight <= 0) return 0;
const viewportAlreadyShrank = metrics.visibleHeight < metrics.layoutHeight * 0.82; const viewportAlreadyShrank = metrics.visibleHeight < metrics.layoutHeight * 0.82;
const keyboardAlreadyDetected = metrics.keyboardHeight > 80; const keyboardAlreadyDetected = metrics.keyboardHeight > 80;
@@ -265,6 +266,13 @@ function isPossibleKeyboardCloseEvent(event: Event): boolean {
return event.type === "resize" || event.type === "geometrychange"; 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 { function shouldUseInAppKeyboardFallback(): boolean {
if (typeof navigator === "undefined") return false; if (typeof navigator === "undefined") return false;
const ua = navigator.userAgent; const ua = navigator.userAgent;