fix(chat): scope keyboard avoidance to Facebook IAB

This commit is contained in:
2026-07-16 16:41:02 +08:00
parent aa801a3e18
commit 514297f469
4 changed files with 55 additions and 23 deletions
@@ -44,7 +44,7 @@ export function useChatKeyboardAvoidance({
}, [active]);
useEffect(() => {
if (typeof window === "undefined" || !PlatformDetector.isAndroid()) {
if (typeof window === "undefined" || !isKeyboardAvoidanceEnabled()) {
return;
}
@@ -72,16 +72,16 @@ export function useChatKeyboardAvoidance({
const container = containerRef.current;
if (typeof window === "undefined" || !container) return;
if (!active || !PlatformDetector.isAndroid()) {
const enabled = isKeyboardAvoidanceEnabled();
if (!active || !enabled) {
clearBottomInset(container);
if (!active) baselineRef.current = readViewportBaseline();
if (!active && enabled) baselineRef.current = readViewportBaseline();
return;
}
const baseline = baselineRef.current ?? readViewportBaseline();
const visualViewport = window.visualViewport;
const virtualKeyboard = getVirtualKeyboard();
const fallbackAllowed = BrowserDetector.isFacebookInAppBrowser();
let frameId: number | null = null;
let fallbackTimerId: number | null = null;
let lastInset = -1;
@@ -194,8 +194,6 @@ export function useChatKeyboardAvoidance({
applyBottomInset(resolution.bottomInset, resolution.source);
return;
}
if (!fallbackAllowed) return;
fallbackApplied = true;
applyBottomInset(
resolveChatKeyboardFallbackInset(baseline.layoutHeight),
@@ -246,3 +244,9 @@ function getVirtualKeyboard(): VirtualKeyboardLike | null {
function clearBottomInset(container: HTMLElement): void {
container.style.removeProperty(CHAT_KEYBOARD_BOTTOM_INSET_VAR);
}
function isKeyboardAvoidanceEnabled(): boolean {
return (
PlatformDetector.isAndroid() && BrowserDetector.isFacebookInAppBrowser()
);
}