{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "range-slider",
  "title": "Range Slider",
  "type": "registry:ui",
  "files": [
    {
      "path": "packages/registry-native/components/range-slider/RangeSlider.tsx",
      "content": "import * as React from 'react'\nimport { I18nManager, View, type LayoutChangeEvent, type ViewProps } from 'react-native'\nimport { Gesture, GestureDetector, GestureHandlerRootView } from 'react-native-gesture-handler'\nimport { cn } from '@/lib/utils'\n\nexport type RangeValue = [number, number]\ntype Thumb = 0 | 1\n\nexport interface RangeSliderProps extends Omit<ViewProps, 'children'> {\n  min?: number\n  max?: number\n  /** Positive step size. Values snap to `min + n * step`; `max` stays reachable. Non-positive means continuous. */\n  step?: number\n  value?: RangeValue\n  defaultValue?: RangeValue\n  disabled?: boolean\n  /** Lower and upper thumb names for assistive technology. */\n  thumbLabels?: [string, string]\n  /** Called with each new pair while dragging or adjusting. A controlled owner may refuse it. */\n  onValueChange?: (value: RangeValue) => void\n  /** Called once when a drag or accessibility adjustment ends with the last requested pair. */\n  onSlidingComplete?: (value: RangeValue) => void\n  className?: string\n}\n\n/** Touch target edge; the track is inset by half of it so both thumbs fit at the ends. */\nconst HIT = 48\nconst HALF = HIT / 2\n\nfunction decimals(value: number) {\n  const text = String(value)\n  if (text.includes('e-')) return Number(text.split('e-')[1])\n  return text.includes('.') ? text.split('.')[1].length : 0\n}\n\ninterface Scale {\n  min: number\n  max: number\n  step: number\n  places: number\n}\nfunction scaleOf(min: number, max: number, step: number): Scale {\n  const lo = Number.isFinite(min) ? min : 0\n  const hi = Number.isFinite(max) && max > lo ? max : lo\n  const size = Number.isFinite(step) && step > 0 ? step : 0\n  const places = Math.min(10, Math.max(decimals(size), decimals(lo), decimals(hi)))\n  return { min: lo, max: hi, step: size, places }\n}\nfunction snap(value: number, scale: Scale) {\n  if (!Number.isFinite(value) || value <= scale.min) return scale.min\n  // Endpoints are returned exactly: rounding an off-grid max (10.5 -> 11) would escape the bounds.\n  if (value >= scale.max) return scale.max\n  if (!scale.step) return value\n  const round = (next: number) => Number(next.toFixed(scale.places))\n  // The last grid point may fall short of an off-grid max; max itself is a valid stop when nearer.\n  const lastGrid = round(scale.min + Math.floor((scale.max - scale.min) / scale.step + 1e-9) * scale.step)\n  const stepped = Math.min(lastGrid, round(scale.min + Math.round((value - scale.min) / scale.step) * scale.step))\n  if (value - stepped > scale.max - value) return scale.max\n  return Math.min(scale.max, Math.max(scale.min, stepped))\n}\nfunction normalize(pair: RangeValue | undefined, scale: Scale): RangeValue {\n  const lower = snap(pair?.[0] ?? scale.min, scale)\n  const upper = snap(pair?.[1] ?? scale.max, scale)\n  return lower <= upper ? [lower, upper] : [upper, lower]\n}\nfunction same(a: RangeValue, b: RangeValue) {\n  return a[0] === b[0] && a[1] === b[1]\n}\n\n/**\n * iOS Fabric only accepts integers in accessibilityValue min/max/now and crashes on fractions,\n * so decimal ranges are announced through text alone.\n */\nfunction accessibleValue(min: number, max: number, now: number) {\n  const text = String(now)\n  return [min, max, now].every(Number.isInteger) ? { min, max, now, text } : { text }\n}\n\ninterface Drag {\n  thumb: Thumb | null\n  offset: number\n  requested: RangeValue | null\n  startX: number\n}\n\nexport const RangeSlider = React.forwardRef<React.ComponentRef<typeof View>, RangeSliderProps>(\n  (\n    {\n      min = 0,\n      max = 100,\n      step = 1,\n      value,\n      defaultValue,\n      disabled = false,\n      thumbLabels = ['Minimum', 'Maximum'],\n      onValueChange,\n      onSlidingComplete,\n      className,\n      ...props\n    },\n    ref,\n  ) => {\n    const scale = scaleOf(min, max, step)\n    const [internal, setInternal] = React.useState<RangeValue | undefined>(defaultValue)\n    const [width, setWidth] = React.useState(0)\n    const current = normalize(value ?? internal, scale)\n    const travel = Math.max(0, width - HIT)\n    const span = scale.max - scale.min\n    const adjustable = !disabled && span > 0\n    const interactive = adjustable && travel > 0\n    const rtl = I18nManager.isRTL\n\n    // Gesture callbacks run on the JS thread and may outlive a render; read live values from refs.\n    const live = React.useRef({\n      current,\n      scale,\n      width,\n      travel,\n      rtl,\n      interactive,\n      value,\n      onValueChange,\n      onSlidingComplete,\n    })\n    live.current = { current, scale, width, travel, rtl, interactive, value, onValueChange, onSlidingComplete }\n    const drag = React.useRef<Drag>({ thumb: null, offset: 0, requested: null, startX: 0 })\n\n    // Bounds, step, or availability changing under a finger invalidate the drag geometry: drop it.\n    React.useEffect(() => {\n      drag.current = { thumb: null, offset: 0, requested: null, startX: 0 }\n    }, [scale.min, scale.max, scale.step, interactive, travel])\n\n    const position = (next: number) => HALF + (span > 0 ? ((next - scale.min) / span) * travel : 0)\n\n    function request(next: RangeValue) {\n      const state = live.current\n      if (same(next, state.current)) return false\n      if (state.value === undefined) setInternal(next)\n      state.onValueChange?.(next)\n      return true\n    }\n    function move(thumb: Thumb, target: number): RangeValue {\n      const [lower, upper] = live.current.current\n      const snapped = snap(target, live.current.scale)\n      // Thumbs never cross: each one stops at the other.\n      return thumb === 0 ? [Math.min(snapped, upper), upper] : [lower, Math.max(snapped, lower)]\n    }\n    function valueAt(logicalX: number) {\n      const state = live.current\n      const ratio = state.travel ? (logicalX - HALF) / state.travel : 0\n      return state.scale.min + ratio * (state.scale.max - state.scale.min)\n    }\n    const logical = (x: number) => (live.current.rtl ? live.current.width - x : x)\n\n    const pan = Gesture.Pan()\n      .runOnJS(true)\n      .enabled(interactive)\n      // Horizontal intent only; vertical movement fails fast so a parent ScrollView keeps scrolling.\n      .activeOffsetX([-10, 10])\n      .failOffsetY([-10, 10])\n      .onBegin((event) => {\n        if (!live.current.interactive) return\n        const x = logical(event.x)\n        const [lower, upper] = live.current.current\n        const lowerX = position(lower)\n        const upperX = position(upper)\n        // Overlapping thumbs are resolved by the first movement direction in onStart.\n        const thumb: Thumb | null = lowerX === upperX ? null : Math.abs(x - lowerX) <= Math.abs(x - upperX) ? 0 : 1\n        const thumbX = thumb === 1 ? upperX : lowerX\n        drag.current = {\n          thumb,\n          // Grabbing a thumb keeps its grip point; touching bare track moves the nearest thumb to the finger.\n          offset: Math.abs(x - thumbX) <= HALF ? x - thumbX : 0,\n          requested: null,\n          startX: x,\n        }\n      })\n      .onStart((event) => {\n        const state = drag.current\n        if (state.thumb !== null) return\n        const forward = logical(event.x) >= state.startX\n        const [lower, upper] = live.current.current\n        // Stacked at an end, only one direction can move: pick the thumb that can.\n        if (upper >= live.current.scale.max) state.thumb = 0\n        else if (lower <= live.current.scale.min) state.thumb = 1\n        else state.thumb = forward ? 1 : 0\n      })\n      .onUpdate((event) => {\n        const state = drag.current\n        if (state.thumb === null || !live.current.interactive) return\n        const next = move(state.thumb, valueAt(logical(event.x) - state.offset))\n        if (state.requested && same(next, state.requested)) return\n        state.requested = next\n        request(next)\n      })\n      .onEnd(() => {\n        const state = drag.current\n        if (state.thumb !== null && state.requested) live.current.onSlidingComplete?.(state.requested)\n      })\n      .onFinalize(() => {\n        drag.current = { thumb: null, offset: 0, requested: null, startX: 0 }\n      })\n\n    function adjust(thumb: Thumb, direction: 1 | -1) {\n      if (!adjustable) return\n      const delta = scale.step || span / 100\n      const next = move(thumb, current[thumb] + direction * delta)\n      if (request(next)) onSlidingComplete?.(next)\n    }\n\n    const fillStart = position(current[0])\n    const fillEnd = position(current[1])\n    return (\n      <GestureHandlerRootView style={{ flexGrow: 0, flexShrink: 0 }}>\n        <GestureDetector gesture={pan}>\n          <View\n            {...props}\n            ref={ref}\n            className={cn('h-[48px] w-full justify-center', disabled && 'opacity-50', className)}\n            onLayout={(event: LayoutChangeEvent) => {\n              setWidth(Math.max(0, event.nativeEvent.layout.width))\n              props.onLayout?.(event)\n            }}\n          >\n            <View\n              pointerEvents=\"none\"\n              className=\"absolute h-[4px] rounded-full bg-input\"\n              style={{ start: HALF, end: HALF }}\n            />\n            <View\n              pointerEvents=\"none\"\n              className=\"absolute h-[4px] rounded-full bg-primary\"\n              style={{ start: fillStart, width: Math.max(0, fillEnd - fillStart) }}\n            />\n            {([0, 1] as const).map((thumb) => (\n              <View\n                key={thumb}\n                accessible\n                accessibilityRole=\"adjustable\"\n                accessibilityLabel={thumbLabels[thumb]}\n                accessibilityState={{ disabled: !adjustable }}\n                accessibilityValue={accessibleValue(\n                  thumb === 0 ? scale.min : current[0],\n                  thumb === 0 ? current[1] : scale.max,\n                  current[thumb],\n                )}\n                accessibilityActions={[{ name: 'increment' }, { name: 'decrement' }]}\n                onAccessibilityAction={(event) => {\n                  if (event.nativeEvent.actionName === 'increment') adjust(thumb, 1)\n                  else if (event.nativeEvent.actionName === 'decrement') adjust(thumb, -1)\n                }}\n                className=\"absolute top-0 size-[48px] items-center justify-center\"\n                style={{ start: position(current[thumb]) - HALF }}\n              >\n                <View\n                  pointerEvents=\"none\"\n                  className=\"size-[24px] rounded-full border-2 border-background bg-primary shadow-sm\"\n                />\n              </View>\n            ))}\n          </View>\n        </GestureDetector>\n      </GestureHandlerRootView>\n    )\n  },\n)\nRangeSlider.displayName = 'RangeSlider'\n",
      "type": "registry:ui",
      "target": "~/components/ui/range-slider/RangeSlider.tsx"
    },
    {
      "path": "packages/registry-native/components/range-slider/index.ts",
      "content": "export { RangeSlider, type RangeSliderProps, type RangeValue } from './RangeSlider'\n",
      "type": "registry:ui",
      "target": "~/components/ui/range-slider/index.ts"
    }
  ],
  "dependencies": [
    "react-native-gesture-handler"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/utils.json"
  ],
  "description": "Dual-thumb bounded range slider with stepped values, controlled refusal, and adjustable thumbs.",
  "categories": [
    "control"
  ]
}