|
| 1 | +export const metadata = { title: "@json-render/react-native API" } |
| 2 | + |
| 3 | +# @json-render/react-native |
| 4 | + |
| 5 | +React Native renderer with standard components, providers, and hooks. |
| 6 | + |
| 7 | +## Standard Components |
| 8 | + |
| 9 | +### Layout |
| 10 | + |
| 11 | +| Component | Props | Description | |
| 12 | +|-----------|-------|-------------| |
| 13 | +| `Container` | `padding`, `background`, `borderRadius`, `borderColor`, `flex` | Basic wrapper with styling | |
| 14 | +| `Row` | `gap`, `align`, `justify`, `flex`, `wrap` | Horizontal flex layout | |
| 15 | +| `Column` | `gap`, `align`, `justify`, `flex` | Vertical flex layout | |
| 16 | +| `ScrollContainer` | `direction` | Scrollable area (vertical or horizontal) | |
| 17 | +| `SafeArea` | `edges` | Safe area insets for notch/home indicator | |
| 18 | +| `Pressable` | `action`, `actionParams` | Touchable wrapper that triggers actions | |
| 19 | +| `Spacer` | `size`, `flex` | Fixed or flexible spacing | |
| 20 | +| `Divider` | `color`, `thickness` | Thin line separator | |
| 21 | + |
| 22 | +### Content |
| 23 | + |
| 24 | +| Component | Props | Description | |
| 25 | +|-----------|-------|-------------| |
| 26 | +| `Heading` | `text`, `level`, `align`, `color` | Heading text (levels 1-6) | |
| 27 | +| `Paragraph` | `text`, `align`, `color` | Body text | |
| 28 | +| `Label` | `text`, `color`, `bold` | Small label text | |
| 29 | +| `Image` | `uri`, `width`, `height`, `resizeMode`, `borderRadius` | Image display | |
| 30 | +| `Avatar` | `uri`, `size`, `fallback` | Circular avatar | |
| 31 | +| `Badge` | `label`, `color`, `textColor` | Status badge | |
| 32 | +| `Chip` | `label`, `selected`, `color` | Tag/chip | |
| 33 | + |
| 34 | +### Input |
| 35 | + |
| 36 | +| Component | Props | Description | |
| 37 | +|-----------|-------|-------------| |
| 38 | +| `Button` | `label`, `variant`, `size`, `disabled`, `action`, `actionParams` | Pressable button | |
| 39 | +| `TextInput` | `placeholder`, `statePath`, `secure`, `keyboardType`, `multiline` | Text input field | |
| 40 | +| `Switch` | `statePath`, `label` | Toggle switch | |
| 41 | +| `Checkbox` | `statePath`, `label` | Checkbox with label | |
| 42 | +| `Slider` | `statePath`, `min`, `max`, `step` | Range slider | |
| 43 | +| `SearchBar` | `placeholder`, `statePath` | Search input | |
| 44 | + |
| 45 | +### Feedback |
| 46 | + |
| 47 | +| Component | Props | Description | |
| 48 | +|-----------|-------|-------------| |
| 49 | +| `Spinner` | `size`, `color` | Loading indicator | |
| 50 | +| `ProgressBar` | `progress`, `color`, `trackColor` | Progress indicator | |
| 51 | + |
| 52 | +### Composite |
| 53 | + |
| 54 | +| Component | Props | Description | |
| 55 | +|-----------|-------|-------------| |
| 56 | +| `Card` | `title`, `subtitle`, `padding` | Card container | |
| 57 | +| `ListItem` | `title`, `subtitle`, `leading`, `trailing`, `action`, `actionParams` | List row | |
| 58 | +| `Modal` | `visible`, `title` | Bottom sheet modal | |
| 59 | + |
| 60 | +## Providers |
| 61 | + |
| 62 | +### StateProvider |
| 63 | + |
| 64 | +```tsx |
| 65 | +<StateProvider initialState={object}> |
| 66 | + {children} |
| 67 | +</StateProvider> |
| 68 | +``` |
| 69 | + |
| 70 | +### ActionProvider |
| 71 | + |
| 72 | +```tsx |
| 73 | +<ActionProvider handlers={Record<string, ActionHandler>}> |
| 74 | + {children} |
| 75 | +</ActionProvider> |
| 76 | +``` |
| 77 | + |
| 78 | +### VisibilityProvider |
| 79 | + |
| 80 | +```tsx |
| 81 | +<VisibilityProvider> |
| 82 | + {children} |
| 83 | +</VisibilityProvider> |
| 84 | +``` |
| 85 | + |
| 86 | +### ValidationProvider |
| 87 | + |
| 88 | +```tsx |
| 89 | +<ValidationProvider> |
| 90 | + {children} |
| 91 | +</ValidationProvider> |
| 92 | +``` |
| 93 | + |
| 94 | +## defineRegistry |
| 95 | + |
| 96 | +Create a type-safe component registry. Standard components are built-in -- only register custom components. |
| 97 | + |
| 98 | +```tsx |
| 99 | +import { defineRegistry, type Components } from '@json-render/react-native'; |
| 100 | + |
| 101 | +const { registry } = defineRegistry(catalog, { |
| 102 | + components: { |
| 103 | + Icon: ({ props }) => <Ionicons name={props.name} size={props.size ?? 24} />, |
| 104 | + } as Components<typeof catalog>, |
| 105 | +}); |
| 106 | +``` |
| 107 | + |
| 108 | +## Hooks |
| 109 | + |
| 110 | +### useUIStream |
| 111 | + |
| 112 | +```typescript |
| 113 | +const { |
| 114 | + spec, // Spec | null - current UI state |
| 115 | + isStreaming, // boolean - true while streaming |
| 116 | + error, // Error | null |
| 117 | + send, // (prompt: string) => Promise<void> |
| 118 | + clear, // () => void - reset spec and error |
| 119 | +} = useUIStream({ |
| 120 | + api: string, |
| 121 | + onComplete?: (spec: Spec) => void, |
| 122 | + onError?: (error: Error) => void, |
| 123 | +}); |
| 124 | +``` |
| 125 | + |
| 126 | +### useStateStore |
| 127 | + |
| 128 | +```typescript |
| 129 | +const { state, get, set, update } = useStateStore(); |
| 130 | +``` |
| 131 | + |
| 132 | +### useStateValue |
| 133 | + |
| 134 | +```typescript |
| 135 | +const value = useStateValue(path: string); |
| 136 | +``` |
| 137 | + |
| 138 | +### useStateBinding |
| 139 | + |
| 140 | +```typescript |
| 141 | +const [value, setValue] = useStateBinding(path: string); |
| 142 | +``` |
| 143 | + |
| 144 | +### useActions |
| 145 | + |
| 146 | +```typescript |
| 147 | +const { execute } = useActions(); |
| 148 | +``` |
| 149 | + |
| 150 | +### useIsVisible |
| 151 | + |
| 152 | +```typescript |
| 153 | +const isVisible = useIsVisible(condition?: VisibilityCondition); |
| 154 | +``` |
| 155 | + |
| 156 | +## Catalog Exports |
| 157 | + |
| 158 | +```typescript |
| 159 | +import { standardComponentDefinitions, standardActionDefinitions } from "@json-render/react-native/catalog"; |
| 160 | +import { schema } from "@json-render/react-native/schema"; |
| 161 | +``` |
| 162 | + |
| 163 | +| Export | Purpose | |
| 164 | +|--------|---------| |
| 165 | +| `standardComponentDefinitions` | Catalog definitions for all 25+ standard components | |
| 166 | +| `standardActionDefinitions` | Catalog definitions for standard actions (setState, navigate) | |
| 167 | +| `schema` | React Native element tree schema | |
0 commit comments