{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "carousel",
  "title": "Carousel",
  "type": "registry:ui",
  "files": [
    {
      "path": "packages/registry-native/components/carousel/Carousel.tsx",
      "content": "import * as React from 'react'\nimport { I18nManager, Pressable, ScrollView, View, type ScrollViewProps, type ViewProps } from 'react-native'\nimport { useReducedMotion } from 'react-native-reanimated'\nimport { Button, type ButtonProps } from '@/components/ui/button'\nimport { Text, type TextProps } from '@/components/ui/text'\nimport { renderTextChildren } from '@/lib/label-children'\nimport { cn } from '@/lib/utils'\n\ninterface CarouselState {\n  index: number\n  count: number\n  width: number\n  disabled: boolean\n  scroll: React.RefObject<React.ComponentRef<typeof ScrollView> | null>\n  setWidth: (width: number) => void\n  setCount: (count: number) => void\n  settle: (index: number) => void\n  go: (index: number) => void\n}\nconst Context = React.createContext<CarouselState | null>(null)\nfunction useCarousel() {\n  const value = React.useContext(Context)\n  if (!value) throw new Error('Carousel parts must be inside Carousel')\n  return value\n}\nfunction clamp(index: number, count: number) {\n  return Math.max(0, Math.min(Math.max(0, count - 1), Number.isFinite(index) ? Math.trunc(index) : 0))\n}\nexport interface CarouselProps extends ViewProps {\n  index?: number\n  defaultIndex?: number\n  onIndexChange?: (index: number) => void\n  disabled?: boolean\n  className?: string\n}\nexport const Carousel = React.forwardRef<React.ComponentRef<typeof View>, CarouselProps>(\n  ({ index, defaultIndex = 0, onIndexChange, disabled = false, className, ...props }, ref) => {\n    const [internal, setInternal] = React.useState(defaultIndex)\n    const [count, setCount] = React.useState(0)\n    const [width, setWidth] = React.useState(0)\n    const [settled, setSettled] = React.useState({ index: 0 })\n    const scroll = React.useRef<React.ComponentRef<typeof ScrollView>>(null)\n    const previousWidth = React.useRef(0)\n    const reduced = useReducedMotion()\n    const current = clamp(index ?? internal, count)\n    const controlled = index !== undefined\n    const registerCount = React.useCallback(\n      (next: number) => {\n        setCount(next)\n        if (!controlled) setInternal((value) => clamp(value, next))\n      },\n      [controlled],\n    )\n    function go(next: number) {\n      if (disabled || !count) return\n      const target = clamp(next, count)\n      if (target === current) return\n      if (!controlled) setInternal(target)\n      onIndexChange?.(target)\n    }\n    React.useLayoutEffect(() => {\n      if (!width) return\n      scroll.current?.scrollTo({\n        x: current * width,\n        y: 0,\n        animated: !reduced && previousWidth.current === width && current !== settled.index,\n      })\n      previousWidth.current = width\n      // `count` is deliberately absent: appending slides keeps the page, and iOS scrollTo would stop a live drag.\n    }, [current, width, settled, reduced])\n    return (\n      <Context.Provider\n        value={{\n          index: current,\n          count,\n          width,\n          scroll,\n          disabled,\n          setWidth,\n          setCount: registerCount,\n          go,\n          settle: (next) => {\n            setSettled({ index: next })\n            go(next)\n          },\n        }}\n      >\n        <View {...props} ref={ref} className={cn('w-full gap-[12px]', className)} />\n      </Context.Provider>\n    )\n  },\n)\nCarousel.displayName = 'Carousel'\n\nfunction pages(children: React.ReactNode, namespace = ''): React.ReactNode[] {\n  return React.Children.toArray(children).flatMap((child) => {\n    if (!React.isValidElement<{ children?: React.ReactNode }>(child)) return [child]\n    const key = namespace + '/' + child.key\n    if (child.type === React.Fragment) return pages(child.props.children, key)\n    return [React.cloneElement(child, { key })]\n  })\n}\nexport type CarouselContentProps = Omit<\n  ScrollViewProps,\n  'horizontal' | 'pagingEnabled' | 'children' | 'contentContainerStyle'\n> & {\n  children?: React.ReactNode\n  className?: string\n}\nexport const CarouselContent = React.forwardRef<React.ComponentRef<typeof ScrollView>, CarouselContentProps>(\n  ({ children, className, onLayout, onMomentumScrollEnd, onScrollEndDrag, scrollEnabled, ...props }, ref) => {\n    const carousel = useCarousel()\n    const content = pages(children)\n    const { setCount } = carousel\n    React.useLayoutEffect(() => {\n      setCount(content.length)\n    }, [setCount, content.length])\n    React.useImperativeHandle(ref, () => carousel.scroll.current!, [carousel.scroll])\n    return (\n      <ScrollView\n        {...props}\n        ref={carousel.scroll}\n        horizontal\n        pagingEnabled\n        scrollEnabled={!carousel.disabled && scrollEnabled !== false && content.length > 1}\n        showsHorizontalScrollIndicator={false}\n        className={cn('w-full rounded-lg', className)}\n        onLayout={(event) => {\n          carousel.setWidth(Math.max(0, event.nativeEvent.layout.width))\n          onLayout?.(event)\n        }}\n        onScrollEndDrag={(event) => {\n          // iOS only: when UIKit's paging target equals the current offset it will not decelerate, and no\n          // onMomentumScrollEnd follows. Android sends no target and always ends with a momentum event.\n          const { contentOffset, targetContentOffset, contentSize, layoutMeasurement } = event.nativeEvent\n          if (carousel.width && targetContentOffset) {\n            // iOS reports contentOffset in logical (RTL-adjusted) space but targetContentOffset physically.\n            const target = I18nManager.isRTL\n              ? contentSize.width - layoutMeasurement.width - targetContentOffset.x\n              : targetContentOffset.x\n            if (Math.abs(target - contentOffset.x) < 0.5)\n              carousel.settle(clamp(Math.round(contentOffset.x / carousel.width), content.length))\n          }\n          onScrollEndDrag?.(event)\n        }}\n        onMomentumScrollEnd={(event) => {\n          if (carousel.width)\n            carousel.settle(clamp(Math.round(event.nativeEvent.contentOffset.x / carousel.width), content.length))\n          onMomentumScrollEnd?.(event)\n        }}\n      >\n        {content}\n      </ScrollView>\n    )\n  },\n)\nCarouselContent.displayName = 'CarouselContent'\nexport const CarouselItem = React.forwardRef<React.ComponentRef<typeof View>, ViewProps & { className?: string }>(\n  ({ children, className, style, ...props }, ref) => {\n    const carousel = useCarousel()\n    return (\n      <View {...props} ref={ref} className={cn('shrink-0', className)} style={[{ width: carousel.width }, style]}>\n        {renderTextChildren(children)}\n      </View>\n    )\n  },\n)\nCarouselItem.displayName = 'CarouselItem'\nexport const CarouselPrevious = React.forwardRef<React.ComponentRef<typeof Pressable>, ButtonProps>(\n  ({ children = 'Previous slide', disabled, onPress, ...props }, ref) => {\n    const carousel = useCarousel()\n    const isDisabled = carousel.disabled || !!disabled || carousel.index <= 0 || !carousel.count\n    return (\n      <Button\n        variant=\"outline\"\n        {...props}\n        ref={ref}\n        disabled={isDisabled}\n        onPress={(event) => {\n          if (isDisabled) return\n          onPress?.(event)\n          if (!event.isDefaultPrevented()) carousel.go(carousel.index - 1)\n        }}\n      >\n        {children}\n      </Button>\n    )\n  },\n)\nCarouselPrevious.displayName = 'CarouselPrevious'\nexport const CarouselNext = React.forwardRef<React.ComponentRef<typeof Pressable>, ButtonProps>(\n  ({ children = 'Next slide', disabled, onPress, ...props }, ref) => {\n    const carousel = useCarousel()\n    const isDisabled = carousel.disabled || !!disabled || !carousel.count || carousel.index >= carousel.count - 1\n    return (\n      <Button\n        variant=\"outline\"\n        {...props}\n        ref={ref}\n        disabled={isDisabled}\n        onPress={(event) => {\n          if (isDisabled) return\n          onPress?.(event)\n          if (!event.isDefaultPrevented()) carousel.go(carousel.index + 1)\n        }}\n      >\n        {children}\n      </Button>\n    )\n  },\n)\nCarouselNext.displayName = 'CarouselNext'\nexport const CarouselStatus = React.forwardRef<React.ComponentRef<typeof Text>, TextProps>(\n  ({ children, ...props }, ref) => {\n    const carousel = useCarousel()\n    return (\n      <Text {...props} ref={ref}>\n        {children ?? (carousel.count ? 'Slide ' + (carousel.index + 1) + ' of ' + carousel.count : 'No slides')}\n      </Text>\n    )\n  },\n)\nCarouselStatus.displayName = 'CarouselStatus'\n",
      "type": "registry:ui",
      "target": "~/components/ui/carousel/Carousel.tsx"
    },
    {
      "path": "packages/registry-native/components/carousel/index.ts",
      "content": "export * from './Carousel'\n",
      "type": "registry:ui",
      "target": "~/components/ui/carousel/index.ts"
    }
  ],
  "dependencies": [
    "react-native-reanimated"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/button.json",
    "https://native.uipkge.dev/r/native/text.json",
    "https://native.uipkge.dev/r/native/utils.json",
    "https://native.uipkge.dev/r/native/label-children.json"
  ],
  "description": "Native paged scrolling with measured slide widths and composed page controls."
}