page.mdx 4.9 KB

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