@vvedantb/native-ui 0.26.1 → 0.28.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.
- package/dist/ai/activity-question.jsx +302 -0
- package/dist/ai/choice-question.jsx +1 -1
- package/dist/ai/index.js +1 -0
- package/dist/ai/message-context-menu.jsx +111 -113
- package/dist/entries/primitives.js +2 -0
- package/dist/media/ImageGallery.jsx +12 -15
- package/dist/primitives/window-layer.jsx +212 -0
- package/package.json +1 -1
- package/src/ai/activity-question.tsx +179 -0
- package/src/ai/choice-question.tsx +1 -1
- package/src/ai/index.ts +2 -0
- package/src/ai/message-context-menu.tsx +11 -10
- package/src/entries/primitives.ts +3 -0
- package/src/media/ImageGallery.tsx +6 -5
- package/src/primitives/window-layer.tsx +133 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import { useContext, useState } from "react";
|
|
3
|
-
import { FlatList, Image,
|
|
3
|
+
import { FlatList, Image, Pressable, Text, View, useWindowDimensions } from "react-native";
|
|
4
4
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
5
5
|
import { IconExternalLink, IconX } from "@tabler/icons-react-native";
|
|
6
6
|
import { typeStyle } from "../controlStyles";
|
|
7
|
+
import { WindowLayer } from "../primitives/window-layer";
|
|
7
8
|
import { IconButton } from "../IconButton";
|
|
8
9
|
import { withAlpha } from "../palette";
|
|
9
10
|
import { tokens } from "../tokens";
|
|
10
|
-
import { useReduceMotion } from "../useReduceMotion";
|
|
11
11
|
import { useScheme } from "../useScheme";
|
|
12
12
|
import { ZoomImageContext } from "./zoomImage";
|
|
13
13
|
import { imageAspect, imageGridTiles, imageViewerPage, MEDIA } from "./imageGrid";
|
|
@@ -346,7 +346,7 @@ function _temp(tile) {
|
|
|
346
346
|
* at once with Reduce Motion.
|
|
347
347
|
*/
|
|
348
348
|
export function ImageViewer(t0) {
|
|
349
|
-
const $ = _c(
|
|
349
|
+
const $ = _c(9);
|
|
350
350
|
const {
|
|
351
351
|
images,
|
|
352
352
|
index,
|
|
@@ -354,34 +354,31 @@ export function ImageViewer(t0) {
|
|
|
354
354
|
onClose,
|
|
355
355
|
onOpenImage
|
|
356
356
|
} = t0;
|
|
357
|
-
const reduceMotion = useReduceMotion();
|
|
358
357
|
if (index === null) {
|
|
359
358
|
return null;
|
|
360
359
|
}
|
|
361
|
-
|
|
362
|
-
let t2;
|
|
360
|
+
let t1;
|
|
363
361
|
if ($[0] !== images || $[1] !== index || $[2] !== onClose || $[3] !== onIndexChange || $[4] !== onOpenImage) {
|
|
364
|
-
|
|
362
|
+
t1 = <ViewerRoot><ViewerPages images={images} index={index} onIndexChange={onIndexChange} onClose={onClose} onOpenImage={onOpenImage} /></ViewerRoot>;
|
|
365
363
|
$[0] = images;
|
|
366
364
|
$[1] = index;
|
|
367
365
|
$[2] = onClose;
|
|
368
366
|
$[3] = onIndexChange;
|
|
369
367
|
$[4] = onOpenImage;
|
|
370
|
-
$[5] =
|
|
368
|
+
$[5] = t1;
|
|
371
369
|
} else {
|
|
372
|
-
|
|
370
|
+
t1 = $[5];
|
|
373
371
|
}
|
|
374
|
-
let
|
|
375
|
-
if ($[6] !== onClose || $[7] !== t1
|
|
376
|
-
|
|
372
|
+
let t2;
|
|
373
|
+
if ($[6] !== onClose || $[7] !== t1) {
|
|
374
|
+
t2 = <WindowLayer onRequestClose={onClose}>{t1}</WindowLayer>;
|
|
377
375
|
$[6] = onClose;
|
|
378
376
|
$[7] = t1;
|
|
379
377
|
$[8] = t2;
|
|
380
|
-
$[9] = t3;
|
|
381
378
|
} else {
|
|
382
|
-
|
|
379
|
+
t2 = $[8];
|
|
383
380
|
}
|
|
384
|
-
return
|
|
381
|
+
return t2;
|
|
385
382
|
}
|
|
386
383
|
|
|
387
384
|
/** The zoom parts' gesture root, when there are zoom parts. */
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { c as _c } from "react/compiler-runtime";
|
|
2
|
+
import { useId, useLayoutEffect, useSyncExternalStore } from "react";
|
|
3
|
+
import { BackHandler, Modal, StyleSheet, View } from "react-native";
|
|
4
|
+
import Animated, { FadeIn, FadeOut, ReduceMotion } from "react-native-reanimated";
|
|
5
|
+
import { useReduceMotion } from "../useReduceMotion";
|
|
6
|
+
|
|
7
|
+
// Overlays drawn in the app's own window. A React Native `Modal` is a window
|
|
8
|
+
// of its own on Android: it takes the focus as it opens and hands it back as
|
|
9
|
+
// it closes, and each time `react-native-keyboard-controller`'s chat list
|
|
10
|
+
// scrolls to its newest message. A layer in `WindowLayerHost` is a view over
|
|
11
|
+
// the app instead, so the focus never moves. Without a host, `WindowLayer`
|
|
12
|
+
// falls back to a `Modal`, so an app that mounts none keeps working.
|
|
13
|
+
|
|
14
|
+
const EMPTY = [];
|
|
15
|
+
let layers = EMPTY;
|
|
16
|
+
let hosts = 0;
|
|
17
|
+
const listeners = new Set();
|
|
18
|
+
const emit = () => {
|
|
19
|
+
for (const listener of listeners) listener();
|
|
20
|
+
};
|
|
21
|
+
const subscribe = listener => {
|
|
22
|
+
listeners.add(listener);
|
|
23
|
+
return () => {
|
|
24
|
+
listeners.delete(listener);
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const upsert = layer => {
|
|
28
|
+
const at = layers.findIndex(item => item.id === layer.id);
|
|
29
|
+
layers = at === -1 ? [...layers, layer] : layers.map((item, index) => index === at ? layer : item);
|
|
30
|
+
emit();
|
|
31
|
+
};
|
|
32
|
+
const remove = id => {
|
|
33
|
+
if (!layers.some(item => item.id === id)) return;
|
|
34
|
+
layers = layers.filter(item => item.id !== id);
|
|
35
|
+
emit();
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Android back closes the newest layer, as a Modal's `onRequestClose`.
|
|
39
|
+
const onBack = () => {
|
|
40
|
+
const top = layers[layers.length - 1];
|
|
41
|
+
if (!top) return false;
|
|
42
|
+
top.onRequestClose();
|
|
43
|
+
return true;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** Mounted: the host is there, and it answers Android back for its layers. */
|
|
47
|
+
const hostRef = view => {
|
|
48
|
+
if (view === null) return undefined;
|
|
49
|
+
hosts += 1;
|
|
50
|
+
const back = BackHandler.addEventListener("hardwareBackPress", onBack);
|
|
51
|
+
emit();
|
|
52
|
+
return () => {
|
|
53
|
+
hosts -= 1;
|
|
54
|
+
back.remove();
|
|
55
|
+
emit();
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Wrap the app once (inside `NativeUiProvider`, around the navigator): the
|
|
61
|
+
* `WindowLayer`s draw over it, in the same window. While a layer shows, the
|
|
62
|
+
* app under it is hidden from TalkBack and VoiceOver, as under a Modal.
|
|
63
|
+
*/
|
|
64
|
+
export function WindowLayerHost(t0) {
|
|
65
|
+
const $ = _c(12);
|
|
66
|
+
const {
|
|
67
|
+
children
|
|
68
|
+
} = t0;
|
|
69
|
+
const shown = useSyncExternalStore(subscribe, _temp, _temp2);
|
|
70
|
+
let t1;
|
|
71
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
72
|
+
t1 = FadeIn.duration(200).reduceMotion(ReduceMotion.System);
|
|
73
|
+
$[0] = t1;
|
|
74
|
+
} else {
|
|
75
|
+
t1 = $[0];
|
|
76
|
+
}
|
|
77
|
+
const enter = t1;
|
|
78
|
+
let t2;
|
|
79
|
+
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
|
80
|
+
t2 = FadeOut.duration(150).reduceMotion(ReduceMotion.System);
|
|
81
|
+
$[1] = t2;
|
|
82
|
+
} else {
|
|
83
|
+
t2 = $[1];
|
|
84
|
+
}
|
|
85
|
+
const exit = t2;
|
|
86
|
+
const t3 = shown.length > 0 ? "no-hide-descendants" : "auto";
|
|
87
|
+
const t4 = shown.length > 0;
|
|
88
|
+
let t5;
|
|
89
|
+
if ($[2] !== children || $[3] !== t3 || $[4] !== t4) {
|
|
90
|
+
t5 = <View style={styles.fill} importantForAccessibility={t3} accessibilityElementsHidden={t4}>{children}</View>;
|
|
91
|
+
$[2] = children;
|
|
92
|
+
$[3] = t3;
|
|
93
|
+
$[4] = t4;
|
|
94
|
+
$[5] = t5;
|
|
95
|
+
} else {
|
|
96
|
+
t5 = $[5];
|
|
97
|
+
}
|
|
98
|
+
let t6;
|
|
99
|
+
if ($[6] !== shown) {
|
|
100
|
+
let t7;
|
|
101
|
+
if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
|
|
102
|
+
t7 = layer => <Animated.View key={layer.id} entering={enter} exiting={exit} style={StyleSheet.absoluteFill} pointerEvents="box-none">{layer.node}</Animated.View>;
|
|
103
|
+
$[8] = t7;
|
|
104
|
+
} else {
|
|
105
|
+
t7 = $[8];
|
|
106
|
+
}
|
|
107
|
+
t6 = shown.map(t7);
|
|
108
|
+
$[6] = shown;
|
|
109
|
+
$[7] = t6;
|
|
110
|
+
} else {
|
|
111
|
+
t6 = $[7];
|
|
112
|
+
}
|
|
113
|
+
let t7;
|
|
114
|
+
if ($[9] !== t5 || $[10] !== t6) {
|
|
115
|
+
t7 = <View ref={hostRef} style={styles.fill}>{t5}{t6}</View>;
|
|
116
|
+
$[9] = t5;
|
|
117
|
+
$[10] = t6;
|
|
118
|
+
$[11] = t7;
|
|
119
|
+
} else {
|
|
120
|
+
t7 = $[11];
|
|
121
|
+
}
|
|
122
|
+
return t7;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* An overlay over the whole app, in its own window only when it must be: in
|
|
127
|
+
* `WindowLayerHost` when the app has one, else a transparent `Modal` (with
|
|
128
|
+
* `onDismiss` there). Render it only while the overlay shows. Android back
|
|
129
|
+
* calls `onRequestClose`. Its children keep the providers above the host, not
|
|
130
|
+
* those between the host and this element.
|
|
131
|
+
*/
|
|
132
|
+
function _temp2() {
|
|
133
|
+
return EMPTY;
|
|
134
|
+
}
|
|
135
|
+
function _temp() {
|
|
136
|
+
return layers;
|
|
137
|
+
}
|
|
138
|
+
export function WindowLayer(t0) {
|
|
139
|
+
const $ = _c(14);
|
|
140
|
+
const {
|
|
141
|
+
onRequestClose,
|
|
142
|
+
onDismiss,
|
|
143
|
+
children
|
|
144
|
+
} = t0;
|
|
145
|
+
const id = useId();
|
|
146
|
+
const reduceMotion = useReduceMotion();
|
|
147
|
+
const hosted = useSyncExternalStore(subscribe, _temp3, _temp4);
|
|
148
|
+
let t1;
|
|
149
|
+
let t2;
|
|
150
|
+
if ($[0] !== children || $[1] !== hosted || $[2] !== id || $[3] !== onRequestClose) {
|
|
151
|
+
t1 = () => {
|
|
152
|
+
if (hosted) {
|
|
153
|
+
upsert({
|
|
154
|
+
id,
|
|
155
|
+
node: children,
|
|
156
|
+
onRequestClose
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
t2 = [hosted, id, children, onRequestClose];
|
|
161
|
+
$[0] = children;
|
|
162
|
+
$[1] = hosted;
|
|
163
|
+
$[2] = id;
|
|
164
|
+
$[3] = onRequestClose;
|
|
165
|
+
$[4] = t1;
|
|
166
|
+
$[5] = t2;
|
|
167
|
+
} else {
|
|
168
|
+
t1 = $[4];
|
|
169
|
+
t2 = $[5];
|
|
170
|
+
}
|
|
171
|
+
useLayoutEffect(t1, t2);
|
|
172
|
+
let t3;
|
|
173
|
+
let t4;
|
|
174
|
+
if ($[6] !== id) {
|
|
175
|
+
t3 = () => () => remove(id);
|
|
176
|
+
t4 = [id];
|
|
177
|
+
$[6] = id;
|
|
178
|
+
$[7] = t3;
|
|
179
|
+
$[8] = t4;
|
|
180
|
+
} else {
|
|
181
|
+
t3 = $[7];
|
|
182
|
+
t4 = $[8];
|
|
183
|
+
}
|
|
184
|
+
useLayoutEffect(t3, t4);
|
|
185
|
+
if (hosted) {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
const t5 = reduceMotion ? "none" : "fade";
|
|
189
|
+
let t6;
|
|
190
|
+
if ($[9] !== children || $[10] !== onDismiss || $[11] !== onRequestClose || $[12] !== t5) {
|
|
191
|
+
t6 = <Modal visible={true} transparent={true} statusBarTranslucent={true} animationType={t5} onRequestClose={onRequestClose} onDismiss={onDismiss}>{children}</Modal>;
|
|
192
|
+
$[9] = children;
|
|
193
|
+
$[10] = onDismiss;
|
|
194
|
+
$[11] = onRequestClose;
|
|
195
|
+
$[12] = t5;
|
|
196
|
+
$[13] = t6;
|
|
197
|
+
} else {
|
|
198
|
+
t6 = $[13];
|
|
199
|
+
}
|
|
200
|
+
return t6;
|
|
201
|
+
}
|
|
202
|
+
function _temp4() {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
function _temp3() {
|
|
206
|
+
return hosts > 0;
|
|
207
|
+
}
|
|
208
|
+
const styles = StyleSheet.create({
|
|
209
|
+
fill: {
|
|
210
|
+
flex: 1
|
|
211
|
+
}
|
|
212
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/native-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Shared React Native / Expo UI primitives. Floating surfaces, forms, overlays, toasts, settings chrome, tab bar, AI chat parts, the family app marks, a NativeWind preset, the Expo web root and Clerk + Convex auth screens.",
|
|
6
6
|
"type": "module",
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { Text, View } from "react-native";
|
|
2
|
+
import { IconCheck, IconMessageQuestion, IconPencil } from "@tabler/icons-react-native";
|
|
3
|
+
import { sizeStyle, textStyle, typeStyle } from "../controlStyles";
|
|
4
|
+
import { palette } from "../palette";
|
|
5
|
+
import { useLargerText } from "../theme";
|
|
6
|
+
import { tokens } from "../tokens";
|
|
7
|
+
import { useScheme } from "../useScheme";
|
|
8
|
+
import type { ActivityQuestion } from "./activity-step-types";
|
|
9
|
+
import { chatTextSize } from "./chat-text";
|
|
10
|
+
import { TopicBadge } from "./choice-question";
|
|
11
|
+
|
|
12
|
+
const LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The offered labels the user picked. A whole-answer match wins first, so a
|
|
16
|
+
* single-select label holding ", " is not read as several picks; only a
|
|
17
|
+
* multi-select answer is split on the ", " the dock joins it with.
|
|
18
|
+
*/
|
|
19
|
+
export function selectedLabels(answer: string | undefined, question: ActivityQuestion): string[] {
|
|
20
|
+
if (answer === undefined) return [];
|
|
21
|
+
const offered = new Set(question.options.map((option) => option.label));
|
|
22
|
+
if (offered.has(answer)) return [answer];
|
|
23
|
+
if (!question.multiSelect) return [];
|
|
24
|
+
return answer.split(", ").filter((label) => offered.has(label));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Free text typed into "Other": an answer that matches no offered label. */
|
|
28
|
+
export function freeTextAnswer(answer: string | undefined, chosen: readonly string[]): string | null {
|
|
29
|
+
if (answer === undefined || answer.trim().length === 0) return null;
|
|
30
|
+
return chosen.length > 0 ? null : answer;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type ActivityQuestionCardProps = {
|
|
34
|
+
/** The prompt's questions, as the agent asked them. */
|
|
35
|
+
questions: ActivityQuestion[];
|
|
36
|
+
/** The answers, keyed by question text (`ChoiceQuestion`'s `onSubmit` shape). */
|
|
37
|
+
answers?: Record<string, string>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The read-only record of an AskUserQuestion prompt and the answer given, as
|
|
42
|
+
* the web `ActivityQuestionCard`: "Question(s)" over each question with its
|
|
43
|
+
* topic badge, its lettered options with the picked ones filled and checked,
|
|
44
|
+
* the free "Other" text with a pencil, and "Answered in the next message" when
|
|
45
|
+
* no structured answer was kept. The live prompt is `ChoiceQuestion`; this is
|
|
46
|
+
* what the transcript keeps once it is answered. Nothing here is pressable.
|
|
47
|
+
*/
|
|
48
|
+
export function ActivityQuestionCard({ questions, answers }: ActivityQuestionCardProps) {
|
|
49
|
+
const scheme = useScheme();
|
|
50
|
+
const largerText = useLargerText();
|
|
51
|
+
if (questions.length === 0) return null;
|
|
52
|
+
const caption = chatTextSize("caption", largerText);
|
|
53
|
+
const small = chatTextSize("small", largerText);
|
|
54
|
+
const title = questions.length > 1 ? "Questions" : "Question";
|
|
55
|
+
return (
|
|
56
|
+
<View
|
|
57
|
+
accessibilityLabel={title}
|
|
58
|
+
style={{ borderRadius: tokens.radius.lg, backgroundColor: tokens.color.surface[scheme], padding: 12, gap: 12 }}
|
|
59
|
+
>
|
|
60
|
+
<View className="flex-row items-center" style={{ gap: 6 }}>
|
|
61
|
+
<IconMessageQuestion size={largerText ? 18 : 14} color={tokens.color.muted[scheme]} />
|
|
62
|
+
<Text className="font-instrument-sans-medium" style={[sizeStyle(caption), textStyle("muted", scheme), typeStyle("medium")]}>
|
|
63
|
+
{title}
|
|
64
|
+
</Text>
|
|
65
|
+
</View>
|
|
66
|
+
{questions.map((question, questionIndex) => {
|
|
67
|
+
const answer = answers?.[question.question];
|
|
68
|
+
const chosen = selectedLabels(answer, question);
|
|
69
|
+
const freeText = freeTextAnswer(answer, chosen);
|
|
70
|
+
const answered = answer !== undefined && answer.trim().length > 0;
|
|
71
|
+
return (
|
|
72
|
+
<View key={`${question.question}-${questionIndex}`} style={{ gap: 6 }}>
|
|
73
|
+
<View className="flex-row items-start justify-between" style={{ gap: 8 }}>
|
|
74
|
+
<Text
|
|
75
|
+
className="min-w-0 flex-1 font-instrument-sans-medium"
|
|
76
|
+
style={[sizeStyle(small), textStyle("foreground", scheme), typeStyle("medium")]}
|
|
77
|
+
>
|
|
78
|
+
{question.question}
|
|
79
|
+
</Text>
|
|
80
|
+
{question.header ? <TopicBadge>{question.header}</TopicBadge> : null}
|
|
81
|
+
</View>
|
|
82
|
+
<View style={{ gap: 2 }}>
|
|
83
|
+
{question.options.map((option, optionIndex) => (
|
|
84
|
+
<RecordRow
|
|
85
|
+
key={`${option.label}-${optionIndex}`}
|
|
86
|
+
mark={chosen.includes(option.label) ? "check" : (LETTERS[optionIndex] ?? String(optionIndex + 1))}
|
|
87
|
+
label={option.label}
|
|
88
|
+
description={option.description}
|
|
89
|
+
selected={chosen.includes(option.label)}
|
|
90
|
+
/>
|
|
91
|
+
))}
|
|
92
|
+
{freeText ? <RecordRow mark="other" label="Other" description={freeText} selected /> : null}
|
|
93
|
+
</View>
|
|
94
|
+
{answered ? null : (
|
|
95
|
+
<Text className="font-instrument-sans" style={[sizeStyle(caption), textStyle("muted", scheme)]}>
|
|
96
|
+
Answered in the next message
|
|
97
|
+
</Text>
|
|
98
|
+
)}
|
|
99
|
+
</View>
|
|
100
|
+
);
|
|
101
|
+
})}
|
|
102
|
+
</View>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* One option as recorded (web `OptionRow`): a 20 rounded mark (the letter, a
|
|
108
|
+
* check when picked, a pencil for "Other"), the label and its description.
|
|
109
|
+
* Picked: the row on the tertiary fill, the mark on primary, the label medium.
|
|
110
|
+
*/
|
|
111
|
+
function RecordRow({
|
|
112
|
+
mark,
|
|
113
|
+
label,
|
|
114
|
+
description,
|
|
115
|
+
selected,
|
|
116
|
+
}: {
|
|
117
|
+
mark: string;
|
|
118
|
+
label: string;
|
|
119
|
+
description?: string;
|
|
120
|
+
selected: boolean;
|
|
121
|
+
}) {
|
|
122
|
+
const scheme = useScheme();
|
|
123
|
+
const largerText = useLargerText();
|
|
124
|
+
const caption = chatTextSize("caption", largerText);
|
|
125
|
+
const small = chatTextSize("small", largerText);
|
|
126
|
+
const markSize = largerText ? 26 : 20;
|
|
127
|
+
const markColor = selected ? palette.primaryForeground[scheme] : tokens.color.muted[scheme];
|
|
128
|
+
const glyph = largerText ? 15 : 12;
|
|
129
|
+
return (
|
|
130
|
+
<View
|
|
131
|
+
accessibilityLabel={selected ? `${label}, chosen` : label}
|
|
132
|
+
accessibilityHint={description || undefined}
|
|
133
|
+
className="flex-row items-start"
|
|
134
|
+
style={{
|
|
135
|
+
gap: 8,
|
|
136
|
+
borderRadius: tokens.radius.md,
|
|
137
|
+
paddingHorizontal: 8,
|
|
138
|
+
paddingVertical: 6,
|
|
139
|
+
backgroundColor: selected ? palette.surfaceTertiary[scheme] : "transparent",
|
|
140
|
+
}}
|
|
141
|
+
>
|
|
142
|
+
<View
|
|
143
|
+
style={{
|
|
144
|
+
width: markSize,
|
|
145
|
+
height: markSize,
|
|
146
|
+
marginTop: 2,
|
|
147
|
+
// A small rounded square, as the web `rounded-md` mark.
|
|
148
|
+
borderRadius: 6,
|
|
149
|
+
alignItems: "center",
|
|
150
|
+
justifyContent: "center",
|
|
151
|
+
backgroundColor: selected ? palette.primary[scheme] : palette.default[scheme],
|
|
152
|
+
}}
|
|
153
|
+
>
|
|
154
|
+
{mark === "check" ? (
|
|
155
|
+
<IconCheck size={glyph} strokeWidth={3} color={markColor} />
|
|
156
|
+
) : mark === "other" ? (
|
|
157
|
+
<IconPencil size={glyph} strokeWidth={3} color={markColor} />
|
|
158
|
+
) : (
|
|
159
|
+
<Text className="font-instrument-sans-semibold" style={[{ fontSize: largerText ? 13 : 10, color: markColor }, typeStyle("semibold")]}>
|
|
160
|
+
{mark}
|
|
161
|
+
</Text>
|
|
162
|
+
)}
|
|
163
|
+
</View>
|
|
164
|
+
<View className="min-w-0 flex-1">
|
|
165
|
+
<Text
|
|
166
|
+
className={selected ? "font-instrument-sans-medium" : "font-instrument-sans"}
|
|
167
|
+
style={[sizeStyle(small, "snug"), textStyle(selected ? "foreground" : "muted", scheme), selected ? typeStyle("medium") : null]}
|
|
168
|
+
>
|
|
169
|
+
{label}
|
|
170
|
+
</Text>
|
|
171
|
+
{description ? (
|
|
172
|
+
<Text className="font-instrument-sans" style={[sizeStyle(caption), textStyle("muted", scheme), { marginTop: 2 }]}>
|
|
173
|
+
{description}
|
|
174
|
+
</Text>
|
|
175
|
+
) : null}
|
|
176
|
+
</View>
|
|
177
|
+
</View>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
@@ -232,7 +232,7 @@ export function ChoiceQuestion({
|
|
|
232
232
|
* `text-3xs font-semibold` (10 / 14, 600) in a `px-2.5 py-0.5` pill. Drawn here
|
|
233
233
|
* because `Badge` sets its own size and weight.
|
|
234
234
|
*/
|
|
235
|
-
function TopicBadge({ children }: { children: string }) {
|
|
235
|
+
export function TopicBadge({ children }: { children: string }) {
|
|
236
236
|
const scheme = useScheme();
|
|
237
237
|
const largerText = useLargerText();
|
|
238
238
|
const fontSize = largerText ? 14 : 10;
|
package/src/ai/index.ts
CHANGED
|
@@ -181,6 +181,8 @@ export type { CodeBlockProps, CodeBlockCopyButtonProps } from "./code-block";
|
|
|
181
181
|
export { ResponseText, ChatTextColorContext } from "./response-text";
|
|
182
182
|
export type { ResponseTextProps } from "./response-text";
|
|
183
183
|
export { ChoiceQuestion, choiceAnswers } from "./choice-question";
|
|
184
|
+
export { ActivityQuestionCard, freeTextAnswer, selectedLabels } from "./activity-question";
|
|
185
|
+
export type { ActivityQuestionCardProps } from "./activity-question";
|
|
184
186
|
export type { ChoiceQuestionProps, ChoiceQuestionItem } from "./choice-question";
|
|
185
187
|
export { ActivityStepDetail } from "./activity-step-detail";
|
|
186
188
|
export type { ActivityStepDetailProps, ActivityStepDetailStep } from "./activity-step-detail";
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { Pressable, StyleSheet, Text, View, useWindowDimensions } from "react-native";
|
|
3
3
|
import Animated, { useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
|
|
4
4
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
5
5
|
import { cn } from "../cn";
|
|
6
|
+
import { WindowLayer } from "../primitives/window-layer";
|
|
6
7
|
import { PANEL_SCALE_FROM, POPOVER_ENTER } from "../motion";
|
|
7
8
|
import { sizeStyle, typeStyle } from "../controlStyles";
|
|
8
9
|
import { palette, withAlpha } from "../palette";
|
|
9
10
|
import { useLargerText } from "../theme";
|
|
10
11
|
import { tokens } from "../tokens";
|
|
11
|
-
import { useReduceMotion } from "../useReduceMotion";
|
|
12
12
|
import { useScheme } from "../useScheme";
|
|
13
13
|
import { chatTextSize } from "./chat-text";
|
|
14
14
|
import { MESSAGE_MENU, messageContextMenuLayout, type MessageMenu, type MessageMenuRect } from "./message-menu-layout";
|
|
@@ -21,8 +21,9 @@ const LIFT_SCALE = 1.02;
|
|
|
21
21
|
* The iMessage hold menu for a chat message: the chat fades under a frosted
|
|
22
22
|
* wash of the screen colour, the held message stays in place,
|
|
23
23
|
* lifted, with the quick reactions in a pill above it and the actions in a
|
|
24
|
-
* card below it, label first and icon last. It
|
|
25
|
-
*
|
|
24
|
+
* card below it, label first and icon last. It draws in the app's window
|
|
25
|
+
* (`WindowLayer`) and fades in and out as one; with Reduce Motion on, it
|
|
26
|
+
* appears at once. As it fades
|
|
26
27
|
* in, the pill and the card grow into place from the message's side (0.96 to
|
|
27
28
|
* 1) and the held message lifts a little (to 1.02), in 150 ms; with Reduce
|
|
28
29
|
* Motion they are in place at once. A tap outside, Android back
|
|
@@ -56,11 +57,10 @@ export function MessageContextMenu({
|
|
|
56
57
|
const window = useWindowDimensions();
|
|
57
58
|
const insets = useSafeAreaInsets();
|
|
58
59
|
const largerText = useLargerText();
|
|
59
|
-
const reduceMotion = useReduceMotion();
|
|
60
60
|
const rowHeight = largerText ? 56 : 48;
|
|
61
61
|
const body = chatTextSize("body", largerText);
|
|
62
|
-
// 0 to 1 as the menu opens
|
|
63
|
-
// entering
|
|
62
|
+
// 0 to 1 as the menu opens, started from the menu's first layout: a shared value runs in a
|
|
63
|
+
// layer and in the fallback Modal alike (Reanimated's entering does not run inside a Modal on Android).
|
|
64
64
|
const shown = useSharedValue(0);
|
|
65
65
|
const popStyle = useAnimatedStyle(() => ({ transform: [{ scale: PANEL_SCALE_FROM + (1 - PANEL_SCALE_FROM) * shown.get() }] }));
|
|
66
66
|
const liftStyle = useAnimatedStyle(() => ({ transform: [{ scale: 1 + (LIFT_SCALE - 1) * shown.get() }] }));
|
|
@@ -92,8 +92,9 @@ export function MessageContextMenu({
|
|
|
92
92
|
const pillWidth = Math.min(window.width - 2 * MESSAGE_MENU.edge, (menu.reactions?.items.length ?? 0) * 48 + 16);
|
|
93
93
|
|
|
94
94
|
return (
|
|
95
|
-
//
|
|
96
|
-
|
|
95
|
+
// In the app's window (`WindowLayer`): a Modal's own window moved the focus on Android, and the chat
|
|
96
|
+
// list's keyboard handling scrolled to the newest message as it opened and closed.
|
|
97
|
+
<WindowLayer onRequestClose={onClose} onDismiss={onDismissed}>
|
|
97
98
|
<View style={{ flex: 1 }} testID={testID} accessibilityViewIsModal onAccessibilityEscape={onClose} onLayout={appear}>
|
|
98
99
|
<View style={StyleSheet.absoluteFill}>
|
|
99
100
|
<Pressable
|
|
@@ -191,7 +192,7 @@ export function MessageContextMenu({
|
|
|
191
192
|
))}
|
|
192
193
|
</Animated.View>
|
|
193
194
|
</View>
|
|
194
|
-
</
|
|
195
|
+
</WindowLayer>
|
|
195
196
|
);
|
|
196
197
|
}
|
|
197
198
|
|
|
@@ -168,3 +168,6 @@ export type { SheetProps, SheetContentProps } from "../Sheet";
|
|
|
168
168
|
export { Toaster } from "../Toast";
|
|
169
169
|
export { toast } from "../toastStore";
|
|
170
170
|
export type { ToastOptions, ToastVariant } from "../toastStore";
|
|
171
|
+
|
|
172
|
+
// Overlays in the app's window (the hold menu, the image viewer): wrap the navigator once.
|
|
173
|
+
export { WindowLayerHost } from "../primitives/window-layer";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { useContext, useState, type ReactNode } from "react";
|
|
2
|
-
import { FlatList, Image,
|
|
2
|
+
import { FlatList, Image, Pressable, Text, View, useWindowDimensions } from "react-native";
|
|
3
3
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
4
4
|
import { IconExternalLink, IconX } from "@tabler/icons-react-native";
|
|
5
5
|
import { typeStyle } from "../controlStyles";
|
|
6
|
+
import { WindowLayer } from "../primitives/window-layer";
|
|
6
7
|
import { IconButton } from "../IconButton";
|
|
7
8
|
import { withAlpha } from "../palette";
|
|
8
9
|
import { tokens } from "../tokens";
|
|
9
|
-
import { useReduceMotion } from "../useReduceMotion";
|
|
10
10
|
import { useScheme } from "../useScheme";
|
|
11
11
|
import { ZoomImageContext } from "./zoomImage";
|
|
12
12
|
import { imageAspect, imageGridTiles, imageViewerPage, MEDIA, type GalleryImage, type ImageGridTile } from "./imageGrid";
|
|
@@ -156,14 +156,15 @@ export type ImageViewerProps = {
|
|
|
156
156
|
* at once with Reduce Motion.
|
|
157
157
|
*/
|
|
158
158
|
export function ImageViewer({ images, index, onIndexChange, onClose, onOpenImage }: ImageViewerProps) {
|
|
159
|
-
const reduceMotion = useReduceMotion();
|
|
160
159
|
if (index === null) return null;
|
|
161
160
|
return (
|
|
162
|
-
|
|
161
|
+
// In the app's window (`WindowLayer`): a Modal's own window moved the focus on Android, and a chat
|
|
162
|
+
// list under the viewer scrolled to its newest message as it opened and closed.
|
|
163
|
+
<WindowLayer onRequestClose={onClose}>
|
|
163
164
|
<ViewerRoot>
|
|
164
165
|
<ViewerPages images={images} index={index} onIndexChange={onIndexChange} onClose={onClose} onOpenImage={onOpenImage} />
|
|
165
166
|
</ViewerRoot>
|
|
166
|
-
</
|
|
167
|
+
</WindowLayer>
|
|
167
168
|
);
|
|
168
169
|
}
|
|
169
170
|
|