@vvedantb/native-ui 0.27.0 → 0.29.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/README.md +3 -3
- package/dist/DropdownMenu.jsx +26 -12
- package/dist/ai/conversation-context.js +2 -0
- package/dist/ai/conversation.jsx +31 -7
- 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/overlay.jsx +31 -17
- package/dist/primitives/window-layer.jsx +230 -0
- package/package.json +1 -1
- package/src/DropdownMenu.tsx +13 -12
- package/src/ai/conversation-context.ts +3 -0
- package/src/ai/conversation.tsx +21 -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/overlay.tsx +18 -18
- package/src/primitives/window-layer.tsx +159 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import * as Slot from "@rn-primitives/slot";
|
|
3
3
|
import { createContext, Fragment, useContext, useEffect, useState } from "react";
|
|
4
|
-
import {
|
|
4
|
+
import { Pressable, StyleSheet } from "react-native";
|
|
5
5
|
import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
|
|
6
6
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
7
7
|
import { palette } from "../palette";
|
|
@@ -11,6 +11,7 @@ import { useReduceMotion } from "../useReduceMotion";
|
|
|
11
11
|
import { useScheme } from "../useScheme";
|
|
12
12
|
import { SheetDragProvider, SheetGestureContext, slideSheetIn, slideSheetOut, useSheetBackdropStyle, useSheetDragState } from "./sheet-drag";
|
|
13
13
|
import { useControllableState } from "./use-controllable-state";
|
|
14
|
+
import { WindowLayer } from "./window-layer";
|
|
14
15
|
const OverlayContext = createContext(null);
|
|
15
16
|
export function useOverlay(part) {
|
|
16
17
|
const context = useContext(OverlayContext);
|
|
@@ -150,25 +151,26 @@ export function OverlayClose(props) {
|
|
|
150
151
|
}
|
|
151
152
|
|
|
152
153
|
/**
|
|
153
|
-
*
|
|
154
|
+
* A `WindowLayer` (in the app's window under `WindowLayerHost`, so a chat
|
|
155
|
+
* under it keeps its place; else a `Modal`) with a tinted backdrop, safe-area padding and keyboard avoidance
|
|
154
156
|
* (`KeyboardAvoidingView`: frame by frame with `KeyboardControllerProvider`).
|
|
155
157
|
* `placement="center"` centres the child (dialogs) inside the insets on every
|
|
156
158
|
* side: the backdrop fades while the panel scales from 0.96 and fades in (200
|
|
157
|
-
* ms on open, 150 ms on close), and the
|
|
159
|
+
* ms on open, 150 ms on close), and the layer stays up until it is out of
|
|
158
160
|
* sight. `"bottom"` pins it to the bottom
|
|
159
161
|
* edge (sheets), which pad their own bottom inset: the sheet slides up on
|
|
160
162
|
* open and back down on close, however it closes, and may be dragged down to
|
|
161
163
|
* close (`SheetDragView`); the backdrop fades with the sheet's position. The
|
|
162
|
-
*
|
|
164
|
+
* layer stays up until the sheet is out of sight. The backdrop closes the
|
|
163
165
|
* overlay only when `dismissible`; Android back and the VoiceOver escape
|
|
164
166
|
* gesture always close it, as Escape does on the web. With Reduce Motion on,
|
|
165
167
|
* overlays appear and leave in place. With the Gesture Handler parts
|
|
166
168
|
* (`GestureHandlerProvider`), the content sits in its own root view: on
|
|
167
169
|
* Android a `Modal` is a separate root, and without one there every gesture
|
|
168
|
-
* in it silently does nothing.
|
|
170
|
+
* in it silently does nothing (the fallback `Modal`).
|
|
169
171
|
*/
|
|
170
172
|
export function OverlayModal(t0) {
|
|
171
|
-
const $ = _c(
|
|
173
|
+
const $ = _c(22);
|
|
172
174
|
const {
|
|
173
175
|
part,
|
|
174
176
|
placement,
|
|
@@ -176,10 +178,11 @@ export function OverlayModal(t0) {
|
|
|
176
178
|
onShow,
|
|
177
179
|
children
|
|
178
180
|
} = t0;
|
|
181
|
+
const overlay = useOverlay(part);
|
|
179
182
|
const {
|
|
180
183
|
open,
|
|
181
184
|
setOpen
|
|
182
|
-
} =
|
|
185
|
+
} = overlay;
|
|
183
186
|
const reduceMotion = useReduceMotion();
|
|
184
187
|
const slides = placement === "bottom" && !reduceMotion;
|
|
185
188
|
const scales = placement === "center" && !reduceMotion;
|
|
@@ -200,6 +203,9 @@ export function OverlayModal(t0) {
|
|
|
200
203
|
}
|
|
201
204
|
const close = t1;
|
|
202
205
|
const ModalRoot = useContext(SheetGestureContext)?.ModalRoot ?? Fragment;
|
|
206
|
+
if (!shown) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
203
209
|
let t2;
|
|
204
210
|
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
|
205
211
|
t2 = () => setShown(false);
|
|
@@ -232,20 +238,28 @@ export function OverlayModal(t0) {
|
|
|
232
238
|
t4 = $[14];
|
|
233
239
|
}
|
|
234
240
|
let t5;
|
|
235
|
-
if ($[15] !==
|
|
236
|
-
t5 = <
|
|
237
|
-
$[15] =
|
|
238
|
-
$[16] =
|
|
239
|
-
$[17] =
|
|
240
|
-
|
|
241
|
-
$[
|
|
241
|
+
if ($[15] !== overlay || $[16] !== t4) {
|
|
242
|
+
t5 = <OverlayContext.Provider value={overlay}>{t4}</OverlayContext.Provider>;
|
|
243
|
+
$[15] = overlay;
|
|
244
|
+
$[16] = t4;
|
|
245
|
+
$[17] = t5;
|
|
246
|
+
} else {
|
|
247
|
+
t5 = $[17];
|
|
248
|
+
}
|
|
249
|
+
let t6;
|
|
250
|
+
if ($[18] !== close || $[19] !== onShow || $[20] !== t5) {
|
|
251
|
+
t6 = <WindowLayer onRequestClose={close} onShow={onShow} fade={false}>{t5}</WindowLayer>;
|
|
252
|
+
$[18] = close;
|
|
253
|
+
$[19] = onShow;
|
|
254
|
+
$[20] = t5;
|
|
255
|
+
$[21] = t6;
|
|
242
256
|
} else {
|
|
243
|
-
|
|
257
|
+
t6 = $[21];
|
|
244
258
|
}
|
|
245
|
-
return
|
|
259
|
+
return t6;
|
|
246
260
|
}
|
|
247
261
|
|
|
248
|
-
/** The
|
|
262
|
+
/** The layer's content: mounted with each opening, so a sheet starts below the screen (or at rest). */
|
|
249
263
|
function OverlayModalBody(t0) {
|
|
250
264
|
const $ = _c(48);
|
|
251
265
|
const {
|
|
@@ -0,0 +1,230 @@
|
|
|
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
|
+
|
|
33
|
+
// Layers that have called `onShow` once, as a Modal does once per opening.
|
|
34
|
+
const announced = new Set();
|
|
35
|
+
const showOnce = layer => {
|
|
36
|
+
if (announced.has(layer.id)) return;
|
|
37
|
+
announced.add(layer.id);
|
|
38
|
+
layer.onShow?.();
|
|
39
|
+
};
|
|
40
|
+
const remove = id => {
|
|
41
|
+
announced.delete(id);
|
|
42
|
+
if (!layers.some(item => item.id === id)) return;
|
|
43
|
+
layers = layers.filter(item => item.id !== id);
|
|
44
|
+
emit();
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// Android back closes the newest layer, as a Modal's `onRequestClose`.
|
|
48
|
+
const onBack = () => {
|
|
49
|
+
const top = layers[layers.length - 1];
|
|
50
|
+
if (!top) return false;
|
|
51
|
+
top.onRequestClose();
|
|
52
|
+
return true;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** Mounted: the host is there, and it answers Android back for its layers. */
|
|
56
|
+
const hostRef = view => {
|
|
57
|
+
if (view === null) return undefined;
|
|
58
|
+
hosts += 1;
|
|
59
|
+
const back = BackHandler.addEventListener("hardwareBackPress", onBack);
|
|
60
|
+
emit();
|
|
61
|
+
return () => {
|
|
62
|
+
hosts -= 1;
|
|
63
|
+
back.remove();
|
|
64
|
+
emit();
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Wrap the app once (inside `NativeUiProvider`, around the navigator): the
|
|
70
|
+
* `WindowLayer`s draw over it, in the same window. While a layer shows, the
|
|
71
|
+
* app under it is hidden from TalkBack and VoiceOver, as under a Modal.
|
|
72
|
+
*/
|
|
73
|
+
export function WindowLayerHost(t0) {
|
|
74
|
+
const $ = _c(12);
|
|
75
|
+
const {
|
|
76
|
+
children
|
|
77
|
+
} = t0;
|
|
78
|
+
const shown = useSyncExternalStore(subscribe, _temp, _temp2);
|
|
79
|
+
let t1;
|
|
80
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
81
|
+
t1 = FadeIn.duration(200).reduceMotion(ReduceMotion.System);
|
|
82
|
+
$[0] = t1;
|
|
83
|
+
} else {
|
|
84
|
+
t1 = $[0];
|
|
85
|
+
}
|
|
86
|
+
const enter = t1;
|
|
87
|
+
let t2;
|
|
88
|
+
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
|
89
|
+
t2 = FadeOut.duration(150).reduceMotion(ReduceMotion.System);
|
|
90
|
+
$[1] = t2;
|
|
91
|
+
} else {
|
|
92
|
+
t2 = $[1];
|
|
93
|
+
}
|
|
94
|
+
const exit = t2;
|
|
95
|
+
const t3 = shown.length > 0 ? "no-hide-descendants" : "auto";
|
|
96
|
+
const t4 = shown.length > 0;
|
|
97
|
+
let t5;
|
|
98
|
+
if ($[2] !== children || $[3] !== t3 || $[4] !== t4) {
|
|
99
|
+
t5 = <View style={styles.fill} importantForAccessibility={t3} accessibilityElementsHidden={t4}>{children}</View>;
|
|
100
|
+
$[2] = children;
|
|
101
|
+
$[3] = t3;
|
|
102
|
+
$[4] = t4;
|
|
103
|
+
$[5] = t5;
|
|
104
|
+
} else {
|
|
105
|
+
t5 = $[5];
|
|
106
|
+
}
|
|
107
|
+
let t6;
|
|
108
|
+
if ($[6] !== shown) {
|
|
109
|
+
let t7;
|
|
110
|
+
if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
|
|
111
|
+
t7 = layer => <Animated.View key={layer.id} entering={layer.fade ? enter : undefined} exiting={layer.fade ? exit : undefined} onLayout={() => showOnce(layer)} style={StyleSheet.absoluteFill} pointerEvents="box-none">{layer.node}</Animated.View>;
|
|
112
|
+
$[8] = t7;
|
|
113
|
+
} else {
|
|
114
|
+
t7 = $[8];
|
|
115
|
+
}
|
|
116
|
+
t6 = shown.map(t7);
|
|
117
|
+
$[6] = shown;
|
|
118
|
+
$[7] = t6;
|
|
119
|
+
} else {
|
|
120
|
+
t6 = $[7];
|
|
121
|
+
}
|
|
122
|
+
let t7;
|
|
123
|
+
if ($[9] !== t5 || $[10] !== t6) {
|
|
124
|
+
t7 = <View ref={hostRef} style={styles.fill}>{t5}{t6}</View>;
|
|
125
|
+
$[9] = t5;
|
|
126
|
+
$[10] = t6;
|
|
127
|
+
$[11] = t7;
|
|
128
|
+
} else {
|
|
129
|
+
t7 = $[11];
|
|
130
|
+
}
|
|
131
|
+
return t7;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* An overlay over the whole app, in its own window only when it must be: in
|
|
136
|
+
* `WindowLayerHost` when the app has one, else a transparent `Modal` (with
|
|
137
|
+
* `onDismiss` there). Render it only while the overlay shows. Android back
|
|
138
|
+
* calls `onRequestClose`. Its children keep the providers above the host, not
|
|
139
|
+
* those between the host and this element: an overlay with its own context
|
|
140
|
+
* (a Dialog's open state, a menu's) provides it again inside.
|
|
141
|
+
*/
|
|
142
|
+
function _temp2() {
|
|
143
|
+
return EMPTY;
|
|
144
|
+
}
|
|
145
|
+
function _temp() {
|
|
146
|
+
return layers;
|
|
147
|
+
}
|
|
148
|
+
export function WindowLayer(t0) {
|
|
149
|
+
const $ = _c(17);
|
|
150
|
+
const {
|
|
151
|
+
onRequestClose,
|
|
152
|
+
onDismiss,
|
|
153
|
+
onShow,
|
|
154
|
+
fade: t1,
|
|
155
|
+
children
|
|
156
|
+
} = t0;
|
|
157
|
+
const fade = t1 === undefined ? true : t1;
|
|
158
|
+
const id = useId();
|
|
159
|
+
const reduceMotion = useReduceMotion();
|
|
160
|
+
const hosted = useSyncExternalStore(subscribe, _temp3, _temp4);
|
|
161
|
+
let t2;
|
|
162
|
+
let t3;
|
|
163
|
+
if ($[0] !== children || $[1] !== fade || $[2] !== hosted || $[3] !== id || $[4] !== onRequestClose || $[5] !== onShow) {
|
|
164
|
+
t2 = () => {
|
|
165
|
+
if (hosted) {
|
|
166
|
+
upsert({
|
|
167
|
+
id,
|
|
168
|
+
node: children,
|
|
169
|
+
onRequestClose,
|
|
170
|
+
onShow,
|
|
171
|
+
fade
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
t3 = [hosted, id, children, onRequestClose, onShow, fade];
|
|
176
|
+
$[0] = children;
|
|
177
|
+
$[1] = fade;
|
|
178
|
+
$[2] = hosted;
|
|
179
|
+
$[3] = id;
|
|
180
|
+
$[4] = onRequestClose;
|
|
181
|
+
$[5] = onShow;
|
|
182
|
+
$[6] = t2;
|
|
183
|
+
$[7] = t3;
|
|
184
|
+
} else {
|
|
185
|
+
t2 = $[6];
|
|
186
|
+
t3 = $[7];
|
|
187
|
+
}
|
|
188
|
+
useLayoutEffect(t2, t3);
|
|
189
|
+
let t4;
|
|
190
|
+
let t5;
|
|
191
|
+
if ($[8] !== id) {
|
|
192
|
+
t4 = () => () => remove(id);
|
|
193
|
+
t5 = [id];
|
|
194
|
+
$[8] = id;
|
|
195
|
+
$[9] = t4;
|
|
196
|
+
$[10] = t5;
|
|
197
|
+
} else {
|
|
198
|
+
t4 = $[9];
|
|
199
|
+
t5 = $[10];
|
|
200
|
+
}
|
|
201
|
+
useLayoutEffect(t4, t5);
|
|
202
|
+
if (hosted) {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
const t6 = fade && !reduceMotion ? "fade" : "none";
|
|
206
|
+
let t7;
|
|
207
|
+
if ($[11] !== children || $[12] !== onDismiss || $[13] !== onRequestClose || $[14] !== onShow || $[15] !== t6) {
|
|
208
|
+
t7 = <Modal visible={true} transparent={true} statusBarTranslucent={true} animationType={t6} onRequestClose={onRequestClose} onDismiss={onDismiss} onShow={onShow}>{children}</Modal>;
|
|
209
|
+
$[11] = children;
|
|
210
|
+
$[12] = onDismiss;
|
|
211
|
+
$[13] = onRequestClose;
|
|
212
|
+
$[14] = onShow;
|
|
213
|
+
$[15] = t6;
|
|
214
|
+
$[16] = t7;
|
|
215
|
+
} else {
|
|
216
|
+
t7 = $[16];
|
|
217
|
+
}
|
|
218
|
+
return t7;
|
|
219
|
+
}
|
|
220
|
+
function _temp4() {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
function _temp3() {
|
|
224
|
+
return hosts > 0;
|
|
225
|
+
}
|
|
226
|
+
const styles = StyleSheet.create({
|
|
227
|
+
fill: {
|
|
228
|
+
flex: 1
|
|
229
|
+
}
|
|
230
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/native-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.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",
|
package/src/DropdownMenu.tsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as Slot from "@rn-primitives/slot";
|
|
2
2
|
import { createContext, useContext, useEffect, useRef, useState, type ComponentType, type ReactNode } from "react";
|
|
3
3
|
import {
|
|
4
|
-
Modal,
|
|
5
4
|
Pressable,
|
|
6
5
|
ScrollView,
|
|
7
6
|
StyleSheet,
|
|
@@ -26,6 +25,7 @@ import { tokens } from "./tokens";
|
|
|
26
25
|
import { useReduceMotion } from "./useReduceMotion";
|
|
27
26
|
import { useScheme } from "./useScheme";
|
|
28
27
|
import { useControllableState } from "./primitives/use-controllable-state";
|
|
28
|
+
import { WindowLayer } from "./primitives/window-layer";
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Sizes from the web menu classes (`_menu-classes.ts`): content `min-w-[12rem]
|
|
@@ -193,7 +193,8 @@ export type DropdownMenuContentProps = ViewProps & {
|
|
|
193
193
|
};
|
|
194
194
|
|
|
195
195
|
/**
|
|
196
|
-
* The menu in a
|
|
196
|
+
* The menu in a `WindowLayer` (in the app's window under `WindowLayerHost`, so
|
|
197
|
+
* a chat under it keeps its place; else a transparent `Modal`): the opaque overlay surface of
|
|
197
198
|
* `Dialog` and `Sheet` (`FloatingSurface` without blur, with the floating
|
|
198
199
|
* shadow) at radius 16, at least 192 wide, `p-1.5`, scrolling when taller than
|
|
199
200
|
* the room. A tap outside, Android back and the VoiceOver escape gesture close
|
|
@@ -209,7 +210,8 @@ export function DropdownMenuContent({
|
|
|
209
210
|
children,
|
|
210
211
|
...props
|
|
211
212
|
}: DropdownMenuContentProps) {
|
|
212
|
-
const
|
|
213
|
+
const menu = useMenu("DropdownMenuContent");
|
|
214
|
+
const { open, setOpen, trigger } = menu;
|
|
213
215
|
const window = useWindowDimensions();
|
|
214
216
|
const insets = useSafeAreaInsets();
|
|
215
217
|
const reduceMotion = useReduceMotion();
|
|
@@ -265,16 +267,14 @@ export function DropdownMenuContent({
|
|
|
265
267
|
// The scale grows from the corner nearest the trigger: its edge on the
|
|
266
268
|
// trigger's (`align`), and the top, or the bottom when the menu flipped above.
|
|
267
269
|
const transformOrigin = `${align === "end" ? 100 : 0}% ${position.bottom === undefined ? 0 : 100}%`;
|
|
270
|
+
if (!shown) return null;
|
|
268
271
|
return (
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
statusBarTranslucent
|
|
274
|
-
onRequestClose={close}
|
|
275
|
-
>
|
|
272
|
+
// The panel runs its own motion, so no fade; the items need the menu's
|
|
273
|
+
// context, which a layer loses, so it is provided again.
|
|
274
|
+
<WindowLayer onRequestClose={close} fade={false}>
|
|
275
|
+
<MenuContext.Provider value={menu}>
|
|
276
276
|
{/* A full-size host, as `OverlayModal` has: without it the backdrop and the
|
|
277
|
-
menu are bare
|
|
277
|
+
menu are bare layer children with no box to size or hit-test against,
|
|
278
278
|
and the menu can stack under tab bars and glass layers. */}
|
|
279
279
|
<View style={{ flex: 1 }} pointerEvents="box-none">
|
|
280
280
|
<Pressable
|
|
@@ -314,7 +314,8 @@ export function DropdownMenuContent({
|
|
|
314
314
|
</Animated.View>
|
|
315
315
|
</View>
|
|
316
316
|
</View>
|
|
317
|
-
|
|
317
|
+
</MenuContext.Provider>
|
|
318
|
+
</WindowLayer>
|
|
318
319
|
);
|
|
319
320
|
}
|
|
320
321
|
|
|
@@ -9,10 +9,13 @@ import type { NativeScrollEvent } from "react-native";
|
|
|
9
9
|
* the `FlatList` of `ConversationList`. `scrollToEnd` goes to the newest
|
|
10
10
|
* message, which is offset 0 in an inverted list. `scrollTo` goes to an
|
|
11
11
|
* offset; only the `ScrollView` has it, so call it as `scrollTo?.(...)`.
|
|
12
|
+
* `scrollToIndex` brings one row of the list's `data` into view (a find in
|
|
13
|
+
* the thread); only the `FlatList` has it. `viewPosition` 0.5 centres it.
|
|
12
14
|
*/
|
|
13
15
|
export type ConversationScroller = {
|
|
14
16
|
scrollToEnd: (options?: { animated?: boolean }) => void;
|
|
15
17
|
scrollTo?: (options: { y: number; animated?: boolean }) => void;
|
|
18
|
+
scrollToIndex?: (options: { index: number; animated?: boolean; viewPosition?: number }) => void;
|
|
16
19
|
};
|
|
17
20
|
|
|
18
21
|
export type ConversationContextValue = {
|
package/src/ai/conversation.tsx
CHANGED
|
@@ -255,6 +255,9 @@ export function ConversationList<T>({
|
|
|
255
255
|
// when inverted); `keyboardMoving` is true while the keyboard scrolls the
|
|
256
256
|
// list, which is not the reader leaving the bottom.
|
|
257
257
|
const size = useRef({ content: 0, view: 0, inset: 0, keyboardMoving: false });
|
|
258
|
+
// The list, and the row `scrollToIndex` last asked for, for its retry when that row was not drawn.
|
|
259
|
+
const listRef = useRef<FlatList<T> | null>(null);
|
|
260
|
+
const indexTarget = useRef<{ index: number; animated?: boolean; viewPosition?: number; tries: number } | null>(null);
|
|
258
261
|
// Not inverted: hidden until the first jump to the end (see above). An
|
|
259
262
|
// empty list (a spinner, an empty state) shows at once.
|
|
260
263
|
const hasRows = (props.data?.length ?? 0) > 0;
|
|
@@ -328,9 +331,27 @@ export function ConversationList<T>({
|
|
|
328
331
|
)
|
|
329
332
|
: props.renderScrollComponent
|
|
330
333
|
}
|
|
334
|
+
// A row the list has not drawn yet (it draws only those near the view):
|
|
335
|
+
// go to its estimated offset, which draws it, then to the row itself.
|
|
336
|
+
onScrollToIndexFailed={
|
|
337
|
+
props.onScrollToIndexFailed ??
|
|
338
|
+
((info) => {
|
|
339
|
+
const list = listRef.current;
|
|
340
|
+
const target = indexTarget.current;
|
|
341
|
+
if (!list || !target || target.index !== info.index || target.tries >= 3) return;
|
|
342
|
+
target.tries += 1;
|
|
343
|
+
list.scrollToOffset({ offset: info.averageItemLength * info.index, animated: false });
|
|
344
|
+
requestAnimationFrame(() => list.scrollToIndex(target));
|
|
345
|
+
})
|
|
346
|
+
}
|
|
331
347
|
ref={(list: FlatList<T> | null) => {
|
|
348
|
+
listRef.current = list;
|
|
332
349
|
conversation.scrollRef.current = list && {
|
|
333
350
|
scrollToEnd: (options) => list.scrollToOffset({ offset: end(), animated: options?.animated }),
|
|
351
|
+
scrollToIndex: (options) => {
|
|
352
|
+
indexTarget.current = { ...options, tries: 0 };
|
|
353
|
+
list.scrollToIndex(options);
|
|
354
|
+
},
|
|
334
355
|
};
|
|
335
356
|
}}
|
|
336
357
|
/>
|
|
@@ -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
|
|