{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "native-hook-use-bottom-sheet-aware-handlers", "type": "registry:hook", "title": "Use Bottom Sheet Aware Handlers", "description": "Use Bottom Sheet Aware Handlers from @pitsi-ui/native for native projects.", "dependencies": [ "@gorhom/bottom-sheet@^5.2.8" ], "registryDependencies": [], "files": [ { "path": "registry/native-ui/src/helpers/external/hooks/use-bottom-sheet-aware-handlers.ts", "content": "import { useCallback } from \"react\";\nimport { type BlurEvent, type FocusEvent, findNodeHandle, TextInput } from \"react-native\";\nimport GorhomBottomSheetPackage from \"../../../optional/gorhom-bottom-sheet\";\n\n/**\n * Return type for the bottom-sheet-aware handlers hook\n */\ninterface UseBottomSheetAwareHandlersReturn {\n /** Focus handler that notifies the bottom sheet about the keyboard target */\n onFocus: (e: FocusEvent) => void;\n /** Blur handler that conditionally clears the keyboard target in the bottom sheet */\n onBlur: (e: BlurEvent) => void;\n}\n\n/**\n * Hook that provides onFocus/onBlur handlers for managing bottom sheet\n * keyboard state when an input is rendered inside a BottomSheet context.\n *\n * Uses `useBottomSheetInternal(true)` (unsafe mode) so it returns `null`\n * instead of throwing when called outside a BottomSheet. When inside a\n * BottomSheet it returns handlers that wire into the keyboard state\n * management logic required by `@gorhom/bottom-sheet`.\n *\n * Pass the returned handlers to your `` or `` component:\n *\n * ```tsx\n * const { onFocus, onBlur } = useBottomSheetAwareHandlers();\n * \n * ```\n *\n * @returns onFocus and onBlur handlers for bottom sheet keyboard management\n */\nexport function useBottomSheetAwareHandlers(): UseBottomSheetAwareHandlersReturn {\n const useBottomSheetInternal = GorhomBottomSheetPackage?.useBottomSheetInternal;\n const bottomSheetContext = useBottomSheetInternal?.(true) ?? null;\n\n const isActive = bottomSheetContext !== null;\n\n /**\n * Handles focus event: notifies the bottom sheet about the keyboard target.\n */\n const onFocus = useCallback(\n (e: FocusEvent) => {\n if (isActive && bottomSheetContext) {\n bottomSheetContext.animatedKeyboardState.set((state: Record) => ({\n ...state,\n target: e.nativeEvent.target,\n }));\n }\n },\n [isActive, bottomSheetContext],\n );\n\n /**\n * Handles blur event: conditionally clears the keyboard target in the\n * bottom sheet state.\n */\n const onBlur = useCallback(\n (e: BlurEvent) => {\n if (isActive && bottomSheetContext) {\n const keyboardState = bottomSheetContext.animatedKeyboardState.get();\n const currentFocusedInput = findNodeHandle(\n TextInput.State.currentlyFocusedInput() as TextInput | null,\n );\n const shouldRemoveCurrentTarget = keyboardState.target === e.nativeEvent.target;\n const shouldIgnoreBlurEvent =\n currentFocusedInput &&\n bottomSheetContext.textInputNodesRef.current.has(currentFocusedInput);\n\n if (shouldRemoveCurrentTarget && !shouldIgnoreBlurEvent) {\n bottomSheetContext.animatedKeyboardState.set((state: Record) => ({\n ...state,\n target: undefined,\n }));\n }\n }\n },\n [isActive, bottomSheetContext],\n );\n\n return { onFocus, onBlur };\n}\n", "type": "registry:hook", "target": "@components/pitsi-ui/native-ui/src/helpers/external/hooks/use-bottom-sheet-aware-handlers.ts" }, { "path": "registry/native-ui/src/optional/gorhom-bottom-sheet.ts", "content": "let GorhomBottomSheetPackage: any;\n\ntry {\n GorhomBottomSheetPackage = require(\"@gorhom/bottom-sheet\");\n} catch (_error) {\n /* @gorhom/bottom-sheet is an optional peer dependency */\n}\n\nexport default GorhomBottomSheetPackage;\n", "type": "registry:hook", "target": "@components/pitsi-ui/native-ui/src/optional/gorhom-bottom-sheet.ts" } ], "categories": [ "native", "react-native", "hooks" ], "meta": { "package": "@pitsi-ui/native", "packageSlug": "native-ui", "platform": "native" } }