Dismiss keyboard when opening mobile sidebar

This commit is contained in:
Mohamed Boudra
2026-05-03 14:17:15 +07:00
parent f3de568969
commit f993b1d856

View File

@@ -7,10 +7,11 @@ import {
useRef,
type ReactNode,
} from "react";
import { useWindowDimensions } from "react-native";
import { Keyboard, useWindowDimensions } from "react-native";
import { useSharedValue, withTiming, Easing, type SharedValue } from "react-native-reanimated";
import { type GestureType } from "react-native-gesture-handler";
import { useIsCompactFormFactor } from "@/constants/layout";
import { isNative } from "@/constants/platform";
import { selectIsAgentListOpen, usePanelStore } from "@/stores/panel-store";
import {
getLeftSidebarAnimationTargets,
@@ -65,11 +66,16 @@ export function SidebarAnimationProvider({ children }: { children: ReactNode })
const previousIsOpen = prevIsOpen.current;
prevIsOpen.current = isOpen;
prevWindowWidth.current = windowWidth;
const didOpen = !previousIsOpen && isOpen;
if (!didStateChange) {
return;
}
if (didOpen && isCompactLayout && isNative) {
Keyboard.dismiss();
}
// Gesture onEnd already started the animation on the UI thread — skip to avoid
// a second competing withTiming that can desync translateX and backdropOpacity
// after a provider remount (e.g. theme change).
@@ -99,7 +105,7 @@ export function SidebarAnimationProvider({ children }: { children: ReactNode })
translateX.value = targets.translateX;
backdropOpacity.value = targets.backdropOpacity;
}, [isOpen, translateX, backdropOpacity, windowWidth, isGesturing]);
}, [isOpen, translateX, backdropOpacity, windowWidth, isGesturing, isCompactLayout]);
const animateToOpen = useCallback(() => {
"worklet";