@vvedantb/native-ui 0.25.1 → 0.25.2
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.
- package/dist/ai/conversation-context.js +27 -0
- package/dist/ai/conversation.jsx +62 -52
- package/dist/ai/message-context-menu.jsx +414 -329
- package/dist/ai/message.jsx +92 -74
- package/dist/primitives/keyboard-controller.jsx +32 -26
- package/package.json +1 -1
- package/src/ai/conversation-context.ts +56 -0
- package/src/ai/conversation.tsx +12 -42
- package/src/ai/message-context-menu.tsx +76 -32
- package/src/ai/message.tsx +10 -1
- package/src/primitives/keyboard-controller.tsx +3 -0
- package/src/primitives/keyboard-parts.tsx +3 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
|
|
3
|
+
// The `Conversation` context on its own, so a message can reach it without the
|
|
4
|
+
// thread's components (`message.tsx` sets `overlay`).
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* What the thread scrolls with: the `ScrollView` of `ConversationContent` or
|
|
8
|
+
* the `FlatList` of `ConversationList`. `scrollToEnd` goes to the newest
|
|
9
|
+
* message, which is offset 0 in an inverted list. `scrollTo` goes to an
|
|
10
|
+
* offset; only the `ScrollView` has it, so call it as `scrollTo?.(...)`.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const ConversationContext = createContext(null);
|
|
14
|
+
|
|
15
|
+
/** `isAtBottom` and `scrollToBottom` of the enclosing `Conversation`, for a custom scroll button. */
|
|
16
|
+
export function useConversation() {
|
|
17
|
+
const context = useContext(ConversationContext);
|
|
18
|
+
if (!context) {
|
|
19
|
+
throw new Error("Conversation parts must be used within Conversation");
|
|
20
|
+
}
|
|
21
|
+
return context;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The enclosing `Conversation`, or null for a message drawn outside one. */
|
|
25
|
+
export function useOptionalConversation() {
|
|
26
|
+
return useContext(ConversationContext);
|
|
27
|
+
}
|
package/dist/ai/conversation.jsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { isValidElement, useRef, useState } from "react";
|
|
3
3
|
import { FlatList, Platform, Pressable, ScrollView, StyleSheet, Text, View } from "react-native";
|
|
4
4
|
import { IconArrowDown } from "@tabler/icons-react-native";
|
|
5
5
|
import { FadeIn, FadeOut } from "react-native-reanimated";
|
|
@@ -16,6 +16,7 @@ import { tokens } from "../tokens";
|
|
|
16
16
|
import { useReduceMotion } from "../useReduceMotion";
|
|
17
17
|
import { useScheme } from "../useScheme";
|
|
18
18
|
import { chatTextSize } from "./chat-text";
|
|
19
|
+
import { ConversationContext, useConversation } from "./conversation-context";
|
|
19
20
|
|
|
20
21
|
/** Within this many points of the end, the thread counts as at the bottom and keeps following new content. */
|
|
21
22
|
export const AT_BOTTOM_THRESHOLD = 70;
|
|
@@ -36,31 +37,14 @@ export function isScrolledToBottom({
|
|
|
36
37
|
if (inverted) return contentOffset.y + bottomInset <= AT_BOTTOM_THRESHOLD;
|
|
37
38
|
return contentSize.height + bottomInset - layoutMeasurement.height - contentOffset.y <= AT_BOTTOM_THRESHOLD;
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* What the thread scrolls with: the `ScrollView` of `ConversationContent` or
|
|
42
|
-
* the `FlatList` of `ConversationList`. `scrollToEnd` goes to the newest
|
|
43
|
-
* message, which is offset 0 in an inverted list. `scrollTo` goes to an
|
|
44
|
-
* offset; only the `ScrollView` has it, so call it as `scrollTo?.(...)`.
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
const ConversationContext = createContext(null);
|
|
48
|
-
|
|
49
|
-
/** `isAtBottom` and `scrollToBottom` of the enclosing `Conversation`, for a custom scroll button. */
|
|
50
|
-
export function useConversation() {
|
|
51
|
-
const context = useContext(ConversationContext);
|
|
52
|
-
if (!context) {
|
|
53
|
-
throw new Error("Conversation parts must be used within Conversation");
|
|
54
|
-
}
|
|
55
|
-
return context;
|
|
56
|
-
}
|
|
40
|
+
export { useConversation, useOptionalConversation } from "./conversation-context";
|
|
57
41
|
/**
|
|
58
42
|
* The thread frame (web `relative flex-1`). It sticks to the bottom: while the
|
|
59
43
|
* reader is at the end, new and growing messages stay in view; once they
|
|
60
44
|
* scroll up, it stops following and `ConversationScrollButton` shows.
|
|
61
45
|
*/
|
|
62
46
|
export function Conversation(t0) {
|
|
63
|
-
const $ = _c(
|
|
47
|
+
const $ = _c(25);
|
|
64
48
|
let className;
|
|
65
49
|
let props;
|
|
66
50
|
if ($[0] !== t0) {
|
|
@@ -81,6 +65,7 @@ export function Conversation(t0) {
|
|
|
81
65
|
const autoScrolling = useRef(false);
|
|
82
66
|
const [isAtBottom, setIsAtBottom] = useState(true);
|
|
83
67
|
const [dockHeight, setDockHeight] = useState(0);
|
|
68
|
+
const [overlay, setOverlay] = useState("none");
|
|
84
69
|
let t1;
|
|
85
70
|
if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
|
|
86
71
|
t1 = next => {
|
|
@@ -140,8 +125,23 @@ export function Conversation(t0) {
|
|
|
140
125
|
t5 = $[8];
|
|
141
126
|
}
|
|
142
127
|
let t6;
|
|
143
|
-
|
|
144
|
-
|
|
128
|
+
let t7;
|
|
129
|
+
let t8;
|
|
130
|
+
if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
|
|
131
|
+
t6 = () => setOverlay("open");
|
|
132
|
+
t7 = () => setOverlay("closing");
|
|
133
|
+
t8 = () => setOverlay(_temp);
|
|
134
|
+
$[9] = t6;
|
|
135
|
+
$[10] = t7;
|
|
136
|
+
$[11] = t8;
|
|
137
|
+
} else {
|
|
138
|
+
t6 = $[9];
|
|
139
|
+
t7 = $[10];
|
|
140
|
+
t8 = $[11];
|
|
141
|
+
}
|
|
142
|
+
let t9;
|
|
143
|
+
if ($[12] !== dockHeight || $[13] !== isAtBottom || $[14] !== overlay || $[15] !== t2) {
|
|
144
|
+
t9 = {
|
|
145
145
|
isAtBottom,
|
|
146
146
|
scrollRef,
|
|
147
147
|
scrollToBottom: t2,
|
|
@@ -149,47 +149,54 @@ export function Conversation(t0) {
|
|
|
149
149
|
onUserScroll: t4,
|
|
150
150
|
followContent: t5,
|
|
151
151
|
dockHeight,
|
|
152
|
-
setDockHeight
|
|
152
|
+
setDockHeight,
|
|
153
|
+
overlay,
|
|
154
|
+
openOverlay: t6,
|
|
155
|
+
closeOverlay: t7,
|
|
156
|
+
settleOverlay: t8
|
|
153
157
|
};
|
|
154
|
-
$[
|
|
155
|
-
$[
|
|
156
|
-
$[
|
|
157
|
-
$[
|
|
158
|
+
$[12] = dockHeight;
|
|
159
|
+
$[13] = isAtBottom;
|
|
160
|
+
$[14] = overlay;
|
|
161
|
+
$[15] = t2;
|
|
162
|
+
$[16] = t9;
|
|
158
163
|
} else {
|
|
159
|
-
|
|
164
|
+
t9 = $[16];
|
|
160
165
|
}
|
|
161
|
-
const value =
|
|
162
|
-
let
|
|
163
|
-
if ($[
|
|
164
|
-
|
|
165
|
-
$[
|
|
166
|
-
$[
|
|
166
|
+
const value = t9;
|
|
167
|
+
let t10;
|
|
168
|
+
if ($[17] !== className) {
|
|
169
|
+
t10 = cn("relative flex-1", className);
|
|
170
|
+
$[17] = className;
|
|
171
|
+
$[18] = t10;
|
|
167
172
|
} else {
|
|
168
|
-
|
|
173
|
+
t10 = $[18];
|
|
169
174
|
}
|
|
170
|
-
let
|
|
171
|
-
if ($[
|
|
172
|
-
|
|
173
|
-
$[
|
|
174
|
-
$[
|
|
175
|
-
$[
|
|
175
|
+
let t11;
|
|
176
|
+
if ($[19] !== props || $[20] !== t10) {
|
|
177
|
+
t11 = <View className={t10} {...props} />;
|
|
178
|
+
$[19] = props;
|
|
179
|
+
$[20] = t10;
|
|
180
|
+
$[21] = t11;
|
|
176
181
|
} else {
|
|
177
|
-
|
|
182
|
+
t11 = $[21];
|
|
178
183
|
}
|
|
179
|
-
let
|
|
180
|
-
if ($[
|
|
181
|
-
|
|
182
|
-
$[
|
|
183
|
-
$[
|
|
184
|
-
$[
|
|
184
|
+
let t12;
|
|
185
|
+
if ($[22] !== t11 || $[23] !== value) {
|
|
186
|
+
t12 = <ConversationContext.Provider value={value}>{t11}</ConversationContext.Provider>;
|
|
187
|
+
$[22] = t11;
|
|
188
|
+
$[23] = value;
|
|
189
|
+
$[24] = t12;
|
|
185
190
|
} else {
|
|
186
|
-
|
|
191
|
+
t12 = $[24];
|
|
187
192
|
}
|
|
188
|
-
return
|
|
193
|
+
return t12;
|
|
189
194
|
}
|
|
190
195
|
|
|
191
196
|
/** The scroll handlers a thread's scroller passes on, as `ScrollView` and `FlatList` both take them. */
|
|
192
|
-
|
|
197
|
+
function _temp(current) {
|
|
198
|
+
return current === "closing" ? "none" : current;
|
|
199
|
+
}
|
|
193
200
|
/**
|
|
194
201
|
* Taps reach rows while the keyboard is up; a drag lowers it (interactively
|
|
195
202
|
* on iOS, and on Android 11+ with `KeyboardControllerProvider`, in
|
|
@@ -235,6 +242,7 @@ function useConversationScroll({
|
|
|
235
242
|
},
|
|
236
243
|
onScrollBeginDrag: event_0 => {
|
|
237
244
|
conversation.onUserScroll();
|
|
245
|
+
conversation.settleOverlay();
|
|
238
246
|
onScrollBeginDrag?.(event_0);
|
|
239
247
|
},
|
|
240
248
|
// The app's handler first, so a scroller that measures itself (`ConversationList`) has the new size to follow.
|
|
@@ -396,12 +404,14 @@ export function ConversationList({
|
|
|
396
404
|
// Inverted, the column's end is the top: a short thread sits there.
|
|
397
405
|
contentContainerClassName={cn("px-3 py-3", inverted && "grow justify-end", contentContainerClassName)} {...wired} style={[wired.style, !inverted && hasRows && !placed ? styles.hidden : null]}
|
|
398
406
|
// At the bottom, a new message shows at offset 0; scrolled up, it must not move what the reader sees.
|
|
399
|
-
maintainVisibleContentPosition={props.maintainVisibleContentPosition ?? (inverted && !conversation.isAtBottom ? KEEP_VISIBLE : undefined)} keyboardDismissMode={props.keyboardDismissMode ?? (keyboard?.interactive ? "interactive" : SCROLL_DEFAULTS.keyboardDismissMode)} renderScrollComponent={keyboard ? scrollProps => <keyboard.ChatScrollView {...scrollProps} inverted={inverted}
|
|
407
|
+
maintainVisibleContentPosition={props.maintainVisibleContentPosition ?? (inverted && !conversation.isAtBottom ? KEEP_VISIBLE : undefined)} keyboardDismissMode={props.keyboardDismissMode ?? (keyboard?.interactive ? "interactive" : SCROLL_DEFAULTS.keyboardDismissMode)} renderScrollComponent={keyboard ? scrollProps => <keyboard.ChatScrollView {...scrollProps} inverted={inverted} freeze={conversation.overlay !== "none"}
|
|
400
408
|
// The composer pads the bottom inset, which the keyboard covers: the content rises by the rest.
|
|
401
409
|
bottomOffset={insets.bottom} onInsetChange={inset => {
|
|
402
410
|
size.current.inset = inset;
|
|
403
411
|
}} onKeyboardMove={moving => {
|
|
404
412
|
size.current.keyboardMoving = moving;
|
|
413
|
+
// The closing menu's window hands the focus back with a keyboard event: frozen until it ends.
|
|
414
|
+
if (!moving) conversation.settleOverlay();
|
|
405
415
|
}} /> : props.renderScrollComponent} ref={list => {
|
|
406
416
|
conversation.scrollRef.current = list && {
|
|
407
417
|
scrollToEnd: options => list.scrollToOffset({
|