{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "onboarding",
  "type": "registry:block",
  "title": "Onboarding",
  "description": "A paged welcome with animated illustration panels, a progress line that follows the swipe and word-by-word titles.",
  "categories": [
    "screen"
  ],
  "dependencies": [
    "react-native-reanimated",
    "react-native-safe-area-context",
    "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/press-jelly.json",
    "https://kinetik-ui.dev/r/word-cascade.json"
  ],
  "files": [
    {
      "path": "src/components/kinetik/screens/onboarding.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/screens/onboarding.tsx",
      "content": "import { useEffect, useRef, useState, type ReactNode } from 'react';\nimport {\n  Pressable,\n  StyleSheet,\n  Text,\n  View,\n  type LayoutChangeEvent,\n  type NativeScrollEvent,\n  type NativeSyntheticEvent,\n} from 'react-native';\nimport Animated, {\n  Extrapolation,\n  interpolate,\n  useAnimatedRef,\n  useAnimatedScrollHandler,\n  useAnimatedStyle,\n  useSharedValue,\n  withDelay,\n  withRepeat,\n  withSequence,\n  withSpring,\n  withTiming,\n  type SharedValue,\n} from 'react-native-reanimated';\nimport { useSafeAreaInsets } from 'react-native-safe-area-context';\n\nimport { PressJelly } from '../press-jelly';\nimport { WordCascade } from '../word-cascade';\nimport { spring, timing } from '../../../lib/kinetik/motion/motion';\nimport { useReduceMotion } from '../../../lib/kinetik/hooks/use-reduce-motion';\nimport { useKinetikTheme } from '../../../lib/kinetik/tokens/theme';\nimport { minTouchTarget } from '../../../lib/kinetik/tokens/tokens';\n\nexport type OnboardingSlide = {\n  key: string;\n  /** Small chip above the title, e.g. \"Easy sign-up\". */\n  tag?: string;\n  title: string;\n  /**\n   * Fills the rounded panel at the top. Receives whether its slide is the\n   * current one, so it can play only while visible. Defaults to built-in\n   * illustrations.\n   */\n  visual?: (active: boolean) => ReactNode;\n};\n\nexport type OnboardingProps = {\n  /** Called by the button on the last slide. */\n  onFinish: () => void;\n  /** Called by the link under the button. Hidden when omitted. */\n  onSkip?: () => void;\n  slides?: readonly OnboardingSlide[];\n  /** Button label before the last slide. Defaults to \"Continue\". */\n  nextLabel?: string;\n  /** Button label on the last slide. Defaults to \"Get started\". */\n  finishLabel?: string;\n  /** Link label. Defaults to \"Maybe later\". */\n  skipLabel?: string;\n};\n\nconst DEFAULT_SLIDES: OnboardingSlide[] = [\n  { key: 'welcome', tag: 'Welcome', title: 'Everything you track, in one calm place' },\n  { key: 'setup', tag: 'Easy setup', title: 'Set up your account in under a minute' },\n  { key: 'nudge', tag: 'Stay on top', title: 'A nudge only when it really matters' },\n];\n\nconst DEFAULT_VISUALS = [\n  (active: boolean) => <CardStack active={active} />,\n  (active: boolean) => <Checklist active={active} />,\n  (active: boolean) => <Nudge active={active} />,\n];\n\n/**\n * A paged welcome: a rounded illustration panel, a thin progress line that\n * follows the finger, a tag and a title that rises in word by word, and one\n * clear button with a quiet \"Maybe later\" under it.\n */\nexport function Onboarding({\n  onFinish,\n  onSkip,\n  slides = DEFAULT_SLIDES,\n  nextLabel = 'Continue',\n  finishLabel = 'Get started',\n  skipLabel = 'Maybe later',\n}: OnboardingProps) {\n  const { colors, space, font } = useKinetikTheme();\n  const insets = useSafeAreaInsets();\n  const scroller = useAnimatedRef<Animated.ScrollView>();\n  const offset = useSharedValue(0);\n  const widthRef = useRef(0);\n  const [width, setWidth] = useState(0);\n  const [height, setHeight] = useState(0);\n  const [index, setIndex] = useState(0);\n  const count = slides.length;\n  const last = index >= count - 1;\n\n  const onScroll = useAnimatedScrollHandler((e) => {\n    offset.set(e.contentOffset.x);\n  });\n\n  const onLayout = (e: LayoutChangeEvent) => {\n    widthRef.current = e.nativeEvent.layout.width;\n    setWidth(e.nativeEvent.layout.width);\n  };\n\n  const settle = (e: NativeSyntheticEvent<NativeScrollEvent>) => {\n    const w = widthRef.current;\n    if (w > 0) setIndex(Math.round(e.nativeEvent.contentOffset.x / w));\n  };\n\n  const next = () => {\n    if (last) return onFinish();\n    const to = index + 1;\n    scroller.current?.scrollTo({ x: to * widthRef.current, animated: true });\n    setIndex(to);\n  };\n\n  const pad = space[6];\n\n  return (\n    <View\n      style={[\n        styles.fill,\n        {\n          backgroundColor: colors.background,\n          paddingTop: insets.top + space[3],\n          paddingBottom: insets.bottom + space[4],\n        },\n      ]}\n      onLayout={onLayout}\n      testID=\"onboarding\"\n    >\n      <Animated.ScrollView\n        ref={scroller}\n        horizontal\n        pagingEnabled\n        showsHorizontalScrollIndicator={false}\n        onScroll={onScroll}\n        scrollEventThrottle={16}\n        onMomentumScrollEnd={settle}\n        onLayout={(e) => setHeight(e.nativeEvent.layout.height)}\n        style={styles.fill}\n      >\n        {width > 0 &&\n          slides.map((slide, i) => {\n            const active = i === index;\n            return (\n              <View\n                key={slide.key}\n                style={{\n                  width,\n                  height: height || undefined,\n                  paddingHorizontal: pad,\n                  paddingBottom: space[6],\n                  gap: space[5],\n                }}\n                accessibilityElementsHidden={!active}\n                importantForAccessibility={active ? 'auto' : 'no-hide-descendants'}\n              >\n                <Panel>{(slide.visual ?? DEFAULT_VISUALS[i % 3])?.(active)}</Panel>\n                <Track index={i} count={count} offset={offset} width={width} />\n                <View style={{ gap: space[3], alignItems: 'flex-start' }}>\n                  {slide.tag ? (\n                    <View\n                      style={[\n                        styles.tag,\n                        { backgroundColor: colors.surfaceRaised, borderColor: colors.border },\n                      ]}\n                    >\n                      <Text\n                        style={{\n                          color: colors.textMuted,\n                          fontSize: font.size.xs,\n                          fontWeight: font.weight.semibold,\n                        }}\n                      >\n                        {slide.tag}\n                      </Text>\n                    </View>\n                  ) : null}\n                  <WordCascade\n                    text={slide.title}\n                    replayKey={active ? `${slide.key}-on` : slide.key}\n                    stagger={55}\n                    rise={14}\n                    style={{\n                      color: colors.text,\n                      fontSize: font.size['2xl'],\n                      lineHeight: 34,\n                      fontWeight: font.weight.bold,\n                      letterSpacing: font.tracking.tight,\n                    }}\n                  />\n                </View>\n              </View>\n            );\n          })}\n      </Animated.ScrollView>\n\n      <View style={{ paddingHorizontal: pad, gap: space[2] }}>\n        <PressJelly block size=\"lg\" onPress={next}>\n          {last ? finishLabel : nextLabel}\n        </PressJelly>\n        {onSkip ? (\n          <Pressable accessibilityRole=\"button\" onPress={onSkip} style={styles.link} hitSlop={4}>\n            <Text\n              style={{\n                color: colors.textMuted,\n                fontSize: font.size.sm,\n                fontWeight: font.weight.medium,\n                textDecorationLine: 'underline',\n              }}\n            >\n              {skipLabel}\n            </Text>\n          </Pressable>\n        ) : (\n          <View style={styles.link} />\n        )}\n      </View>\n    </View>\n  );\n}\n\n/** The rounded panel every illustration sits in. */\nfunction Panel({ children }: { children: ReactNode }) {\n  const { colors, radius } = useKinetikTheme();\n  return (\n    <View\n      style={[\n        styles.panel,\n        {\n          backgroundColor: colors.surface,\n          borderColor: colors.border,\n          borderRadius: radius.xl,\n        },\n      ]}\n    >\n      {children}\n    </View>\n  );\n}\n\n/**\n * A hairline under the panel with one darker segment per slide. Every slide\n * draws it, so it scrolls with the page; the segment itself counters the\n * scroll and slides along the line as the finger moves.\n */\nfunction Track({\n  index,\n  count,\n  offset,\n  width,\n}: {\n  index: number;\n  count: number;\n  offset: SharedValue<number>;\n  width: number;\n}) {\n  const { colors, space } = useKinetikTheme();\n  const inner = width - space[6] * 2;\n  const segment = inner / count;\n  const style = useAnimatedStyle(() => {\n    const progress = width > 0 ? offset.get() / width : 0;\n    return { transform: [{ translateX: progress * segment }] };\n  });\n  // Only the current slide's line is visible; the others fade as they leave.\n  const fade = useAnimatedStyle(() => {\n    const progress = width > 0 ? offset.get() / width - index : 0;\n    return { opacity: interpolate(Math.abs(progress), [0, 0.6], [1, 0], Extrapolation.CLAMP) };\n  });\n  return (\n    <Animated.View\n      accessible\n      accessibilityRole=\"text\"\n      accessibilityLabel={`Step ${index + 1} of ${count}`}\n      style={[styles.track, { backgroundColor: colors.track }, fade]}\n    >\n      <Animated.View\n        style={[styles.segment, { width: segment, backgroundColor: colors.text }, style]}\n      />\n    </Animated.View>\n  );\n}\n\n/** Three cards that fan out and drift, standing for \"everything in one place\". */\nfunction CardStack({ active }: { active: boolean }) {\n  const { colors, radius, space } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const fan = useSharedValue(reduced ? 1 : 0);\n  const float = useSharedValue(0);\n\n  useEffect(() => {\n    fan.set(active ? withDelay(120, withSpring(1, spring('bouncy', reduced))) : 0);\n    float.set(\n      active && !reduced\n        ? withRepeat(withTiming(1, { ...timing('slow', false, 'inOut'), duration: 2400 }), -1, true)\n        : 0,\n    );\n  }, [active, reduced, fan, float]);\n\n  const face = (fill: string, lines: number[]) => (\n    <View\n      style={[\n        styles.card,\n        {\n          backgroundColor: colors.surfaceRaised,\n          borderColor: colors.border,\n          borderRadius: radius.lg,\n          padding: space[3],\n          gap: space[2],\n        },\n      ]}\n    >\n      <View style={[styles.cardDot, { backgroundColor: fill }]} />\n      {lines.map((w, i) => (\n        <View key={i} style={[styles.line, { width: `${w}%`, backgroundColor: colors.track }]} />\n      ))}\n      <View style={[styles.cardBar, { backgroundColor: fill, borderRadius: radius.sm }]} />\n    </View>\n  );\n\n  return (\n    <View style={styles.center}>\n      <FanCard angle={-9} shift={-46} fan={fan} float={float}>\n        {face(colors.azure, [70, 46])}\n      </FanCard>\n      <FanCard angle={9} shift={46} fan={fan} float={float}>\n        {face(colors.success, [58, 80])}\n      </FanCard>\n      <FanCard angle={0} shift={0} fan={fan} float={float}>\n        {face(colors.ember, [82, 54])}\n      </FanCard>\n    </View>\n  );\n}\n\nfunction FanCard({\n  angle,\n  shift,\n  fan,\n  float,\n  children,\n}: {\n  angle: number;\n  shift: number;\n  fan: SharedValue<number>;\n  float: SharedValue<number>;\n  children: ReactNode;\n}) {\n  const style = useAnimatedStyle(() => ({\n    transform: [\n      { translateX: shift * fan.get() },\n      { translateY: -float.get() * (angle === 0 ? 8 : 4) },\n      { rotate: `${angle * fan.get()}deg` },\n    ],\n  }));\n  return <Animated.View style={[styles.layer, style]}>{children}</Animated.View>;\n}\n\nconst CHECKS = ['Create your profile', 'Pick what you follow', 'Turn on reminders'];\n\n/** A setup list that ticks itself off, row by row. */\nfunction Checklist({ active }: { active: boolean }) {\n  const { colors, radius, space, font } = useKinetikTheme();\n  return (\n    <View style={styles.center}>\n      <View\n        style={[\n          styles.sheet,\n          {\n            backgroundColor: colors.surfaceRaised,\n            borderColor: colors.border,\n            borderRadius: radius.lg,\n            padding: space[4],\n            gap: space[3],\n          },\n        ]}\n      >\n        {CHECKS.map((label, i) => (\n          <CheckRow key={label} label={label} index={i} active={active} />\n        ))}\n        <View style={[styles.line, { width: '40%', backgroundColor: colors.track }]} />\n        <Text style={{ color: colors.textSubtle, fontSize: font.size.xs }}>About a minute</Text>\n      </View>\n    </View>\n  );\n}\n\nfunction CheckRow({ label, index, active }: { label: string; index: number; active: boolean }) {\n  const { colors, font, space } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const done = useSharedValue(reduced ? 1 : 0);\n\n  useEffect(() => {\n    done.set(\n      active\n        ? withDelay(reduced ? 0 : 450 + index * 420, withSpring(1, spring('bouncy', reduced)))\n        : 0,\n    );\n  }, [active, reduced, index, done]);\n\n  const fill = useAnimatedStyle(() => ({\n    opacity: Math.min(1, done.get()),\n    transform: [{ scale: done.get() }],\n  }));\n  const text = useAnimatedStyle(() => ({ opacity: 0.55 + Math.min(1, done.get()) * 0.45 }));\n\n  return (\n    <View style={[styles.row, { gap: space[3] }]}>\n      <View style={[styles.box, { borderColor: colors.borderStrong }]}>\n        <Animated.View style={[styles.boxFill, { backgroundColor: colors.ember }, fill]}>\n          <Text style={{ color: colors.onEmber, fontSize: 11, fontWeight: font.weight.heavy }}>\n            ✓\n          </Text>\n        </Animated.View>\n      </View>\n      <Animated.Text\n        style={[\n          { color: colors.text, fontSize: font.size.sm, fontWeight: font.weight.medium },\n          text,\n        ]}\n      >\n        {label}\n      </Animated.Text>\n    </View>\n  );\n}\n\n/** A notification drops in over a quiet screen, then tucks away again. */\nfunction Nudge({ active }: { active: boolean }) {\n  const { colors, radius, space, font } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const drop = useSharedValue(reduced ? 1 : 0);\n  const ring = useSharedValue(0);\n\n  useEffect(() => {\n    if (!active || reduced) {\n      drop.set(reduced ? 1 : 0);\n      ring.set(0);\n      return;\n    }\n    drop.set(\n      withRepeat(\n        withSequence(\n          withDelay(300, withSpring(1, spring('bouncy'))),\n          withDelay(1800, withTiming(0, timing('base', false, 'exit'))),\n        ),\n        -1,\n      ),\n    );\n    ring.set(withRepeat(withTiming(1, { ...timing('slow', false, 'linear'), duration: 1600 }), -1));\n  }, [active, reduced, drop, ring]);\n\n  const banner = useAnimatedStyle(() => ({\n    opacity: Math.min(1, drop.get() * 1.4),\n    transform: [{ translateY: (1 - drop.get()) * -70 }, { scale: 0.94 + drop.get() * 0.06 }],\n  }));\n  const pulse = useAnimatedStyle(() => ({\n    opacity: (1 - ring.get()) * 0.5,\n    transform: [{ scale: 1 + ring.get() * 1.6 }],\n  }));\n\n  return (\n    <View style={styles.center}>\n      <View\n        style={[\n          styles.phone,\n          { borderColor: colors.borderStrong, backgroundColor: colors.background },\n        ]}\n      >\n        <Animated.View\n          style={[\n            styles.banner,\n            {\n              backgroundColor: colors.surfaceRaised,\n              borderColor: colors.border,\n              borderRadius: radius.md,\n              padding: space[2],\n              gap: space[2],\n            },\n            banner,\n          ]}\n        >\n          <View style={styles.bell}>\n            <Animated.View style={[styles.bellRing, { borderColor: colors.ember }, pulse]} />\n            <View style={[styles.bellDot, { backgroundColor: colors.ember }]} />\n          </View>\n          <View style={styles.fill}>\n            <Text\n              numberOfLines={1}\n              style={{ color: colors.text, fontSize: 11, fontWeight: font.weight.bold }}\n            >\n              Rent due tomorrow\n            </Text>\n            <Text numberOfLines={1} style={{ color: colors.textMuted, fontSize: 10 }}>\n              Tap to pay\n            </Text>\n          </View>\n        </Animated.View>\n        <View style={{ gap: space[2], marginTop: 'auto' }}>\n          <View style={[styles.line, { width: '70%', backgroundColor: colors.track }]} />\n          <View style={[styles.line, { width: '50%', backgroundColor: colors.track }]} />\n          <View style={[styles.line, { width: '84%', backgroundColor: colors.track }]} />\n        </View>\n      </View>\n    </View>\n  );\n}\n\nconst styles = StyleSheet.create({\n  fill: { flex: 1 },\n  panel: { flex: 1, minHeight: 240, borderWidth: StyleSheet.hairlineWidth, overflow: 'hidden' },\n  center: { flex: 1, alignItems: 'center', justifyContent: 'center' },\n  track: { height: 3, borderRadius: 2, overflow: 'hidden' },\n  segment: { height: 3, borderRadius: 2 },\n  tag: {\n    paddingHorizontal: 10,\n    paddingVertical: 5,\n    borderRadius: 8,\n    borderWidth: StyleSheet.hairlineWidth,\n  },\n  link: { minHeight: minTouchTarget, alignItems: 'center', justifyContent: 'center' },\n  layer: { position: 'absolute' },\n  card: { width: 132, height: 168, borderWidth: StyleSheet.hairlineWidth },\n  cardDot: { width: 28, height: 28, borderRadius: 14, marginBottom: 6 },\n  cardBar: { height: 44, marginTop: 'auto', opacity: 0.85 },\n  line: { height: 7, borderRadius: 4 },\n  sheet: { width: '78%', maxWidth: 280, borderWidth: StyleSheet.hairlineWidth },\n  row: { flexDirection: 'row', alignItems: 'center' },\n  box: {\n    width: 22,\n    height: 22,\n    borderRadius: 11,\n    borderWidth: 1.5,\n    alignItems: 'center',\n    justifyContent: 'center',\n  },\n  boxFill: {\n    width: 22,\n    height: 22,\n    borderRadius: 11,\n    alignItems: 'center',\n    justifyContent: 'center',\n  },\n  phone: {\n    width: 196,\n    height: 236,\n    marginBottom: -48,\n    borderRadius: 28,\n    borderWidth: 1.5,\n    padding: 12,\n    paddingBottom: 60,\n  },\n  banner: {\n    flexDirection: 'row',\n    alignItems: 'center',\n    borderWidth: StyleSheet.hairlineWidth,\n  },\n  bell: { width: 26, height: 26, alignItems: 'center', justifyContent: 'center' },\n  bellRing: { position: 'absolute', width: 14, height: 14, borderRadius: 7, borderWidth: 1.5 },\n  bellDot: { width: 12, height: 12, borderRadius: 6 },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "template",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "screen",
    "web": "live",
    "perf": {
      "budget": "Only the current slide's illustration animates (UI-thread springs and loops); the others rest. The progress line is a scroll-driven worklet.",
      "measurements": [
        {
          "device": "Pixel 9 emulator, API 35",
          "kind": "emulator",
          "date": "2026-10-14",
          "build": "release",
          "frameMs": 18,
          "p90Ms": 24,
          "baselineMs": 17,
          "jankyPercent": 0.53,
          "atRest": "animating",
          "memoryMb": 156,
          "notes": "Animating at rest: the current slide’s illustration keeps drifting or looping while it is on screen."
        }
      ]
    },
    "a11y": {
      "reducedMotion": "Illustrations show their finished state without looping, and titles appear without rising (Word Cascade). Paging is user-driven, so it stays.",
      "screenReader": "Only the current slide is exposed. The progress line reads \"Step 2 of 3\". The button is named Continue, then Get started; Maybe later is a separate button.",
      "touchTarget": "The main button is 56 pt tall; Maybe later is at least 44 pt."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { Onboarding } from '@/components/kinetik/screens/onboarding';\n\n<Onboarding\n  slides={[\n    { key: 'track', tag: 'Welcome', title: 'Every habit in one calm place' },\n    { key: 'setup', tag: 'Easy setup', title: 'Set up your account in under a minute' },\n    {\n      key: 'remind',\n      tag: 'Stay on top',\n      title: 'A nudge only when it really matters',\n      visual: (active) => <MyIllustration playing={active} />,\n    },\n  ]}\n  onFinish={() => router.replace('/sign-up')}\n  onSkip={() => router.replace('/home')}\n/>;\n```\n\nSlides without a `visual` use the built-in illustrations (a fanned card stack, a self-ticking checklist and a notification). Pass your own `visual` to show product shots or animations; it receives `active` so it can play only while its slide is on screen.\n\n## When to use\n\n- The first launch, to set expectations in two to four short slides.\n- Before sign-up, when people should know what they get for an account.\n\n## When not to use\n\n- To explain controls the app could make obvious: put hints where the controls are.\n- More than four slides. People skip long tours; keep the rest for later moments.\n\n## Notes\n\n- The button advances the pager; on the last slide it becomes Get started and calls `onFinish`. Swiping works too.\n- Leave out `onSkip` to hide Maybe later, for flows that must be completed.\n"
  },
  "docs": "Prefer `npx kinetik-ui add onboarding`: it installs dependencies with expo install, so versions match your Expo SDK."
}
