aix 0.7.1-alpha.9 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +26 -43
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -5,6 +5,7 @@ alt="aix" width="1600" height="900" />
5
5
 
6
6
  UI Primitives for building AI apps in React Native.
7
7
 
8
+ > [!WARNING]
8
9
  > aix is currently in alpha preview. The API is likely to change.
9
10
 
10
11
  ## Features
@@ -121,27 +122,35 @@ export function ChatScreen({ messages }) {
121
122
  ### Send a message
122
123
 
123
124
  When sending a message, you will likely want to scroll to it after it gets added
124
- to the list.
125
-
126
- Simply call `aix.current?.scrollToIndexWhenBlankSizeReady(index)` in your submit
127
- handler.
125
+ to the list. Use the `scrollToIndex` prop to declaratively trigger an animated
126
+ scroll, and `onDidScrollToIndex` to reset the state when the scroll completes.
128
127
 
129
128
  The `index` you pass should correspond to the newest message in the list. For AI
130
- chats, this is typically the next assistant message index.
129
+ chats, this is typically the next assistant message index. Use a nullish value (`null | undefined`) to indicate
130
+ no scroll target.
131
131
 
132
132
  ```tsx
133
133
  import { Keyboard } from 'react-native'
134
- import { useAixRef } from 'aix'
134
+ import { useState } from 'react'
135
135
 
136
136
  function Chat() {
137
- const aix = useAixRef()
137
+ const [scrollToIndex, setScrollToIndex] = useState<number | null>(null)
138
138
 
139
139
  const onSubmit = () => {
140
- aix.current?.scrollToIndexWhenBlankSizeReady(messages.length + 1, true)
140
+ const newMessageIndex = messages.length + 1
141
+ setScrollToIndex(newMessageIndex)
142
+ sendMessage(message)
141
143
  requestAnimationFrame(Keyboard.dismiss)
142
144
  }
143
145
 
144
- return <Aix ref={aix}>{/* ... */}</Aix>
146
+ return (
147
+ <Aix
148
+ scrollToIndex={scrollToIndex}
149
+ onDidScrollToIndex={() => setScrollToIndex(null)}
150
+ >
151
+ {/* ... */}
152
+ </Aix>
153
+ )
145
154
  }
146
155
  ```
147
156
 
@@ -197,6 +206,8 @@ scrolling for chat interfaces.
197
206
  | `additionalScrollIndicatorInsets` | `object` | - | Additional insets for the scroll indicator, added to existing safe area insets. Applied to `verticalScrollIndicatorInsets` on iOS. |
198
207
  | `mainScrollViewID` | `string` | - | The `nativeID` of the scroll view to use. If provided, will search for a scroll view with this `accessibilityIdentifier`. |
199
208
  | `penultimateCellIndex` | `number` | - | The index of the second-to-last message (typically the last user message in AI chat apps). Used to determine which message will be scrolled into view. Useful when you have custom message types like timestamps in your list. |
209
+ | `scrollToIndex` | `number` | - | When set, triggers an animated scroll to this cell index. Use a nullish value (`null` or `undefined`) to indicate no scroll target. After the scroll completes, `onDidScrollToIndex` is called. Reset after receiving the callback. |
210
+ | `onDidScrollToIndex` | `() => void` | - | Called when the animated scroll to `scrollToIndex` completes. Use this to clear the `scrollToIndex` state. |
200
211
 
201
212
  #### Ref Methods
202
213
 
@@ -207,19 +218,14 @@ const aix = useAixRef()
207
218
 
208
219
  // Scroll to the end of the content
209
220
  aix.current?.scrollToEnd(animated)
210
-
211
- // Scroll to a specific index when the blank size is ready
212
- aix.current?.scrollToIndexWhenBlankSizeReady(
213
- index,
214
- animated,
215
- waitForKeyboardToEnd
216
- )
217
221
  ```
218
222
 
219
- | Method | Parameters | Description |
220
- | --------------------------------- | ------------------------------------------------------------------- | -------------------------------------------------------------------------- |
221
- | `scrollToEnd` | `animated?: boolean` | Scrolls to the end of the content. |
222
- | `scrollToIndexWhenBlankSizeReady` | `index: number, animated?: boolean, waitForKeyboardToEnd?: boolean` | Scrolls to a specific cell index once the blank size calculation is ready. |
223
+ | Method | Parameters | Description |
224
+ | ------------- | -------------------- | ---------------------------------- |
225
+ | `scrollToEnd` | `animated?: boolean` | Scrolls to the end of the content. |
226
+
227
+ > **Note:** For scrolling to a specific message index, prefer using the
228
+ > declarative `scrollToIndex` prop instead of imperative methods.
223
229
 
224
230
  ---
225
231
 
@@ -258,31 +264,8 @@ Accepts all standard React Native `View` props.
258
264
  <Composer />
259
265
  </AixFooter>
260
266
  ```
261
-
262
267
  ---
263
268
 
264
- ### `useAixRef`
265
-
266
- A hook that returns a ref to access imperative methods on the `Aix` component.
267
-
268
- ```tsx
269
- import { useAixRef } from 'aix'
270
-
271
- function Chat({ messages }) {
272
- const aix = useAixRef()
273
- const send = useSendMessage()
274
-
275
- const handleSend = () => {
276
- // Scroll to end after sending a message
277
- send(message)
278
- aix.current?.scrollToIndexWhenBlankSizeReady(messages.length + 1, true)
279
- requestAnimationFrame(Keyboard.dismiss)
280
- }
281
-
282
- return <Aix ref={aix}>{/* ... */}</Aix>
283
- }
284
- ```
285
-
286
269
  ### Rules
287
270
 
288
271
  - Do **NOT** apply padding to `contentContainerStyle`. Instead, use padding on
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aix",
3
- "version": "0.7.1-alpha.9",
3
+ "version": "0.8.0",
4
4
  "author": "Fernando Rojo",
5
5
  "repository": {
6
6
  "type": "git",