| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- import { pageMetadata } from "@/lib/page-metadata"
- export const metadata = pageMetadata("docs/api/react-native")
- # @json-render/react-native
- React Native renderer with standard components, providers, and hooks.
- ## Standard Components
- ### Layout
- <table>
- <thead>
- <tr><th>Component</th><th>Props</th><th>Description</th></tr>
- </thead>
- <tbody>
- <tr><td><code>Container</code></td><td><code>padding</code>, <code>background</code>, <code>borderRadius</code>, <code>borderColor</code>, <code>flex</code></td><td>Basic wrapper with styling</td></tr>
- <tr><td><code>Row</code></td><td><code>gap</code>, <code>align</code>, <code>justify</code>, <code>flex</code>, <code>wrap</code></td><td>Horizontal flex layout</td></tr>
- <tr><td><code>Column</code></td><td><code>gap</code>, <code>align</code>, <code>justify</code>, <code>flex</code></td><td>Vertical flex layout</td></tr>
- <tr><td><code>ScrollContainer</code></td><td><code>direction</code></td><td>Scrollable area (vertical or horizontal)</td></tr>
- <tr><td><code>SafeArea</code></td><td><code>edges</code></td><td>Safe area insets for notch/home indicator</td></tr>
- <tr><td><code>Pressable</code></td><td><code>action</code>, <code>actionParams</code></td><td>Touchable wrapper that triggers actions</td></tr>
- <tr><td><code>Spacer</code></td><td><code>size</code>, <code>flex</code></td><td>Fixed or flexible spacing</td></tr>
- <tr><td><code>Divider</code></td><td><code>color</code>, <code>thickness</code></td><td>Thin line separator</td></tr>
- </tbody>
- </table>
- ### Content
- <table>
- <thead>
- <tr><th>Component</th><th>Props</th><th>Description</th></tr>
- </thead>
- <tbody>
- <tr><td><code>Heading</code></td><td><code>text</code>, <code>level</code>, <code>align</code>, <code>color</code></td><td>Heading text (levels 1-6)</td></tr>
- <tr><td><code>Paragraph</code></td><td><code>text</code>, <code>align</code>, <code>color</code></td><td>Body text</td></tr>
- <tr><td><code>Label</code></td><td><code>text</code>, <code>color</code>, <code>bold</code></td><td>Small label text</td></tr>
- <tr><td><code>Image</code></td><td><code>uri</code>, <code>width</code>, <code>height</code>, <code>resizeMode</code>, <code>borderRadius</code></td><td>Image display</td></tr>
- <tr><td><code>Avatar</code></td><td><code>uri</code>, <code>size</code>, <code>fallback</code></td><td>Circular avatar</td></tr>
- <tr><td><code>Badge</code></td><td><code>label</code>, <code>color</code>, <code>textColor</code></td><td>Status badge</td></tr>
- <tr><td><code>Chip</code></td><td><code>label</code>, <code>selected</code>, <code>color</code></td><td>Tag/chip</td></tr>
- </tbody>
- </table>
- ### Input
- <table>
- <thead>
- <tr><th>Component</th><th>Props</th><th>Description</th></tr>
- </thead>
- <tbody>
- <tr><td><code>Button</code></td><td><code>label</code>, <code>variant</code>, <code>size</code>, <code>disabled</code>, <code>action</code>, <code>actionParams</code></td><td>Pressable button</td></tr>
- <tr><td><code>TextInput</code></td><td><code>placeholder</code>, <code>value</code> (use <code>$bindState</code>), <code>secure</code>, <code>keyboardType</code>, <code>multiline</code></td><td>Text input field</td></tr>
- <tr><td><code>Switch</code></td><td><code>checked</code> (use <code>$bindState</code>), <code>label</code></td><td>Toggle switch</td></tr>
- <tr><td><code>Checkbox</code></td><td><code>checked</code> (use <code>$bindState</code>), <code>label</code></td><td>Checkbox with label</td></tr>
- <tr><td><code>Slider</code></td><td><code>value</code> (use <code>$bindState</code>), <code>min</code>, <code>max</code>, <code>step</code></td><td>Range slider</td></tr>
- <tr><td><code>SearchBar</code></td><td><code>placeholder</code>, <code>value</code> (use <code>$bindState</code>)</td><td>Search input</td></tr>
- </tbody>
- </table>
- ### Feedback
- <table>
- <thead>
- <tr><th>Component</th><th>Props</th><th>Description</th></tr>
- </thead>
- <tbody>
- <tr><td><code>Spinner</code></td><td><code>size</code>, <code>color</code></td><td>Loading indicator</td></tr>
- <tr><td><code>ProgressBar</code></td><td><code>progress</code>, <code>color</code>, <code>trackColor</code></td><td>Progress indicator</td></tr>
- </tbody>
- </table>
- ### Composite
- <table>
- <thead>
- <tr><th>Component</th><th>Props</th><th>Description</th></tr>
- </thead>
- <tbody>
- <tr><td><code>Card</code></td><td><code>title</code>, <code>subtitle</code>, <code>padding</code></td><td>Card container</td></tr>
- <tr><td><code>ListItem</code></td><td><code>title</code>, <code>subtitle</code>, <code>leading</code>, <code>trailing</code>, <code>action</code>, <code>actionParams</code></td><td>List row</td></tr>
- <tr><td><code>Modal</code></td><td><code>visible</code>, <code>title</code></td><td>Bottom sheet modal</td></tr>
- </tbody>
- </table>
- ## Providers
- ### StateProvider
- ```tsx
- <StateProvider initialState={object} onStateChange={fn}>
- {children}
- </StateProvider>
- ```
- <table>
- <thead>
- <tr><th>Prop</th><th>Type</th><th>Description</th></tr>
- </thead>
- <tbody>
- <tr><td><code>store</code></td><td><code>StateStore</code></td><td>External store (controlled mode). When provided, <code>initialState</code> and <code>onStateChange</code> are ignored.</td></tr>
- <tr><td><code>initialState</code></td><td><code>Record<string, unknown></code></td><td>Initial state model (uncontrolled mode).</td></tr>
- <tr><td><code>onStateChange</code></td><td><code>{'(changes: Array<{ path: string; value: unknown }>) => void'}</code></td><td>Callback when state changes (uncontrolled mode). Called once per <code>set</code> or <code>update</code> with all changed entries.</td></tr>
- </tbody>
- </table>
- #### External Store (Controlled Mode)
- Pass a `StateStore` to bypass the internal state and wire json-render to any state management library:
- ```tsx
- import { createStateStore, type StateStore } from "@json-render/react-native";
- const store = createStateStore({ count: 0 });
- <StateProvider store={store}>
- {children}
- </StateProvider>
- // Mutate from anywhere — components re-render automatically:
- store.set("/count", 1);
- ```
- The `store` prop is also available on `JSONUIProvider` and `createRenderer`.
- ### ActionProvider
- ```tsx
- <ActionProvider handlers={Record<string, ActionHandler>}>
- {children}
- </ActionProvider>
- ```
- ### VisibilityProvider
- ```tsx
- <VisibilityProvider>
- {children}
- </VisibilityProvider>
- ```
- Conditions in specs use the `VisibilityCondition` format with `$state` paths (e.g. `{ "$state": "/path" }`, `{ "$state": "/path", "eq": value }`). See [visibility](/docs/visibility) for the full syntax.
- ### ValidationProvider
- ```tsx
- <ValidationProvider>
- {children}
- </ValidationProvider>
- ```
- ## defineRegistry
- Create a type-safe component registry. Standard components are built-in; only register custom components.
- ```tsx
- import { defineRegistry, type Components } from '@json-render/react-native';
- const { registry } = defineRegistry(catalog, {
- components: {
- Icon: ({ props }) => <Ionicons name={props.name} size={props.size ?? 24} />,
- } as Components<typeof catalog>,
- });
- ```
- ## Hooks
- ### useUIStream
- ```typescript
- const {
- spec, // Spec | null - current UI state
- isStreaming, // boolean - true while streaming
- error, // Error | null
- send, // (prompt: string) => Promise<void>
- clear, // () => void - reset spec and error
- } = useUIStream({
- api: string,
- onComplete?: (spec: Spec) => void,
- onError?: (error: Error) => void,
- });
- ```
- ### useStateStore
- ```typescript
- const { state, get, set, update } = useStateStore();
- ```
- ### useStateValue
- ```typescript
- const value = useStateValue(path: string);
- ```
- ### useStateBinding (deprecated)
- > **Deprecated.** Use `useBoundProp` with `$bindState` expressions instead.
- ```typescript
- const [value, setValue] = useStateBinding(path: string);
- ```
- ### useActions
- ```typescript
- const { execute } = useActions();
- ```
- ### useIsVisible
- ```typescript
- const isVisible = useIsVisible(condition?: VisibilityCondition);
- ```
- ## Catalog Exports
- ```typescript
- import { standardComponentDefinitions, standardActionDefinitions } from "@json-render/react-native/catalog";
- import { schema } from "@json-render/react-native/schema";
- ```
- <table>
- <thead>
- <tr><th>Export</th><th>Purpose</th></tr>
- </thead>
- <tbody>
- <tr><td><code>standardComponentDefinitions</code></td><td>Catalog definitions for all 25+ standard components</td></tr>
- <tr><td><code>standardActionDefinitions</code></td><td>Catalog definitions for standard actions (setState, navigate)</td></tr>
- <tr><td><code>schema</code></td><td>React Native element tree schema</td></tr>
- </tbody>
- </table>
|