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