{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "image",
  "title": "Image",
  "type": "registry:ui",
  "files": [
    {
      "path": "packages/registry-native/components/image/Image.tsx",
      "content": "import * as React from 'react'\nimport {\n  Image as NativeImage,\n  Pressable,\n  StyleSheet,\n  View,\n  type ImageProps as NativeImageProps,\n  type ImageURISource,\n  type ViewProps,\n} from 'react-native'\nimport { cssInterop } from 'react-native-css-interop'\nimport { Button, type ButtonProps } from '@/components/ui/button'\nimport { Spinner } from '@/components/ui/spinner'\nimport { Text } from '@/components/ui/text'\nimport { renderTextChildren } from '@/lib/label-children'\nimport { cn } from '@/lib/utils'\n\ntype Status = 'loading' | 'loaded' | 'error'\ninterface ImageState {\n  source: NativeImageProps['source'] | undefined\n  hasSource: boolean\n  status: Status\n  attempt: number\n  current: (attempt: number) => boolean\n  settle: (attempt: number, status: 'loaded' | 'error') => boolean\n  retry: () => void\n}\nconst Context = React.createContext<ImageState | null>(null)\nfunction useImage() {\n  const value = React.useContext(Context)\n  if (!value) throw new Error('Image parts must be inside Image')\n  return value\n}\nfunction hasImageSource(source: NativeImageProps['source'] | undefined): boolean {\n  if (typeof source === 'number') return Number.isFinite(source) && source > 0\n  return !!source && 'uri' in source && !!source.uri?.trim()\n}\nfunction ImageStateProvider({ source, children }: { source?: NativeImageProps['source']; children: React.ReactNode }) {\n  const hasSource = hasImageSource(source)\n  const [status, setStatus] = React.useState<Status>(hasSource ? 'loading' : 'error')\n  const [attempt, setAttempt] = React.useState(0)\n  const active = React.useRef(true)\n  const generation = React.useRef(0)\n  const phase = React.useRef(status)\n  React.useLayoutEffect(() => {\n    active.current = true\n    return () => {\n      active.current = false\n    }\n  }, [])\n  return (\n    <Context.Provider\n      value={{\n        source,\n        hasSource,\n        status,\n        attempt,\n        current: (request) => active.current && generation.current === request,\n        settle: (request, next) => {\n          if (!active.current || generation.current !== request || phase.current !== 'loading') return false\n          phase.current = next\n          setStatus(next)\n          return true\n        },\n        retry: () => {\n          if (!hasSource || phase.current === 'loading') return\n          generation.current += 1\n          phase.current = 'loading'\n          setAttempt(generation.current)\n          setStatus('loading')\n        },\n      }}\n    >\n      {children}\n    </Context.Provider>\n  )\n}\n\n/** Responsive variants belong in the caller so each request has a distinct source identity. */\nexport type ImageSourceValue = number | ImageURISource\nexport interface ImageProps extends ViewProps {\n  source?: ImageSourceValue\n  className?: string\n}\nexport const Image = React.forwardRef<React.ComponentRef<typeof View>, ImageProps>(\n  ({ source, className, style, children, ...props }, ref) => {\n    const identity = JSON.stringify(source) ?? 'missing'\n    return (\n      <View\n        {...props}\n        ref={ref}\n        className={cn('relative w-full overflow-hidden rounded-lg bg-muted', className)}\n        style={[{ aspectRatio: 16 / 9 }, style]}\n      >\n        <ImageStateProvider key={identity} source={source}>\n          {children ?? (\n            <>\n              <ImageSource accessibilityLabel={props.accessibilityLabel} />\n              <ImageLoading />\n              <ImageFallback />\n            </>\n          )}\n        </ImageStateProvider>\n      </View>\n    )\n  },\n)\nImage.displayName = 'Image'\n\nexport type ImageSourceProps = Omit<NativeImageProps, 'source' | 'src' | 'srcSet'> & { className?: string }\nexport const ImageSource = React.forwardRef<React.ComponentRef<typeof NativeImage>, ImageSourceProps>(\n  ({ className, style, resizeMode = 'cover', onLoad, onError, onLoadStart, onLoadEnd, ...props }, ref) => {\n    const image = useImage()\n    const { src: _src, srcSet: _srcSet, ...nativeProps } = props as NativeImageProps\n    if (!image.hasSource || image.status === 'error') return null\n    const request = image.attempt\n    return (\n      <NativeImage\n        {...nativeProps}\n        key={request}\n        ref={ref}\n        source={image.source}\n        accessible={\n          nativeProps.accessible ?? (nativeProps.accessibilityLabel || nativeProps['aria-label'] ? true : undefined)\n        }\n        resizeMode={resizeMode}\n        // Bundled assets have intrinsic dimensions. The preview's bounds must win by default.\n        className={className}\n        style={[StyleSheet.absoluteFill, { width: '100%', height: '100%' }, style]}\n        onLoadStart={() => {\n          if (image.current(request)) onLoadStart?.()\n        }}\n        onLoad={(event) => {\n          if (image.settle(request, 'loaded')) onLoad?.(event)\n        }}\n        onError={(event) => {\n          if (image.settle(request, 'error')) onError?.(event)\n        }}\n        onLoadEnd={() => {\n          if (image.current(request)) onLoadEnd?.()\n        }}\n      />\n    )\n  },\n)\nImageSource.displayName = 'ImageSource'\ncssInterop(ImageSource, { className: 'style' })\n\nexport const ImageFallback = React.forwardRef<React.ComponentRef<typeof View>, ViewProps & { className?: string }>(\n  ({ children = <Text variant=\"muted\">Image unavailable.</Text>, className, ...props }, ref) => {\n    const image = useImage()\n    if (image.status !== 'error') return null\n    return (\n      <View\n        {...props}\n        ref={ref}\n        className={cn('absolute inset-0 items-center justify-center gap-[12px] bg-muted p-[16px]', className)}\n      >\n        {renderTextChildren(children)}\n      </View>\n    )\n  },\n)\nImageFallback.displayName = 'ImageFallback'\nexport const ImageLoading = React.forwardRef<React.ComponentRef<typeof View>, ViewProps & { className?: string }>(\n  ({ children = <Spinner />, className, ...props }, ref) => {\n    const image = useImage()\n    if (image.status !== 'loading') return null\n    return (\n      <View\n        pointerEvents=\"none\"\n        {...props}\n        ref={ref}\n        className={cn('absolute inset-0 items-center justify-center bg-muted', className)}\n      >\n        {renderTextChildren(children)}\n      </View>\n    )\n  },\n)\nImageLoading.displayName = 'ImageLoading'\nexport const ImageRetry = React.forwardRef<React.ComponentRef<typeof Pressable>, ButtonProps>(\n  ({ children = 'Retry image', disabled, onPress, ...props }, ref) => {\n    const image = useImage()\n    const isDisabled = !!disabled || !image.hasSource || image.status === 'loading'\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()) image.retry()\n        }}\n      >\n        {children}\n      </Button>\n    )\n  },\n)\nImageRetry.displayName = 'ImageRetry'\n",
      "type": "registry:ui",
      "target": "~/components/ui/image/Image.tsx"
    },
    {
      "path": "packages/registry-native/components/image/index.ts",
      "content": "export * from './Image'\n",
      "type": "registry:ui",
      "target": "~/components/ui/image/index.ts"
    }
  ],
  "dependencies": [
    "react-native-css-interop"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/button.json",
    "https://native.uipkge.dev/r/native/spinner.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": "Image loading, error fallback and retry with source-safe request state."
}