{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "overlay",
  "title": "Overlay",
  "type": "registry:lib",
  "files": [
    {
      "path": "packages/registry-native/bootstrap/overlay/index.tsx",
      "content": "import * as React from 'react'\nimport {\n  KeyboardAvoidingView,\n  Modal,\n  Platform,\n  Pressable,\n  ScrollView,\n  StyleSheet,\n  Text as NativeText,\n  View,\n  type ViewProps,\n} from 'react-native'\nimport { Gesture, GestureDetector, GestureHandlerRootView } from 'react-native-gesture-handler'\nimport Animated, {\n  runOnJS,\n  useAnimatedStyle,\n  useReducedMotion,\n  useSharedValue,\n  withSpring,\n} from 'react-native-reanimated'\nimport { useSafeAreaInsets } from 'react-native-safe-area-context'\nimport { X } from 'lucide-react-native'\nimport { Button, type ButtonProps } from '@/components/ui/button'\nimport { Text } from '@/components/ui/text'\nimport { focusForScreenReader } from '@/lib/accessibility'\nimport { motionSprings } from '@/lib/motion'\nimport { PortalHost, PortalScope, useModalPortalScope } from '@/lib/portal'\nimport { useThemeColors } from '@/lib/theme'\nimport { cn } from '@/lib/utils'\n\nexport interface OverlayProps {\n  open?: boolean\n  defaultOpen?: boolean\n  onOpenChange?: (open: boolean) => void\n  children: React.ReactNode\n}\n\ninterface OverlayContextValue {\n  open: boolean\n  setOpen: (open: boolean) => void\n  trigger: React.RefObject<React.RefObject<React.ComponentRef<typeof Pressable> | null> | null>\n}\n\nconst OverlayContext = React.createContext<OverlayContextValue | null>(null)\n\nexport function useOverlay() {\n  const context = React.useContext(OverlayContext)\n  if (!context) throw new Error('Overlay controls must be inside their Sheet, Dialog, or Select')\n  return context\n}\n\nexport function useOverlayTriggerRef(forwardedRef: React.Ref<React.ComponentRef<typeof Pressable>>) {\n  const { trigger } = useOverlay()\n  const ownTrigger = React.useRef<React.ComponentRef<typeof Pressable>>(null)\n  const ref = React.useCallback(\n    (node: React.ComponentRef<typeof Pressable> | null) => {\n      ownTrigger.current = node\n      if (typeof forwardedRef === 'function') {\n        const cleanup = forwardedRef(node)\n        if (cleanup)\n          return () => {\n            if (ownTrigger.current === node) ownTrigger.current = null\n            cleanup()\n          }\n      } else if (forwardedRef) forwardedRef.current = node\n    },\n    [forwardedRef],\n  )\n  return {\n    ref,\n    capture: () => {\n      trigger.current = ownTrigger\n    },\n  }\n}\n\nexport function Overlay({ open, defaultOpen = false, onOpenChange, children }: OverlayProps) {\n  const [internal, setInternal] = React.useState(defaultOpen)\n  const trigger = React.useRef<React.RefObject<React.ComponentRef<typeof Pressable> | null> | null>(null)\n  const resolved = open ?? internal\n  const requested = React.useRef(resolved)\n  requested.current = resolved\n  const setOpen = React.useCallback(\n    (next: boolean) => {\n      if (next === (open ?? requested.current)) return\n      if (open === undefined) {\n        requested.current = next\n        setInternal(next)\n      }\n      onOpenChange?.(next)\n    },\n    [open, onOpenChange],\n  )\n\n  return <OverlayContext.Provider value={{ open: resolved, setOpen, trigger }}>{children}</OverlayContext.Provider>\n}\n\nexport const OverlayTrigger = React.forwardRef<React.ComponentRef<typeof Pressable>, ButtonProps>(\n  ({ onPress, disabled, loading, accessibilityState, ...props }, ref) => {\n    const { open, setOpen } = useOverlay()\n    const trigger = useOverlayTriggerRef(ref)\n    return (\n      <Button\n        {...props}\n        ref={trigger.ref}\n        disabled={disabled}\n        loading={loading}\n        accessibilityState={{ ...accessibilityState, expanded: open }}\n        onPress={(event) => {\n          if (disabled || loading) return\n          onPress?.(event)\n          if (!event.isDefaultPrevented()) {\n            trigger.capture()\n            setOpen(true)\n          }\n        }}\n      />\n    )\n  },\n)\nOverlayTrigger.displayName = 'OverlayTrigger'\n\nexport const OverlayClose = React.forwardRef<React.ComponentRef<typeof Pressable>, ButtonProps>(\n  ({ onPress, disabled, loading, ...props }, ref) => {\n    const { setOpen } = useOverlay()\n    return (\n      <Button\n        ref={ref}\n        {...props}\n        disabled={disabled}\n        loading={loading}\n        onPress={(event) => {\n          if (disabled || loading) return\n          onPress?.(event)\n          if (!event.isDefaultPrevented()) setOpen(false)\n        }}\n      />\n    )\n  },\n)\nOverlayClose.displayName = 'OverlayClose'\n\nexport interface OverlayContentProps extends ViewProps {\n  title: string\n  description?: string\n  className?: string\n  closeLabel?: string\n  /** Turn this off when dismissing would discard a pending operation. Back still requests closure. */\n  dismissOnBackdropPress?: boolean\n  initialFocusRef?: React.RefObject<Parameters<typeof import('react-native').findNodeHandle>[0]>\n}\n\nexport const OverlayContent = React.forwardRef<\n  React.ComponentRef<typeof View>,\n  OverlayContentProps & { placement: 'sheet' | 'dialog' }\n>(\n  (\n    {\n      title,\n      description,\n      placement,\n      className,\n      closeLabel = 'Close',\n      dismissOnBackdropPress = true,\n      initialFocusRef,\n      children,\n      ...props\n    },\n    ref,\n  ) => {\n    const { open, setOpen, trigger } = useOverlay()\n    const insets = useSafeAreaInsets()\n    const colors = useThemeColors()\n    const reduced = useReducedMotion()\n    const heading = React.useRef<React.ComponentRef<typeof NativeText>>(null)\n    const cancelFocus = React.useRef<() => void>(() => {})\n    const wasOpen = React.useRef(open)\n    const isOpen = React.useRef(open)\n    isOpen.current = open\n    const translation = useSharedValue(0)\n    const close = React.useCallback(() => setOpen(false), [setOpen])\n    const portalScope = useModalPortalScope()\n    const requestClose = React.useCallback(() => {\n      if (!portalScope.dismissTopmost()) close()\n    }, [portalScope, close])\n    const style = useAnimatedStyle(() => ({ transform: [{ translateY: translation.value }] }))\n    const pan = Gesture.Pan()\n      .onUpdate((event) => {\n        if (!reduced) translation.value = Math.max(0, event.translationY)\n      })\n      .onEnd((event) => {\n        if (event.translationY > 80 || event.velocityY > 800) runOnJS(close)()\n      })\n      .onFinalize(() => {\n        translation.value = reduced ? 0 : withSpring(0, motionSprings.snappy)\n      })\n\n    React.useEffect(() => {\n      translation.value = 0\n      if (!open && wasOpen.current && Platform.OS !== 'ios') {\n        cancelFocus.current()\n        cancelFocus.current = focusForScreenReader(() => (isOpen.current ? null : (trigger.current?.current ?? null)))\n      }\n      wasOpen.current = open\n    }, [open, trigger, translation])\n\n    React.useEffect(() => () => cancelFocus.current(), [])\n\n    return (\n      <Modal\n        visible={open}\n        transparent\n        animationType={reduced ? 'none' : placement === 'sheet' ? 'slide' : 'fade'}\n        presentationStyle=\"overFullScreen\"\n        supportedOrientations={['portrait', 'portrait-upside-down', 'landscape-left', 'landscape-right']}\n        statusBarTranslucent\n        navigationBarTranslucent\n        onRequestClose={requestClose}\n        onShow={() => {\n          cancelFocus.current()\n          cancelFocus.current = focusForScreenReader(() =>\n            isOpen.current ? (initialFocusRef?.current ?? heading.current) : null,\n          )\n        }}\n        onDismiss={() => {\n          cancelFocus.current()\n          cancelFocus.current = focusForScreenReader(() => (isOpen.current ? null : (trigger.current?.current ?? null)))\n        }}\n      >\n        <PortalScope scope={portalScope}>\n          <GestureHandlerRootView style={{ flex: 1 }}>\n            <View ref={portalScope.containerRef} style={{ flex: 1 }}>\n              <Pressable\n                accessible={false}\n                focusable={false}\n                importantForAccessibility=\"no\"\n                onPress={dismissOnBackdropPress ? close : undefined}\n                style={[StyleSheet.absoluteFill, { backgroundColor: 'rgba(0, 0, 0, 0.5)' }]}\n              />\n              <KeyboardAvoidingView\n                behavior={Platform.OS === 'ios' ? 'padding' : Platform.OS === 'android' ? 'height' : undefined}\n                pointerEvents=\"box-none\"\n                style={{\n                  flex: 1,\n                  justifyContent: placement === 'sheet' ? 'flex-end' : 'center',\n                  paddingTop: insets.top + 16,\n                  paddingBottom: placement === 'dialog' ? insets.bottom + 16 : 0,\n                  paddingLeft: insets.left + 16,\n                  paddingRight: insets.right + 16,\n                }}\n              >\n                <Animated.View\n                  style={[{ maxHeight: '100%', width: '100%', maxWidth: 600, alignSelf: 'center' }, style]}\n                >\n                  <View\n                    ref={ref}\n                    {...props}\n                    style={[{ maxHeight: '100%' }, props.style]}\n                    accessibilityViewIsModal\n                    onAccessibilityEscape={close}\n                    className={cn('overflow-hidden rounded-2xl border border-border bg-card', className)}\n                  >\n                    {placement === 'sheet' ? (\n                      <GestureDetector gesture={pan}>\n                        <Animated.View\n                          accessible={false}\n                          importantForAccessibility=\"no-hide-descendants\"\n                          className=\"min-h-[48px] items-center justify-center\"\n                        >\n                          <View aria-hidden className=\"h-1 w-8 rounded-full bg-muted-foreground\" />\n                        </Animated.View>\n                      </GestureDetector>\n                    ) : null}\n                    <ScrollView\n                      keyboardShouldPersistTaps=\"handled\"\n                      automaticallyAdjustKeyboardInsets={false}\n                      contentContainerStyle={{ padding: 16, paddingBottom: Math.max(insets.bottom, 16), gap: 16 }}\n                      style={{ flexGrow: 0, flexShrink: 1 }}\n                    >\n                      <View className=\"flex-row items-start gap-2\">\n                        <View className=\"min-w-0 flex-1 gap-2\">\n                          <Text ref={heading} accessibilityRole=\"header\" size=\"lg\" className=\"font-semibold\">\n                            {title}\n                          </Text>\n                          {description ? (\n                            <Text variant=\"muted\" size=\"sm\">\n                              {description}\n                            </Text>\n                          ) : null}\n                        </View>\n                        <OverlayClose variant=\"ghost\" size=\"icon\" accessibilityLabel={closeLabel}>\n                          <X size={20} color={colors.foreground} aria-hidden />\n                        </OverlayClose>\n                      </View>\n                      {children}\n                    </ScrollView>\n                  </View>\n                </Animated.View>\n              </KeyboardAvoidingView>\n              <PortalHost name={portalScope.hostName} />\n            </View>\n          </GestureHandlerRootView>\n        </PortalScope>\n      </Modal>\n    )\n  },\n)\nOverlayContent.displayName = 'OverlayContent'\n",
      "type": "registry:lib",
      "target": "~/lib/overlay.tsx"
    }
  ],
  "dependencies": [
    "react-native-gesture-handler",
    "react-native-reanimated",
    "react-native-safe-area-context",
    "lucide-react-native",
    "react-native-svg"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/button.json",
    "https://native.uipkge.dev/r/native/text.json",
    "https://native.uipkge.dev/r/native/accessibility.json",
    "https://native.uipkge.dev/r/native/motion.json",
    "https://native.uipkge.dev/r/native/portal.json",
    "https://native.uipkge.dev/r/native/theme.json"
  ],
  "description": "Shared native modal lifecycle, trigger focus, keyboard avoidance, safe-area layout, and sheet gestures."
}