{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "screen-footer",
  "title": "Screen Footer",
  "type": "registry:ui",
  "files": [
    {
      "path": "packages/registry-native/components/screen-footer/ScreenFooter.tsx",
      "content": "import * as React from 'react'\nimport {\n  Keyboard,\n  Platform,\n  View,\n  useWindowDimensions,\n  type KeyboardEvent,\n  type LayoutChangeEvent,\n  type ViewProps,\n} from 'react-native'\nimport { useSafeAreaInsets } from 'react-native-safe-area-context'\nimport { cn } from '@/lib/utils'\n\nexport interface ScreenFooterContextValue {\n  height: number\n  keyboardHeight: number\n  clearance: number\n}\n\ninterface ScreenFooterSetters {\n  setHeight: React.Dispatch<React.SetStateAction<number>>\n  setKeyboardHeight: React.Dispatch<React.SetStateAction<number>>\n}\n\nconst DEFAULT_SCREEN_FOOTER_CONTEXT: ScreenFooterContextValue = {\n  height: 0,\n  keyboardHeight: 0,\n  clearance: 0,\n}\n\nconst ScreenFooterContext = React.createContext<ScreenFooterContextValue>(DEFAULT_SCREEN_FOOTER_CONTEXT)\nconst ScreenFooterSetterContext = React.createContext<ScreenFooterSetters | null>(null)\n\nexport interface ScreenFooterProviderProps {\n  children?: React.ReactNode\n}\n\nexport function ScreenFooterProvider({ children }: ScreenFooterProviderProps) {\n  const [height, setHeight] = React.useState(0)\n  const [keyboardHeight, setKeyboardHeight] = React.useState(0)\n\n  const setters = React.useMemo<ScreenFooterSetters>(() => ({ setHeight, setKeyboardHeight }), [])\n\n  const value = React.useMemo<ScreenFooterContextValue>(\n    () => ({\n      height,\n      keyboardHeight,\n      clearance: height + keyboardHeight,\n    }),\n    [height, keyboardHeight],\n  )\n\n  return (\n    <ScreenFooterSetterContext.Provider value={setters}>\n      <ScreenFooterContext.Provider value={value}>{children}</ScreenFooterContext.Provider>\n    </ScreenFooterSetterContext.Provider>\n  )\n}\n\nexport function useScreenFooter(): ScreenFooterContextValue {\n  return React.useContext(ScreenFooterContext)\n}\n\nexport interface KeyboardOverlapInput {\n  footerBottom?: number\n  keyboardTop?: number\n  keyboardHeight: number\n  windowHeight?: number\n}\n\n/**\n * Computes how far a footer actually overlaps the soft keyboard in window coordinates.\n * When Android `adjustResize` has already shrunk the viewport above `keyboardTop`, overlap is `0`\n * (preventing double-lifting); on non-resized viewports (e.g. iOS), overlap equals the obscured height.\n */\nexport function computeKeyboardOverlap({\n  footerBottom,\n  keyboardTop,\n  keyboardHeight,\n  windowHeight,\n}: KeyboardOverlapInput): number {\n  if (!Number.isFinite(keyboardHeight) || keyboardHeight <= 0) return 0\n  if (typeof keyboardTop === 'number' && Number.isFinite(keyboardTop)) {\n    const referenceBottom =\n      typeof footerBottom === 'number' && Number.isFinite(footerBottom)\n        ? footerBottom\n        : typeof windowHeight === 'number' && Number.isFinite(windowHeight) && windowHeight > 0\n          ? windowHeight\n          : undefined\n    if (referenceBottom !== undefined) {\n      const overlap = referenceBottom - keyboardTop\n      if (overlap <= 0) return 0\n      return Math.min(overlap, keyboardHeight)\n    }\n  }\n  return keyboardHeight\n}\n\nexport interface ScreenFooterProps extends ViewProps {\n  avoidKeyboard?: boolean\n  bordered?: boolean\n  onHeightChange?: (height: number) => void\n  className?: string\n}\n\ninterface ActiveKeyboardMetrics {\n  height: number\n  screenY?: number\n}\n\nexport const ScreenFooter = React.forwardRef<React.ComponentRef<typeof View>, ScreenFooterProps>(\n  ({ avoidKeyboard = true, bordered = true, onHeightChange, onLayout, className, style, ...props }, ref) => {\n    const insets = useSafeAreaInsets()\n    const { height: windowHeight } = useWindowDimensions()\n    const setters = React.useContext(ScreenFooterSetterContext)\n    const [keyboardVisible, setKeyboardVisible] = React.useState(false)\n    const [keyboardLift, setKeyboardLift] = React.useState(0)\n\n    const viewRef = React.useRef<React.ComponentRef<typeof View> | null>(null)\n    const mountedRef = React.useRef(true)\n    const liftRef = React.useRef(0)\n    const windowHeightRef = React.useRef(windowHeight)\n    windowHeightRef.current = windowHeight\n    const activeKeyboardRef = React.useRef<ActiveKeyboardMetrics | null>(null)\n\n    const setRefs = React.useCallback(\n      (node: React.ComponentRef<typeof View> | null) => {\n        viewRef.current = node\n        if (typeof ref === 'function') {\n          ref(node)\n        } else if (ref) {\n          ref.current = node\n        }\n      },\n      [ref],\n    )\n\n    const commitLift = React.useCallback(\n      (nextLift: number) => {\n        if (!mountedRef.current) return\n        const safeLift = Number.isFinite(nextLift) && nextLift > 0 ? nextLift : 0\n        liftRef.current = safeLift\n        setKeyboardLift(safeLift)\n        setters?.setKeyboardHeight(safeLift)\n      },\n      [setters],\n    )\n\n    const reconcileKeyboardLift = React.useCallback(\n      (metrics: ActiveKeyboardMetrics | null) => {\n        if (!metrics || metrics.height <= 0) {\n          commitLift(0)\n          return\n        }\n\n        const node = viewRef.current\n        if (node && typeof node.measureInWindow === 'function' && typeof metrics.screenY === 'number') {\n          node.measureInWindow((_x, y, _width, measuredHeight) => {\n            if (!mountedRef.current || activeKeyboardRef.current !== metrics) return\n            const unshiftedBottom =\n              Number.isFinite(y) && Number.isFinite(measuredHeight) ? y + measuredHeight + liftRef.current : undefined\n            const overlap = computeKeyboardOverlap({\n              footerBottom: unshiftedBottom,\n              keyboardTop: metrics.screenY,\n              keyboardHeight: metrics.height,\n              windowHeight: windowHeightRef.current,\n            })\n            commitLift(overlap)\n          })\n          return\n        }\n\n        const overlap = computeKeyboardOverlap({\n          keyboardTop: metrics.screenY,\n          keyboardHeight: metrics.height,\n          windowHeight: windowHeightRef.current,\n        })\n        commitLift(overlap)\n      },\n      [commitLift],\n    )\n\n    React.useEffect(() => {\n      mountedRef.current = true\n      return () => {\n        mountedRef.current = false\n        activeKeyboardRef.current = null\n        liftRef.current = 0\n        setters?.setHeight(0)\n        setters?.setKeyboardHeight(0)\n      }\n    }, [setters])\n\n    React.useEffect(() => {\n      if (!avoidKeyboard) {\n        activeKeyboardRef.current = null\n        setKeyboardVisible(false)\n        commitLift(0)\n        return\n      }\n      if (typeof Keyboard?.addListener !== 'function') {\n        return\n      }\n\n      const showEvent = Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow'\n      const hideEvent = Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide'\n\n      const showSub = Keyboard.addListener(showEvent, (event: KeyboardEvent) => {\n        const rawHeight = event?.endCoordinates?.height\n        const safeHeight = typeof rawHeight === 'number' && Number.isFinite(rawHeight) && rawHeight > 0 ? rawHeight : 0\n        const rawScreenY = event?.endCoordinates?.screenY\n        const safeScreenY = typeof rawScreenY === 'number' && Number.isFinite(rawScreenY) ? rawScreenY : undefined\n        if (safeHeight <= 0) {\n          activeKeyboardRef.current = null\n          setKeyboardVisible(false)\n          commitLift(0)\n          return\n        }\n        const metrics: ActiveKeyboardMetrics = { height: safeHeight, screenY: safeScreenY }\n        activeKeyboardRef.current = metrics\n        setKeyboardVisible(true)\n        reconcileKeyboardLift(metrics)\n      })\n\n      const hideSub = Keyboard.addListener(hideEvent, () => {\n        activeKeyboardRef.current = null\n        setKeyboardVisible(false)\n        commitLift(0)\n      })\n\n      return () => {\n        showSub?.remove?.()\n        hideSub?.remove?.()\n      }\n    }, [avoidKeyboard, commitLift, reconcileKeyboardLift])\n\n    React.useEffect(() => {\n      if (avoidKeyboard && activeKeyboardRef.current) {\n        reconcileKeyboardLift(activeKeyboardRef.current)\n      }\n    }, [avoidKeyboard, reconcileKeyboardLift, windowHeight])\n\n    const handleLayout = React.useCallback(\n      (event: LayoutChangeEvent) => {\n        const rawHeight = event.nativeEvent.layout.height\n        const nextHeight = Number.isFinite(rawHeight) && rawHeight >= 0 ? rawHeight : 0\n        setters?.setHeight(nextHeight)\n        onHeightChange?.(nextHeight)\n        onLayout?.(event)\n        if (avoidKeyboard && activeKeyboardRef.current) {\n          reconcileKeyboardLift(activeKeyboardRef.current)\n        }\n      },\n      [avoidKeyboard, onHeightChange, onLayout, reconcileKeyboardLift, setters],\n    )\n\n    const safeBottom = Number.isFinite(insets.bottom) && insets.bottom > 0 ? insets.bottom : 0\n    const paddingBottom = keyboardVisible ? 0 : safeBottom\n\n    return (\n      <View\n        ref={setRefs}\n        {...props}\n        onLayout={handleLayout}\n        className={cn('w-full bg-background', bordered && 'border-t border-border', className)}\n        style={[{ paddingBottom, marginBottom: keyboardLift }, style]}\n      />\n    )\n  },\n)\nScreenFooter.displayName = 'ScreenFooter'\n",
      "type": "registry:ui",
      "target": "~/components/ui/screen-footer/ScreenFooter.tsx"
    },
    {
      "path": "packages/registry-native/components/screen-footer/index.ts",
      "content": "export {\n  ScreenFooter,\n  ScreenFooterProvider,\n  computeKeyboardOverlap,\n  useScreenFooter,\n  type KeyboardOverlapInput,\n  type ScreenFooterContextValue,\n  type ScreenFooterProps,\n  type ScreenFooterProviderProps,\n} from './ScreenFooter'\n",
      "type": "registry:ui",
      "target": "~/components/ui/screen-footer/index.ts"
    }
  ],
  "dependencies": [
    "react-native-safe-area-context"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/utils.json"
  ],
  "description": "Sticky screen footer with safe-area bottom inset, keyboard avoidance, and scroll clearance context.",
  "categories": [
    "layout"
  ]
}