@vvedantb/native-ui 0.25.0 → 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 -325
- package/dist/ai/message.jsx +98 -79
- 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 +80 -33
- package/src/ai/message.tsx +18 -5
- package/src/primitives/keyboard-controller.tsx +3 -0
- package/src/primitives/keyboard-parts.tsx +3 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { useState, type ReactNode } from "react";
|
|
2
2
|
import { Modal, Pressable, StyleSheet, Text, View, useWindowDimensions } from "react-native";
|
|
3
3
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
4
4
|
import { cn } from "../cn";
|
|
@@ -23,6 +23,7 @@ import { MESSAGE_MENU, messageContextMenuLayout, type MessageMenu, type MessageM
|
|
|
23
23
|
export function MessageContextMenu({
|
|
24
24
|
open,
|
|
25
25
|
onClose,
|
|
26
|
+
onDismissed,
|
|
26
27
|
anchor,
|
|
27
28
|
align,
|
|
28
29
|
preview,
|
|
@@ -31,6 +32,8 @@ export function MessageContextMenu({
|
|
|
31
32
|
}: {
|
|
32
33
|
open: boolean;
|
|
33
34
|
onClose: () => void;
|
|
35
|
+
/** After the menu has gone from the screen (iOS; Android gives no such callback for a `Modal`). */
|
|
36
|
+
onDismissed?: () => void;
|
|
34
37
|
/** The held message's box; the menu stays shut without one. */
|
|
35
38
|
anchor: MessageMenuRect | null;
|
|
36
39
|
/** Which side the pill and the card line up with: the message's (`end` for the user's). */
|
|
@@ -71,7 +74,7 @@ export function MessageContextMenu({
|
|
|
71
74
|
|
|
72
75
|
return (
|
|
73
76
|
// The Modal's own fade: Reanimated entering animations do not run inside a Modal on Android.
|
|
74
|
-
<Modal visible transparent animationType={reduceMotion ? "none" : "fade"} statusBarTranslucent onRequestClose={onClose}>
|
|
77
|
+
<Modal visible transparent animationType={reduceMotion ? "none" : "fade"} statusBarTranslucent onRequestClose={onClose} onDismiss={onDismissed}>
|
|
75
78
|
<View style={{ flex: 1 }} testID={testID} accessibilityViewIsModal onAccessibilityEscape={onClose}>
|
|
76
79
|
<View style={StyleSheet.absoluteFill}>
|
|
77
80
|
<Pressable
|
|
@@ -84,7 +87,7 @@ export function MessageContextMenu({
|
|
|
84
87
|
style={[StyleSheet.absoluteFill, { backgroundColor: withAlpha(tokens.color.background[scheme], 0.85) }]}
|
|
85
88
|
/>
|
|
86
89
|
</View>
|
|
87
|
-
{/* The held message, lifted: in place, a shadow
|
|
90
|
+
{/* The held message, lifted: in place, on the screen colour with a shadow, clipped when it is taller than the room. */}
|
|
88
91
|
<View
|
|
89
92
|
pointerEvents="none"
|
|
90
93
|
style={{
|
|
@@ -94,6 +97,9 @@ export function MessageContextMenu({
|
|
|
94
97
|
width: anchor.width,
|
|
95
98
|
height: layout.previewHeight,
|
|
96
99
|
overflow: "hidden",
|
|
100
|
+
// The screen colour behind the copy: a reply without a bubble would show the dimmed original through it.
|
|
101
|
+
backgroundColor: tokens.color.background[scheme],
|
|
102
|
+
borderRadius: tokens.radius.card,
|
|
97
103
|
...shadow,
|
|
98
104
|
}}
|
|
99
105
|
>
|
|
@@ -146,38 +152,79 @@ export function MessageContextMenu({
|
|
|
146
152
|
...shadow,
|
|
147
153
|
}}
|
|
148
154
|
>
|
|
149
|
-
{menu.actions.map((action, index) =>
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
// A static style: with a `className`, NativeWind drops a style function.
|
|
162
|
-
className="flex-row items-center gap-3 px-4 active:opacity-70"
|
|
163
|
-
style={[
|
|
164
|
-
{ minHeight: rowHeight, opacity: action.disabled ? 0.5 : 1 },
|
|
165
|
-
index > 0 && { borderTopWidth: StyleSheet.hairlineWidth, borderTopColor: tokens.color.separator[scheme] },
|
|
166
|
-
]}
|
|
167
|
-
>
|
|
168
|
-
<Text
|
|
169
|
-
numberOfLines={1}
|
|
170
|
-
className={cn(body, "min-w-0 flex-1 font-instrument-sans")}
|
|
171
|
-
style={[sizeStyle(body), typeStyle("medium"), { color }]}
|
|
172
|
-
>
|
|
173
|
-
{action.label}
|
|
174
|
-
</Text>
|
|
175
|
-
{Icon ? <Icon size={largerText ? 22 : 20} color={color} /> : null}
|
|
176
|
-
</Pressable>
|
|
177
|
-
);
|
|
178
|
-
})}
|
|
155
|
+
{menu.actions.map((action, index) => (
|
|
156
|
+
<MenuCardRow
|
|
157
|
+
key={action.key}
|
|
158
|
+
testID={`${testID}-action-${action.key}`}
|
|
159
|
+
action={action}
|
|
160
|
+
first={index === 0}
|
|
161
|
+
rowHeight={rowHeight}
|
|
162
|
+
body={body}
|
|
163
|
+
iconSize={largerText ? 22 : 20}
|
|
164
|
+
onPress={() => run(action.onPress)}
|
|
165
|
+
/>
|
|
166
|
+
))}
|
|
179
167
|
</View>
|
|
180
168
|
</View>
|
|
181
169
|
</Modal>
|
|
182
170
|
);
|
|
183
171
|
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* One card row: label first, icon last. While pressed it takes the
|
|
175
|
+
* `SheetRow` pressed fill, so the finger sees which row it is on.
|
|
176
|
+
*/
|
|
177
|
+
function MenuCardRow({
|
|
178
|
+
testID,
|
|
179
|
+
action,
|
|
180
|
+
first,
|
|
181
|
+
rowHeight,
|
|
182
|
+
body,
|
|
183
|
+
iconSize,
|
|
184
|
+
onPress,
|
|
185
|
+
}: {
|
|
186
|
+
testID: string;
|
|
187
|
+
action: MessageMenu["actions"][number];
|
|
188
|
+
first: boolean;
|
|
189
|
+
rowHeight: number;
|
|
190
|
+
body: ReturnType<typeof chatTextSize>;
|
|
191
|
+
iconSize: number;
|
|
192
|
+
onPress: () => void;
|
|
193
|
+
}) {
|
|
194
|
+
const scheme = useScheme();
|
|
195
|
+
// A state, not a style function: with a `className`, NativeWind drops a style function.
|
|
196
|
+
const [pressed, setPressed] = useState(false);
|
|
197
|
+
const disabled = action.disabled === true;
|
|
198
|
+
const Icon = action.icon;
|
|
199
|
+
const color = action.destructive ? palette.danger[scheme] : tokens.color.foreground[scheme];
|
|
200
|
+
return (
|
|
201
|
+
<Pressable
|
|
202
|
+
testID={testID}
|
|
203
|
+
accessibilityRole="menuitem"
|
|
204
|
+
accessibilityLabel={action.label}
|
|
205
|
+
accessibilityState={{ disabled }}
|
|
206
|
+
disabled={disabled}
|
|
207
|
+
onPress={onPress}
|
|
208
|
+
onPressIn={() => setPressed(true)}
|
|
209
|
+
onPressOut={() => setPressed(false)}
|
|
210
|
+
className="flex-row items-center gap-3 px-4"
|
|
211
|
+
style={[
|
|
212
|
+
{
|
|
213
|
+
minHeight: rowHeight,
|
|
214
|
+
opacity: disabled ? 0.5 : 1,
|
|
215
|
+
backgroundColor: pressed && !disabled ? palette.default[scheme] : "transparent",
|
|
216
|
+
},
|
|
217
|
+
!first && { borderTopWidth: StyleSheet.hairlineWidth, borderTopColor: tokens.color.separator[scheme] },
|
|
218
|
+
]}
|
|
219
|
+
>
|
|
220
|
+
<Text
|
|
221
|
+
numberOfLines={1}
|
|
222
|
+
className={cn(body, "min-w-0 flex-1 font-instrument-sans")}
|
|
223
|
+
style={[sizeStyle(body), typeStyle("medium"), { color }]}
|
|
224
|
+
>
|
|
225
|
+
{action.label}
|
|
226
|
+
</Text>
|
|
227
|
+
{Icon ? <Icon size={iconSize} color={color} /> : null}
|
|
228
|
+
</Pressable>
|
|
229
|
+
);
|
|
230
|
+
}
|
package/src/ai/message.tsx
CHANGED
|
@@ -20,6 +20,7 @@ import { useScheme } from "../useScheme";
|
|
|
20
20
|
import { META_TEXT_STYLE, chatTextSize } from "./chat-text";
|
|
21
21
|
import { ChatIconButton, type ChatIconButtonSize } from "./icon-button";
|
|
22
22
|
import { MESSAGE_ACTIONS_TITLE, MessageActionSheet, type MessageSheetAction } from "./message-action-sheet";
|
|
23
|
+
import { useOptionalConversation } from "./conversation-context";
|
|
23
24
|
import { MessageContextMenu } from "./message-context-menu";
|
|
24
25
|
import type { MessageMenu, MessageMenuRect } from "./message-menu-layout";
|
|
25
26
|
import { ChatTextColorContext, ResponseText } from "./response-text";
|
|
@@ -107,7 +108,7 @@ function MessageHighlight() {
|
|
|
107
108
|
* at the start, its parts full width.
|
|
108
109
|
*
|
|
109
110
|
* With `onLongPress` or `actions` the message is a `Pressable` (same layout,
|
|
110
|
-
* `className`, `style` and view props): a 350 ms hold
|
|
111
|
+
* `className`, `style` and view props): a 350 ms hold dims it a little,
|
|
111
112
|
* fires a medium haptic, runs `onLongPress` and opens the
|
|
112
113
|
* `MessageActionSheet`; TalkBack reaches it as the `longpress` action. It stays
|
|
113
114
|
* a non-accessible container so its buttons and links keep their own focus:
|
|
@@ -115,8 +116,12 @@ function MessageHighlight() {
|
|
|
115
116
|
*/
|
|
116
117
|
/** How long a hold takes, in ms: shorter than React Native's 500, as iMessage. */
|
|
117
118
|
const HOLD_DELAY_MS = 350;
|
|
118
|
-
/**
|
|
119
|
-
|
|
119
|
+
/**
|
|
120
|
+
* A held message dims a little. It does not shrink: the hold menu measures the
|
|
121
|
+
* message while it is held, and a scaled box would draw the lifted copy smaller
|
|
122
|
+
* (and could wrap its text differently).
|
|
123
|
+
*/
|
|
124
|
+
const HELD_STYLE = { opacity: 0.9 };
|
|
120
125
|
|
|
121
126
|
export function Message({
|
|
122
127
|
from,
|
|
@@ -140,15 +145,22 @@ export function Message({
|
|
|
140
145
|
const pressable = useRef<View>(null);
|
|
141
146
|
const hasActions = actions != null && actions.length > 0;
|
|
142
147
|
const longPressable = onLongPress != null || hasActions || menu != null;
|
|
148
|
+
// In a thread, the menu freezes the list's keyboard handling until its close settles (see `overlay`).
|
|
149
|
+
const conversation = useOptionalConversation();
|
|
143
150
|
const longPress = () => {
|
|
144
151
|
// A medium tap on a hold, as iMessage; the sheet adds its own selection tick.
|
|
145
152
|
impactHaptic("medium");
|
|
146
153
|
onLongPress?.();
|
|
147
154
|
if (menu) {
|
|
148
155
|
const built = menu();
|
|
156
|
+
conversation?.openOverlay();
|
|
149
157
|
pressable.current?.measureInWindow((x, y, width, height) => setHeld({ anchor: { x, y, width, height }, menu: built }));
|
|
150
158
|
} else if (hasActions) setSheetOpen(true);
|
|
151
159
|
};
|
|
160
|
+
const closeMenu = () => {
|
|
161
|
+
setHeld(null);
|
|
162
|
+
conversation?.closeOverlay();
|
|
163
|
+
};
|
|
152
164
|
const layout: ViewProps["style"] = [
|
|
153
165
|
{ alignSelf: user ? "flex-end" : "flex-start", alignItems: user ? "flex-end" : "stretch" },
|
|
154
166
|
style,
|
|
@@ -169,7 +181,7 @@ export function Message({
|
|
|
169
181
|
ref={pressable}
|
|
170
182
|
accessible={false}
|
|
171
183
|
className={merged}
|
|
172
|
-
// While held it
|
|
184
|
+
// While held it dims a little: the feedback before the menu opens. A state, not a
|
|
173
185
|
// style function: with a `className`, NativeWind drops a style function, layout and all.
|
|
174
186
|
style={[layout, pressing ? HELD_STYLE : null]}
|
|
175
187
|
onPressIn={() => setPressing(true)}
|
|
@@ -188,7 +200,8 @@ export function Message({
|
|
|
188
200
|
{menu ? (
|
|
189
201
|
<MessageContextMenu
|
|
190
202
|
open={held !== null}
|
|
191
|
-
onClose={
|
|
203
|
+
onClose={closeMenu}
|
|
204
|
+
onDismissed={conversation?.settleOverlay}
|
|
192
205
|
anchor={held?.anchor ?? null}
|
|
193
206
|
align={user ? "end" : "start"}
|
|
194
207
|
preview={
|
|
@@ -43,6 +43,7 @@ function StickyView({ bottomOffset, ...props }: ComponentProps<KeyboardParts["St
|
|
|
43
43
|
function ChatScrollView({
|
|
44
44
|
bottomOffset,
|
|
45
45
|
inverted = false,
|
|
46
|
+
freeze = false,
|
|
46
47
|
onInsetChange,
|
|
47
48
|
onKeyboardMove,
|
|
48
49
|
...props
|
|
@@ -64,6 +65,8 @@ function ChatScrollView({
|
|
|
64
65
|
<KeyboardChatScrollView
|
|
65
66
|
{...props}
|
|
66
67
|
inverted={inverted}
|
|
68
|
+
// An overlay window (a hold menu) takes the focus on Android: its keyboard events must not scroll the list.
|
|
69
|
+
freeze={freeze}
|
|
67
70
|
offset={bottomOffset}
|
|
68
71
|
keyboardLiftBehavior="always"
|
|
69
72
|
onContentInsetChange={(insets) =>
|
|
@@ -31,12 +31,14 @@ export type KeyboardParts = {
|
|
|
31
31
|
* gets that extra space as the scroll offset sees it, which `onScroll` does
|
|
32
32
|
* not report: past the content's end, or when `inverted` before offset 0.
|
|
33
33
|
* `onKeyboardMove` is true from the start to the end of each keyboard
|
|
34
|
-
* move, while the keyboard, not the reader, scrolls the list.
|
|
34
|
+
* move, while the keyboard, not the reader, scrolls the list. With
|
|
35
|
+
* `freeze`, keyboard events change nothing (an overlay window is open).
|
|
35
36
|
*/
|
|
36
37
|
ChatScrollView: ComponentType<
|
|
37
38
|
ScrollViewProps & {
|
|
38
39
|
bottomOffset: number;
|
|
39
40
|
inverted?: boolean;
|
|
41
|
+
freeze?: boolean;
|
|
40
42
|
onInsetChange: (inset: number) => void;
|
|
41
43
|
onKeyboardMove: (moving: boolean) => void;
|
|
42
44
|
}
|