{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scan-progress",
  "type": "registry:item",
  "title": "Scan Progress",
  "description": "An analysing state for media: a scan band lights pixel squares over the image while a ring fills a pill.",
  "categories": [
    "feedback"
  ],
  "dependencies": [
    "@shopify/react-native-skia",
    "react-native-reanimated",
    "react-native-worklets"
  ],
  "registryDependencies": [
    "https://kinetik-ui.dev/r/kinetik-tokens.json",
    "https://kinetik-ui.dev/r/kinetik-motion.json",
    "https://kinetik-ui.dev/r/kinetik-clock.json"
  ],
  "files": [
    {
      "path": "src/components/kinetik/scan-progress.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/scan-progress.tsx",
      "content": "import { Canvas, Group, Path, Skia, type SkPath } from '@shopify/react-native-skia';\nimport { useEffect, useMemo, useState, type ReactNode } from 'react';\nimport {\n  Image,\n  StyleSheet,\n  View,\n  type ImageSourcePropType,\n  type StyleProp,\n  type ViewStyle,\n} from 'react-native';\nimport Animated, {\n  Easing,\n  FadeInDown,\n  useAnimatedStyle,\n  useDerivedValue,\n  useSharedValue,\n  withDelay,\n  withRepeat,\n  withSpring,\n  withTiming,\n  type SharedValue,\n} from 'react-native-reanimated';\n\nimport { useReduceMotion } from '../../lib/kinetik/hooks/use-reduce-motion';\nimport { useShaderClock } from '../../lib/kinetik/hooks/use-shader-clock';\nimport { durations, easings, spring, timing } from '../../lib/kinetik/motion/motion';\nimport { useKinetikTheme } from '../../lib/kinetik/tokens/theme';\nimport { glow, withAlpha } from '../../lib/kinetik/tokens/tokens';\n\nexport type ScanProgressProps = {\n  /** The image being analysed. Or pass `children` for any other media. */\n  source?: ImageSourcePropType;\n  children?: ReactNode;\n  /** Height of the media card. Defaults to 260. */\n  height?: number;\n  /** 0–1. Leave out for work of unknown length: the ring creeps on and never quite closes. */\n  progress?: number;\n  /** Switches to the finished state: the pixels clear, the ring closes and the spinner becomes a check. */\n  done?: boolean;\n  /** What is happening, e.g. \"Analyzing swing motion…\". Changes cross-fade. */\n  label: string;\n  /** Shown once done. Defaults to \"Analysis complete\". */\n  doneLabel?: string;\n  /** Colour of the wash over the image, the ring and the glow. Defaults to the theme success green. */\n  tint?: string;\n  /** Read by screen readers for the image. */\n  imageLabel?: string;\n  style?: StyleProp<ViewStyle>;\n};\n\n/** Pitch of the pixel grid and the size of each square, in pt. */\nconst PITCH = 9;\nconst DOT = 6;\nconst PILL = 60;\nconst RING = 2.5;\n\n/** A repeatable 0–1 hash for a grid cell. */\nconst hash = (x: number, y: number) => {\n  const s = Math.sin(x * 127.1 + y * 311.7) * 43758.5453;\n  return s - Math.floor(s);\n};\n\n/**\n * An \"analysing\" state for media: a tinted wash over the image while a scan\n * band rolls down it, lighting a field of pixel squares that twinkle in its\n * wake; under it, a pill whose outline fills with progress and a dashed\n * spinner. When it is done the pixels clear, the ring closes and the spinner\n * turns into a check.\n */\nexport function ScanProgress({\n  source,\n  children,\n  height = 260,\n  progress,\n  done = false,\n  label,\n  doneLabel = 'Analysis complete',\n  tint,\n  imageLabel,\n  style,\n}: ScanProgressProps) {\n  const { colors, radius, space, font } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const color = tint ?? colors.success;\n  const [media, setMedia] = useState({ width: 0, height: 0 });\n  const [pill, setPill] = useState(0);\n\n  const live = useSharedValue(done ? 0 : 1);\n  useEffect(() => {\n    live.set(withTiming(done ? 0 : 1, { ...timing('slow', reduced), duration: 700 }));\n  }, [done, reduced, live]);\n\n  const wash = useAnimatedStyle(() => ({ opacity: live.get() }));\n\n  return (\n    <View style={[{ gap: space[5] }, style]}>\n      {/* The glow sits on its own layer behind the card, so the pixel field\n          redrawing every frame never makes the blurred shadow redraw too. */}\n      <View\n        pointerEvents=\"none\"\n        style={[\n          styles.glow,\n          {\n            height,\n            borderRadius: radius.xl,\n            backgroundColor: colors.surface,\n            boxShadow: glow(color),\n            opacity: done ? 0 : 1,\n          },\n        ]}\n      />\n      <View\n        style={[styles.card, { height, borderRadius: radius.xl, backgroundColor: colors.surface }]}\n        accessible={!!imageLabel}\n        accessibilityRole={imageLabel ? 'image' : undefined}\n        accessibilityLabel={imageLabel}\n        onLayout={(e) =>\n          setMedia({ width: e.nativeEvent.layout.width, height: e.nativeEvent.layout.height })\n        }\n      >\n        {source ? (\n          <Image source={source} style={StyleSheet.absoluteFill} resizeMode=\"cover\" />\n        ) : null}\n        {children}\n        <Animated.View\n          pointerEvents=\"none\"\n          style={[StyleSheet.absoluteFill, { backgroundColor: withAlpha(color, 0.3) }, wash]}\n        />\n        {media.width > 0 && !reduced ? (\n          <Pixels width={media.width} height={media.height} running={!done} live={live} />\n        ) : null}\n      </View>\n\n      <View\n        accessible\n        accessibilityRole=\"progressbar\"\n        accessibilityLabel={done ? doneLabel : label}\n        accessibilityValue={\n          done\n            ? { min: 0, max: 100, now: 100 }\n            : progress === undefined\n              ? undefined\n              : { min: 0, max: 100, now: Math.round(progress * 100) }\n        }\n        accessibilityLiveRegion=\"polite\"\n        onLayout={(e) => setPill(e.nativeEvent.layout.width)}\n        style={[styles.pill, { backgroundColor: colors.surfaceRaised, borderColor: colors.border }]}\n      >\n        {pill > 0 ? <Ring width={pill} progress={progress} done={done} color={color} /> : null}\n        <View\n          style={[\n            styles.inner,\n            { backgroundColor: colors.surfaceSunken, gap: space[3], paddingHorizontal: space[5] },\n          ]}\n        >\n          {done ? <Check color={color} /> : <Spinner />}\n          <Animated.Text\n            key={done ? 'done' : label}\n            // Only the new label animates: an exiting copy would sit beside it in the row.\n            entering={\n              reduced ? undefined : FadeInDown.duration(durations.base).easing(easings.standard)\n            }\n            numberOfLines={1}\n            style={{\n              flexShrink: 1,\n              color: done ? colors.text : colors.textMuted,\n              fontSize: font.size.lg,\n              fontWeight: font.weight.semibold,\n              letterSpacing: font.tracking.tight,\n            }}\n          >\n            {done ? doneLabel : label}\n          </Animated.Text>\n        </View>\n      </View>\n    </View>\n  );\n}\n\n/**\n * The pixel field. Each frame one worklet walks the grid and sorts the lit\n * squares into three brightness levels, drawn as three paths.\n */\nfunction Pixels({\n  width,\n  height,\n  running,\n  live,\n}: {\n  width: number;\n  height: number;\n  running: boolean;\n  live: SharedValue<number>;\n}) {\n  const { colors } = useKinetikTheme();\n  const time = useShaderClock({ running, frameRate: 30 });\n\n  // Per-cell randomness, worked out once per size.\n  const grid = useMemo(() => {\n    const cols = Math.floor(width / PITCH);\n    const rows = Math.floor(height / PITCH);\n    const left = (width - cols * PITCH) / 2;\n    const top = (height - rows * PITCH) / 2;\n    const seed: number[] = [];\n    const rate: number[] = [];\n    // Smooth value noise over blocks of four cells, so lit squares gather in\n    // clusters the way detected features would, rather than as even static.\n    const region: number[] = [];\n    const block = 4;\n    const smooth = (f: number) => f * f * (3 - 2 * f);\n    for (let j = 0; j < rows; j++) {\n      for (let i = 0; i < cols; i++) {\n        const bx = Math.floor(i / block);\n        const by = Math.floor(j / block);\n        const fx = smooth((i % block) / block);\n        const fy = smooth((j % block) / block);\n        const top0 = hash(bx, by) + (hash(bx + 1, by) - hash(bx, by)) * fx;\n        const bottom0 = hash(bx, by + 1) + (hash(bx + 1, by + 1) - hash(bx, by + 1)) * fx;\n        const n = top0 + (bottom0 - top0) * fy;\n        // Push the noise towards on or off for crisper clusters.\n        region.push(Math.min(1, Math.max(0, (n - 0.3) * 1.8)));\n        seed.push(hash(i, j));\n        rate.push(0.4 + hash(j + 17, i) * 1.4);\n      }\n    }\n    return { cols, rows, left, top, seed, rate, region };\n  }, [width, height]);\n\n  const levels = useDerivedValue(() => {\n    const t = time.get();\n    const { cols, rows, left, top, seed, rate, region } = grid;\n    const paths = [Skia.PathBuilder.Make(), Skia.PathBuilder.Make(), Skia.PathBuilder.Make()];\n    // The band rolls top to bottom every 2.8 s, with a pause off the bottom edge.\n    const sweep = ((t / 2.8) % 1) * 1.35 - 0.1;\n    for (let j = 0; j < rows; j++) {\n      const y = j / rows;\n      const d = sweep - y;\n      // Sharp leading edge, long fading trail above it, and a faint floor everywhere.\n      const band = d >= 0 ? Math.exp(-d * 2.2) : Math.exp(d * 18);\n      const field = 0.2 + band * 0.8;\n      for (let i = 0; i < cols; i++) {\n        const k = j * cols + i;\n        const s = seed[k]!;\n        const score = field * (0.15 + 0.85 * region[k]!);\n        const blink = (s * 13 + t * rate[k]!) % 1;\n        if (blink > score) continue;\n        const level = score > 0.62 ? 2 : score > 0.34 ? 1 : 0;\n        // Bright squares are a touch larger.\n        const size = DOT + (level === 2 && s > 0.6 ? 1 : 0);\n        paths[level]!.addRect(\n          Skia.XYWHRect(\n            left + i * PITCH + (PITCH - size) / 2,\n            top + j * PITCH + (PITCH - size) / 2,\n            size,\n            size,\n          ),\n        );\n      }\n    }\n    return paths.map((p) => p.detach());\n  });\n\n  const low = useDerivedValue<SkPath>(() => levels.get()[0]!);\n  const mid = useDerivedValue<SkPath>(() => levels.get()[1]!);\n  const high = useDerivedValue<SkPath>(() => levels.get()[2]!);\n\n  return (\n    <Canvas style={StyleSheet.absoluteFill} pointerEvents=\"none\">\n      <Group opacity={live}>\n        <Path path={low} color={withAlpha(colors.highlight, 0.28)} />\n        <Path path={mid} color={withAlpha(colors.highlight, 0.6)} />\n        <Path path={high} color={withAlpha(colors.highlight, 0.95)} />\n      </Group>\n    </Canvas>\n  );\n}\n\n/** The outline of the pill, traced clockwise from the top centre. */\nfunction ringPath(w: number, h: number): SkPath {\n  const s = RING / 2;\n  const x0 = s;\n  const y0 = s;\n  const x1 = w - s;\n  const y1 = h - s;\n  const r = (h - RING) / 2;\n  const cx = w / 2;\n  const d = [\n    `M ${cx} ${y0}`,\n    `H ${x1 - r}`,\n    `A ${r} ${r} 0 0 1 ${x1} ${y0 + r}`,\n    `A ${r} ${r} 0 0 1 ${x1 - r} ${y1}`,\n    `H ${x0 + r}`,\n    `A ${r} ${r} 0 0 1 ${x0} ${y0 + r}`,\n    `A ${r} ${r} 0 0 1 ${x0 + r} ${y0}`,\n    `H ${cx}`,\n  ].join(' ');\n  return Skia.Path.MakeFromSVGString(d) ?? Skia.Path.Make();\n}\n\nfunction Ring({\n  width,\n  progress,\n  done,\n  color,\n}: {\n  width: number;\n  progress?: number;\n  done: boolean;\n  color: string;\n}) {\n  const reduced = useReduceMotion();\n  const path = useMemo(() => ringPath(width, PILL), [width]);\n  const end = useSharedValue(0);\n  // Without a known progress, creep towards 90% and slow down, the way waits feel.\n  const creep = useSharedValue(0);\n  const known = progress !== undefined;\n\n  useEffect(() => {\n    if (known || done) return;\n    creep.set(\n      reduced ? 0.6 : withTiming(0.9, { duration: 14000, easing: Easing.out(Easing.cubic) }),\n    );\n  }, [known, done, reduced, creep]);\n\n  useEffect(() => {\n    if (done) {\n      end.set(withTiming(1, { ...timing('slow', reduced), duration: 600 }));\n    } else if (known) {\n      end.set(withSpring(Math.max(0, Math.min(1, progress)), spring('smooth', reduced)));\n    }\n  }, [done, known, progress, reduced, end]);\n\n  const trace = useDerivedValue(() => (known || done ? end.get() : creep.get()));\n\n  return (\n    <Canvas style={StyleSheet.absoluteFill} pointerEvents=\"none\">\n      <Path\n        path={path}\n        style=\"stroke\"\n        strokeWidth={RING}\n        strokeCap=\"round\"\n        color={color}\n        start={0}\n        end={trace}\n      />\n    </Canvas>\n  );\n}\n\n/** Eight dashes in a circle, turning. */\nfunction Spinner() {\n  const { colors } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const turn = useSharedValue(0);\n  useEffect(() => {\n    turn.set(\n      reduced ? 0 : withRepeat(withTiming(1, { duration: 1400, easing: Easing.linear }), -1),\n    );\n  }, [reduced, turn]);\n  const spin = useAnimatedStyle(() => ({ transform: [{ rotate: `${turn.get() * 360}deg` }] }));\n  return (\n    <Animated.View aria-hidden style={[styles.spinner, spin]}>\n      {Array.from({ length: 8 }, (_, i) => (\n        <View key={i} style={[styles.dashSlot, { transform: [{ rotate: `${i * 45}deg` }] }]}>\n          <View style={[styles.dash, { backgroundColor: colors.textSubtle }]} />\n        </View>\n      ))}\n    </Animated.View>\n  );\n}\n\n/** A filled circle that pops in, then a tick that draws itself. */\nfunction Check({ color }: { color: string }) {\n  const { colors } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const pop = useSharedValue(reduced ? 1 : 0);\n  const tick = useSharedValue(reduced ? 1 : 0);\n  useEffect(() => {\n    if (reduced) return;\n    pop.set(withSpring(1, spring('bouncy')));\n    tick.set(withDelay(140, withTiming(1, timing('base'))));\n  }, [reduced, pop, tick]);\n  const circle = useAnimatedStyle(() => ({ transform: [{ scale: pop.get() }] }));\n  const mark = useAnimatedStyle(() => ({\n    opacity: tick.get(),\n    transform: [{ rotate: '-45deg' }, { scale: 0.5 + tick.get() * 0.5 }],\n  }));\n  return (\n    <Animated.View aria-hidden style={[styles.check, { backgroundColor: color }, circle]}>\n      <Animated.View style={[styles.tick, { borderColor: colors.background }, mark]} />\n    </Animated.View>\n  );\n}\n\nconst styles = StyleSheet.create({\n  glow: { position: 'absolute', top: 0, left: 0, right: 0 },\n  card: { overflow: 'hidden' },\n  pill: {\n    height: PILL,\n    borderRadius: PILL / 2,\n    borderWidth: StyleSheet.hairlineWidth,\n    padding: 6,\n  },\n  inner: {\n    flex: 1,\n    borderRadius: PILL / 2,\n    flexDirection: 'row',\n    alignItems: 'center',\n    justifyContent: 'center',\n  },\n  spinner: { width: 22, height: 22 },\n  dashSlot: {\n    position: 'absolute',\n    left: 0,\n    top: 0,\n    width: 22,\n    height: 22,\n    alignItems: 'center',\n  },\n  dash: { width: 2, height: 5, borderRadius: 1 },\n  check: {\n    width: 22,\n    height: 22,\n    borderRadius: 11,\n    alignItems: 'center',\n    justifyContent: 'center',\n  },\n  tick: { width: 11, height: 6, marginTop: -3, borderLeftWidth: 2, borderBottomWidth: 2 },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "feedback",
    "web": "live",
    "perf": {
      "budget": "The pixel field is three Skia paths rebuilt 30 times a second by one worklet while scanning; it stops completely when done. The ring is one trimmed path.",
      "measurements": [
        {
          "device": "Pixel 9 emulator, API 35",
          "kind": "emulator",
          "date": "2026-10-14",
          "build": "release",
          "frameMs": 24,
          "p90Ms": 27,
          "baselineMs": 17,
          "jankyPercent": 0.17,
          "atRest": "animating",
          "memoryMb": 195,
          "notes": "Animating while scanning: the pixel field redraws 30 times a second and the spinner turns; both stop when done. Most of each frame is the emulator GPU swap."
        }
      ]
    },
    "a11y": {
      "reducedMotion": "No pixel field or spinner rotation; the wash, the ring and the labels still show progress.",
      "screenReader": "The pill is a progress bar named by the current step, with its percentage when known; changes are announced. Pass imageLabel to describe the image.",
      "touchTarget": "Not interactive."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { ScanProgress } from '@/components/kinetik/scan-progress';\n\n<ScanProgress\n  source={{ uri: video.thumbnail }}\n  imageLabel=\"Your swing, frame 1\"\n  progress={job.progress}\n  done={job.status === 'complete'}\n  label={job.stepLabel}\n/>;\n```\n\nLeave out `progress` when the work has no measurable progress: the ring creeps towards 90% and slows down, and closes when `done` turns true.\n\n## When to use\n\n- Processing a photo or video the person just gave you: AI analysis, enhancement, background removal, upload checks.\n- Waits of a few seconds to a minute, where seeing the image being worked on reassures.\n\n## When not to use\n\n- Instant results under a second: the effect would only flash.\n- Waits without an image: use a progress bar or Ring Spinner.\n\n## Notes\n\n- `label` changes cross-fade, so you can name each step as it happens.\n- The pixel field draws white squares over the image; pick a `tint` that suits your photos (it defaults to the theme success green).\n- With reduced motion the pixel field and spinner rotation are left out; the ring and labels still report progress.\n"
  },
  "docs": "Prefer `npx kinetik-ui add scan-progress`: it installs dependencies with expo install, so versions match your Expo SDK."
}
