{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "message-composer",
  "title": "Message Composer",
  "type": "registry:ui",
  "files": [
    {
      "path": "packages/registry-native/components/message-composer/MessageComposer.tsx",
      "content": "import * as React from 'react'\nimport { TextInput, View, type ViewProps } from 'react-native'\nimport { Button } from '@/components/ui/button'\nimport { Text } from '@/components/ui/text'\nimport { Textarea, type TextareaProps } from '@/components/ui/textarea'\nimport { useAnnouncement } from '@/lib/accessibility'\nimport { cn } from '@/lib/utils'\n\nconst defaultLabels = {\n  input: 'Message',\n  placeholder: 'Write a message',\n  attach: 'Add attachment',\n  send: 'Send message',\n  sending: 'Sending…',\n  failed: 'Message could not be sent. Your draft is still here.',\n}\n\nexport interface MessageComposerProps extends Omit<ViewProps, 'children'> {\n  className?: string\n  value: string\n  onChangeText: (value: string) => void\n  /** Return false or reject to keep the draft and offer a retry. */\n  onSend: (message: string) => void | boolean | Promise<void | boolean>\n  onAttach?: () => void\n  attachment?: (state: { disabled: boolean }) => React.ReactNode\n  /** Enable this for an attachment that can be sent without text. */\n  allowEmptyMessage?: boolean\n  disabled?: boolean\n  inputProps?: Omit<\n    TextareaProps,\n    'value' | 'defaultValue' | 'onChangeText' | 'editable' | 'readOnly' | 'submitBehavior' | 'onSubmitEditing'\n  >\n  labels?: Partial<typeof defaultLabels>\n}\n\nfunction SendFailure({ message }: { message: string }) {\n  useAnnouncement(message)\n  return (\n    <Text size=\"sm\" className=\"text-destructive\">\n      {message}\n    </Text>\n  )\n}\n\nexport const MessageComposer = React.forwardRef<React.ComponentRef<typeof TextInput>, MessageComposerProps>(\n  (\n    {\n      className,\n      value,\n      onChangeText,\n      onSend,\n      onAttach,\n      attachment,\n      allowEmptyMessage = false,\n      disabled = false,\n      inputProps,\n      labels,\n      ...props\n    },\n    ref,\n  ) => {\n    const copy = { ...defaultLabels, ...labels }\n    const [sending, setSending] = React.useState(false)\n    const [failure, setFailure] = React.useState<{ attempt: number; draft: string }>()\n    const request = React.useRef({ attempt: 0, pending: false })\n    const active = React.useRef(false)\n    const latest = React.useRef({ value, onChangeText })\n    React.useLayoutEffect(() => {\n      latest.current = { value, onChangeText }\n    }, [value, onChangeText])\n    React.useLayoutEffect(() => {\n      active.current = true\n      return () => {\n        active.current = false\n      }\n    }, [])\n\n    const blocked = disabled || sending\n    const canSend = allowEmptyMessage || value.trim() !== ''\n    const action = sending ? copy.sending : copy.send\n\n    async function send() {\n      const draft = latest.current.value\n      const message = draft.trim()\n      if (blocked || request.current.pending || (!allowEmptyMessage && !message)) return\n      const attempt = ++request.current.attempt\n      request.current.pending = true\n      setSending(true)\n      setFailure(undefined)\n      try {\n        const accepted = (await onSend(message)) !== false\n        if (!active.current) return\n        if (!accepted) {\n          setFailure({ attempt, draft })\n        } else if (latest.current.value === draft) {\n          latest.current.onChangeText('')\n        }\n      } catch {\n        if (active.current) setFailure({ attempt, draft })\n      } finally {\n        request.current.pending = false\n        if (active.current) setSending(false)\n      }\n    }\n\n    return (\n      <View {...props} className={cn('gap-2', className)}>\n        <Textarea\n          ref={ref}\n          accessibilityLabel={copy.input}\n          placeholder={copy.placeholder}\n          returnKeyType=\"default\"\n          {...inputProps}\n          className={cn('max-h-[168px] min-h-[72px]', inputProps?.className)}\n          editable={!blocked}\n          value={value}\n          submitBehavior=\"newline\"\n          onChangeText={(draft) => {\n            if (blocked || request.current.pending) return\n            setFailure(undefined)\n            onChangeText(draft)\n          }}\n        />\n        {attachment?.({ disabled: blocked })}\n        {failure?.draft === value ? <SendFailure key={failure.attempt} message={copy.failed} /> : null}\n        <View className={cn('flex-row flex-wrap items-center gap-2', onAttach ? 'justify-between' : 'justify-end')}>\n          {onAttach ? (\n            <Button\n              accessibilityLabel={copy.attach}\n              variant=\"outline\"\n              disabled={blocked}\n              onPress={() => {\n                if (!blocked && !request.current.pending) onAttach()\n              }}\n            >\n              {copy.attach}\n            </Button>\n          ) : null}\n          <Button accessibilityLabel={action} disabled={!canSend || disabled} loading={sending} onPress={send}>\n            {action}\n          </Button>\n        </View>\n      </View>\n    )\n  },\n)\nMessageComposer.displayName = 'MessageComposer'\n",
      "type": "registry:ui",
      "target": "~/components/ui/message-composer/MessageComposer.tsx"
    },
    {
      "path": "packages/registry-native/components/message-composer/index.ts",
      "content": "export { MessageComposer, type MessageComposerProps } from './MessageComposer'\n",
      "type": "registry:ui",
      "target": "~/components/ui/message-composer/index.ts"
    }
  ],
  "dependencies": [],
  "devDependencies": [],
  "registryDependencies": [
    "https://native.uipkge.dev/r/native/accessibility.json",
    "https://native.uipkge.dev/r/native/button.json",
    "https://native.uipkge.dev/r/native/text.json",
    "https://native.uipkge.dev/r/native/textarea.json"
  ],
  "description": "A native multiline composer with optional attachment controls and draft retention after a failed send.",
  "categories": [
    "input",
    "messaging"
  ]
}