@marktiderman/genesis-chat 0.8.0 → 0.10.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.
@@ -1,13 +1,15 @@
1
1
  // @vitest-environment happy-dom
2
2
  // @feat:chat
3
3
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
4
- import { act, cleanup, render, waitFor } from "@testing-library/react";
5
- import type { ReactNode } from "react";
4
+ import { act, cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
5
+ import { forwardRef, useImperativeHandle, type ReactNode } from "react";
6
+ import { AccessibilityInfo } from "react-native";
6
7
  import { afterEach, describe, expect, it, vi } from "vitest";
7
8
  import { GenesisModulesProvider, NativeToastProvider } from "@marktiderman/genesis-ui-native/components";
8
9
  import type { ChatClient } from "../../core/client";
9
10
  import type { ChatMessage } from "../../core/types";
10
11
  import { ChatProvider } from "../../react/index";
12
+ import { chatNativeCopy } from "../copy";
11
13
  import { ChatNativeProvider } from "../context";
12
14
  import type { ThreadRow } from "../rows";
13
15
  import { nearBottom, ChatThreadScreen, threadListMode } from "../thread-screen";
@@ -100,6 +102,106 @@ describe("ChatThreadScreen's list", () => {
100
102
  });
101
103
  });
102
104
 
105
+ /** A list that also takes the thread's scroll calls through its ref. */
106
+ function scrollingList() {
107
+ const seen: Record<string, unknown>[] = [];
108
+ const scrollToIndex = vi.fn();
109
+ const List = forwardRef<unknown, Record<string, unknown>>(function List(props, ref) {
110
+ seen.push(props);
111
+ useImperativeHandle(ref, () => ({ scrollToIndex, scrollToEnd: vi.fn(), scrollToOffset: vi.fn() }));
112
+ return null;
113
+ });
114
+ return { List, scrollToIndex, last: () => seen.at(-1)! };
115
+ }
116
+
117
+ describe("ChatThreadScreen's jump to a message", () => {
118
+ const messages = [msg(1, SAM, "2026-10-24T10:00:00Z"), msg(2, ME, "2026-10-24T10:01:00Z"), msg(3, SAM, "2026-10-24T10:02:00Z")];
119
+
120
+ it("goes to a message by its server id (rows are keyed by client id), centred, and says whose it is", async () => {
121
+ const announce = vi.fn();
122
+ (AccessibilityInfo as { announceForAccessibility?: unknown }).announceForAccessibility = announce;
123
+ const list = scrollingList();
124
+ render(wrap(fakeClient(messages, 3), list.List, <ChatThreadScreen conversationId={CONV} jumpTo={{ messageId: "m2", seq: 2 }} />));
125
+ await waitFor(() => expect(list.scrollToIndex).toHaveBeenCalled());
126
+ const { index, viewPosition } = list.scrollToIndex.mock.calls.at(-1)![0] as { index: number; viewPosition: number };
127
+ const row = (list.last().data as ThreadRow[])[index]!;
128
+ expect(row.key).toBe("c:c2");
129
+ expect(row.type === "message" && row.item.type === "message" ? row.item.message.id : null).toBe("m2");
130
+ expect(viewPosition).toBe(0.5);
131
+ expect(announce).toHaveBeenCalledWith("Message from You: body 2");
132
+ });
133
+
134
+ it("says so when the message isn't there and there's no seq to load back to", async () => {
135
+ const list = scrollingList();
136
+ render(wrap(fakeClient(messages, 3), list.List, <ChatThreadScreen conversationId={CONV} jumpTo={{ messageId: "m9" }} />));
137
+ expect(await screen.findByText("That message isn't here any more", {}, { timeout: 2000 })).toBeTruthy();
138
+ expect(list.scrollToIndex).not.toHaveBeenCalled();
139
+ });
140
+ });
141
+
142
+ describe("ChatThreadScreen's jump when it can't load back", () => {
143
+ it("says the load failed, not that the message is gone", async () => {
144
+ const list = scrollingList();
145
+ const client = fakeClient([msg(5, SAM, "2026-10-24T10:00:00Z")], 5);
146
+ (client.messages as ReturnType<typeof vi.fn>).mockResolvedValueOnce({ messages: [msg(5, SAM, "2026-10-24T10:00:00Z")], hasEarlier: true }).mockRejectedValue(new Error("offline"));
147
+ render(wrap(client, list.List, <ChatThreadScreen conversationId={CONV} jumpTo={{ messageId: "m2", seq: 2 }} />));
148
+ expect(await screen.findByText(chatNativeCopy.actionFailed, {}, { timeout: 2000 })).toBeTruthy();
149
+ await act(async () => void (await new Promise((r) => setTimeout(r, 600))));
150
+ expect(screen.queryByText(chatNativeCopy.messageGone)).toBeNull();
151
+ });
152
+
153
+ it("with a deep link and a first page that failed: says the read failed, never gone, and goes there once rows come", async () => {
154
+ const list = scrollingList();
155
+ const client = fakeClient([msg(1, SAM, "2026-10-24T10:00:00Z"), msg(2, ME, "2026-10-24T10:01:00Z")], 3);
156
+ (client.messages as ReturnType<typeof vi.fn>).mockRejectedValueOnce(new Error("offline"));
157
+ const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
158
+ render(
159
+ <QueryClientProvider client={qc}>
160
+ <GenesisModulesProvider modules={{ list: list.List as never }}>
161
+ <ChatProvider client={client} userId={ME}>
162
+ <NativeToastProvider>
163
+ <ChatNativeProvider>
164
+ <ChatThreadScreen conversationId={CONV} jumpTo={{ messageId: "m2" }} />
165
+ </ChatNativeProvider>
166
+ </NativeToastProvider>
167
+ </ChatProvider>
168
+ </GenesisModulesProvider>
169
+ </QueryClientProvider>,
170
+ );
171
+ expect(await screen.findByText(chatNativeCopy.actionFailed, {}, { timeout: 2000 })).toBeTruthy();
172
+ await act(async () => void (await new Promise((r) => setTimeout(r, 600))));
173
+ expect(screen.queryByText(chatNativeCopy.messageGone)).toBeNull();
174
+ expect(list.scrollToIndex).not.toHaveBeenCalled();
175
+ await act(async () => void (await qc.refetchQueries()));
176
+ await waitFor(() => expect(list.scrollToIndex).toHaveBeenCalled());
177
+ expect(screen.queryByText(chatNativeCopy.messageGone)).toBeNull();
178
+ });
179
+
180
+ it("keeps a deep link through a failed first page even with a message of yours waiting to send", async () => {
181
+ const list = scrollingList();
182
+ const client = fakeClient([msg(1, SAM, "2026-10-24T10:00:00Z"), msg(2, ME, "2026-10-24T10:01:00Z")], 3);
183
+ (client.messages as ReturnType<typeof vi.fn>).mockRejectedValueOnce(new Error("offline"));
184
+ (client as unknown as { send: unknown }).send = vi.fn(() => new Promise(() => undefined));
185
+ render(wrap(client, list.List, <ChatThreadScreen conversationId={CONV} jumpTo={{ messageId: "m2" }} testID="t" />));
186
+ await screen.findByText(chatNativeCopy.actionFailed, {}, { timeout: 2000 });
187
+ const input = await screen.findByTestId("t-composer-input");
188
+ await waitFor(() => expect(input.hasAttribute("disabled")).toBe(false));
189
+ fireEvent.change(input, { target: { value: "Still here" } });
190
+ fireEvent.click(screen.getByTestId("t-composer-send"));
191
+ await waitFor(() => expect((list.last().data as ThreadRow[] | undefined)?.some((r) => r.type === "message")).toBe(true));
192
+ await act(async () => void (await new Promise((r) => setTimeout(r, 600))));
193
+ expect(screen.queryByText(chatNativeCopy.messageGone)).toBeNull();
194
+ });
195
+
196
+ it("finds a deleted message: its tombstone is a row", async () => {
197
+ const list = scrollingList();
198
+ const deleted = { ...msg(2, SAM, "2026-10-24T10:01:00Z"), deletedAt: "2026-10-24T11:00:00Z" } as ChatMessage;
199
+ render(wrap(fakeClient([msg(1, SAM, "2026-10-24T10:00:00Z"), deleted], 3), list.List, <ChatThreadScreen conversationId={CONV} jumpTo={{ messageId: "m2", seq: 2 }} />));
200
+ await waitFor(() => expect(list.scrollToIndex).toHaveBeenCalled());
201
+ expect(screen.queryByText(chatNativeCopy.messageGone)).toBeNull();
202
+ });
203
+ });
204
+
103
205
  describe("threadListMode", () => {
104
206
  it("follows new rows by hand only on FlatList, which keeps its place for earlier rows", () => {
105
207
  expect(threadListMode(true, false)).toMatchObject({ followsByHand: false });
@@ -7,10 +7,13 @@
7
7
  * The emoji button opens the full picker, which types where the cursor is.
8
8
  * With `onRecordVideo`, a camera button opens the video recorder. When the
9
9
  * person can't post, it says why instead of taking input.
10
+ *
11
+ * The bar is genesis-ui-native's `NativeComposerBar`; this adds what's chat's: the draft, the
12
+ * attachments and reply above it, the mic in Send's place and the recording in the input's.
10
13
  */
11
14
  import { useEffect, useMemo, useRef, useState } from "react";
12
- import { PanResponder, Pressable, ScrollView, TextInput, View } from "react-native";
13
- import { NativeIcon, NativeImage, NativeListItem, NativeSheet, NativeText } from "@marktiderman/genesis-ui-native/components";
15
+ import { PanResponder, Pressable, ScrollView, View } from "react-native";
16
+ import { NativeComposerBar, NativeIcon, NativeImage, NativeListItem, NativeSheet, NativeText, useGenesisModules } from "@marktiderman/genesis-ui-native/components";
14
17
  import { useThemeRoles } from "@marktiderman/genesis-ui-native/hooks";
15
18
  import { CHAT_LIMITS, formatDuration, recordingLimitMs } from "../core/media";
16
19
  import type { LocalFile } from "../core/outbox";
@@ -94,6 +97,7 @@ function ComposerWithVoice(props: ChatComposerProps & { audio: ExpoAudioLike })
94
97
  function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo, onSchedule, placeholder, voice, userId, testID = "chat-composer" }: ChatComposerProps & { voice: Voice | null }) {
95
98
  const { modules, copy } = useChatNative();
96
99
  const colors = useThemeRoles();
100
+ const genesis = useGenesisModules();
97
101
  const { state, dispatch } = composer;
98
102
  const [attachOpen, setAttachOpen] = useState(false);
99
103
  const [canPaste, setCanPaste] = useState(false);
@@ -122,7 +126,8 @@ function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo,
122
126
  if (!sendable) return;
123
127
  const payload = composer.take();
124
128
  if (!payload) return;
125
- haptic(modules.haptics, "send");
129
+ // The bar taps when the app gave Genesis the module; chat's own covers an app that gave only chat.
130
+ if (!genesis.haptics) haptic(modules.haptics, "send");
126
131
  onSend(payload);
127
132
  };
128
133
 
@@ -175,15 +180,15 @@ function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo,
175
180
  }
176
181
  };
177
182
 
178
- return (
179
- <View testID={testID} style={{ backgroundColor: colors.groupedBackground, paddingHorizontal: 8, paddingTop: 6, paddingBottom: 6, gap: 6 }}>
183
+ const above = (
184
+ <>
180
185
  {notice ? (
181
- <NativeText testID={`${testID}-notice`} accessibilityLiveRegion="polite" preset="caption" style={{ color: colors.destructive, paddingHorizontal: 8 }}>
186
+ <NativeText testID={`${testID}-notice`} accessibilityLiveRegion="polite" preset="caption" style={{ color: colors.destructive, paddingHorizontal: 4 }}>
182
187
  {notice}
183
188
  </NativeText>
184
189
  ) : null}
185
190
  {state.replyTo ? (
186
- <View testID={`${testID}-reply`} style={{ flexDirection: "row", alignItems: "center", paddingLeft: 12, borderLeftWidth: 3, borderLeftColor: colors.tint, marginHorizontal: 4 }}>
191
+ <View testID={`${testID}-reply`} style={{ flexDirection: "row", alignItems: "center", paddingLeft: 12, borderLeftWidth: 3, borderLeftColor: colors.tint }}>
187
192
  <View style={{ flex: 1 }}>
188
193
  <NativeText preset="caption" style={{ color: colors.tint, fontWeight: "600" }}>
189
194
  {fill(copy.replyingTo, { name: state.replyTo.name })}
@@ -220,57 +225,44 @@ function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo,
220
225
  ))}
221
226
  </ScrollView>
222
227
  ) : null}
223
- <View style={{ flexDirection: "row", alignItems: "flex-end", gap: 4 }}>
224
- {recording && voice ? (
225
- <RecordingBar voice={voice} testID={testID} />
226
- ) : (
227
- <>
228
- {modules.imagePicker || modules.clipboard?.getImageAsync ? (
229
- <IconButton testID={`${testID}-attach`} icon="plus" label={copy.attach} onPress={() => void openAttach()} color={colors.tint} disabled={!ready} />
230
- ) : null}
231
- {onRecordVideo ? (
232
- <IconButton testID={`${testID}-video`} icon="video" label={copy.recordVideo} onPress={onRecordVideo} color={colors.tint} disabled={!ready} />
233
- ) : null}
234
- <TextInput
235
- testID={`${testID}-input`}
236
- value={state.text}
237
- onChangeText={(text) => {
238
- dispatch({ type: "text", text });
239
- if (text) signalTyping?.();
240
- }}
241
- onSelectionChange={(e) => {
242
- selection.current = e.nativeEvent.selection;
243
- }}
244
- placeholder={placeholder ?? copy.placeholder}
245
- placeholderTextColor={colors.tertiaryLabel as string}
246
- accessibilityLabel={placeholder ?? copy.placeholder}
247
- editable={ready}
248
- multiline
249
- maxLength={CHAT_LIMITS.bodyChars}
250
- style={{
251
- flex: 1,
252
- minHeight: 40,
253
- maxHeight: 140,
254
- paddingHorizontal: 14,
255
- paddingTop: 10,
256
- paddingBottom: 10,
257
- borderRadius: 20,
258
- fontSize: 17,
259
- color: colors.label as string,
260
- backgroundColor: colors.surface,
261
- }}
262
- />
263
- <IconButton testID={`${testID}-emoji`} icon="smile" label={copy.addEmoji} onPress={() => setEmojiOpen(true)} color={colors.secondaryLabel} disabled={!ready} />
264
- </>
265
- )}
266
- {sendable && !recording ? (
267
- <IconButton testID={`${testID}-send`} icon="arrow-up" label={copy.send} onPress={send} onLongPress={onSchedule} longPressLabel={onSchedule ? copy.schedule : undefined} filled color={colors.tint} />
268
- ) : voice ? (
269
- <MicButton voice={voice} testID={testID} disabled={!ready} />
270
- ) : (
271
- <IconButton testID={`${testID}-send`} icon="arrow-up" label={copy.send} onPress={send} filled color={colors.tint} disabled />
272
- )}
273
- </View>
228
+ </>
229
+ );
230
+ const canAttach = Boolean(modules.imagePicker || modules.clipboard?.getImageAsync);
231
+
232
+ return (
233
+ <>
234
+ <NativeComposerBar
235
+ testID={testID}
236
+ value={state.text}
237
+ onChangeText={(text) => {
238
+ dispatch({ type: "text", text });
239
+ if (text) signalTyping?.();
240
+ }}
241
+ onSelectionChange={(e) => {
242
+ selection.current = e.nativeEvent.selection;
243
+ }}
244
+ onSend={send}
245
+ // A recording sends itself: until it ends, the mic keeps Send's place, even over a written draft.
246
+ hasContent={sendable && !recording}
247
+ editable={ready}
248
+ placeholder={placeholder ?? copy.placeholder}
249
+ sendLabel={copy.send}
250
+ maxLength={CHAT_LIMITS.bodyChars}
251
+ sendActions={onSchedule ? [{ id: "schedule", label: copy.schedule, onPress: onSchedule }] : undefined}
252
+ sendActionsHint={copy.scheduleHoldHint}
253
+ above={above}
254
+ leading={
255
+ canAttach || onRecordVideo ? (
256
+ <View style={{ flexDirection: "row" }}>
257
+ {canAttach ? <IconButton testID={`${testID}-attach`} icon="plus" label={copy.attach} onPress={() => void openAttach()} color={colors.tint} disabled={!ready} /> : null}
258
+ {onRecordVideo ? <IconButton testID={`${testID}-video`} icon="video" label={copy.recordVideo} onPress={onRecordVideo} color={colors.tint} disabled={!ready} /> : null}
259
+ </View>
260
+ ) : null
261
+ }
262
+ trailing={recording ? null : <IconButton testID={`${testID}-emoji`} icon="smile" label={copy.addEmoji} onPress={() => setEmojiOpen(true)} color={colors.secondaryLabel} disabled={!ready} />}
263
+ idleAction={voice ? <MicButton voice={voice} testID={testID} disabled={!ready} /> : null}
264
+ replaceInput={recording && voice ? <RecordingBar voice={voice} testID={testID} /> : null}
265
+ />
274
266
  <ChatEmojiPickerSheet open={emojiOpen} onClose={() => setEmojiOpen(false)} onSelect={insertEmoji} userId={userId} testID={`${testID}-emoji-sheet`} />
275
267
  <NativeSheet open={attachOpen} onOpenChange={setAttachOpen} testID={`${testID}-attach-sheet`}>
276
268
  <View>
@@ -285,7 +277,7 @@ function ComposerBody({ composer, canPost, onSend, signalTyping, onRecordVideo,
285
277
  ) : null}
286
278
  </View>
287
279
  </NativeSheet>
288
- </View>
280
+ </>
289
281
  );
290
282
  }
291
283
 
@@ -294,24 +286,16 @@ function IconButton({
294
286
  label,
295
287
  onPress,
296
288
  color,
297
- filled = false,
298
289
  disabled = false,
299
- onLongPress,
300
- longPressLabel,
301
290
  testID,
302
291
  }: {
303
- icon: "plus" | "arrow-up" | "close" | "trash" | "mic" | "video" | "smile";
292
+ icon: "plus" | "close" | "trash" | "video" | "smile";
304
293
  label: string;
305
294
  onPress: () => void;
306
- onLongPress?: () => void;
307
- /** The long press as a VoiceOver / TalkBack action. */
308
- longPressLabel?: string;
309
295
  color: unknown;
310
- filled?: boolean;
311
296
  disabled?: boolean;
312
297
  testID: string;
313
298
  }) {
314
- const colors = useThemeRoles();
315
299
  return (
316
300
  <Pressable
317
301
  testID={testID}
@@ -320,19 +304,9 @@ function IconButton({
320
304
  accessibilityState={{ disabled }}
321
305
  disabled={disabled}
322
306
  onPress={onPress}
323
- onLongPress={onLongPress}
324
- delayLongPress={onLongPress ? 400 : undefined}
325
- accessibilityActions={onLongPress && longPressLabel ? [{ name: "longpress", label: longPressLabel }] : undefined}
326
- onAccessibilityAction={onLongPress ? (e) => e.nativeEvent.actionName === "longpress" && onLongPress() : undefined}
327
307
  style={{ width: 44, height: 44, alignItems: "center", justifyContent: "center", opacity: disabled ? 0.4 : 1 }}
328
308
  >
329
- {filled ? (
330
- <View style={{ width: 34, height: 34, borderRadius: 17, backgroundColor: color as string, alignItems: "center", justifyContent: "center" }}>
331
- <NativeIcon name={icon} size={18} color={colors.surface} weight="semibold" />
332
- </View>
333
- ) : (
334
- <NativeIcon name={icon} size={24} color={color as string} />
335
- )}
309
+ <NativeIcon name={icon} size={24} color={color as string} />
336
310
  </Pressable>
337
311
  );
338
312
  }
@@ -8,6 +8,7 @@
8
8
  import { createContext, useContext, useMemo, type ReactNode } from "react";
9
9
  import { usePeople } from "../react/index";
10
10
  import { resolveChatCopy, type ChatNativeCopy, type ChatNativeCopyOverrides } from "./copy";
11
+ import { useGenesisModules } from "@marktiderman/genesis-ui-native/components";
11
12
  import type { ChatNativeModules } from "./modules";
12
13
 
13
14
  export interface ChatPerson {
@@ -37,9 +38,15 @@ export interface ChatNativeProviderProps {
37
38
 
38
39
  /** Inside `ChatProvider` (from `/react`). Optional: without it there are no native extras and people are "Someone". */
39
40
  export function ChatNativeProvider({ modules = EMPTY_MODULES, copy, getPerson, children }: ChatNativeProviderProps) {
41
+ const { haptics: genesisHaptics } = useGenesisModules();
40
42
  const value = useMemo<ChatNativeContextValue>(
41
- () => ({ modules, copy: resolveChatCopy(copy), person: (id) => (id && getPerson ? getPerson(id) : undefined) }),
42
- [modules, copy, getPerson],
43
+ () => ({
44
+ // Chat's own haptics module, else the one the app gave Genesis, so it's passed once.
45
+ modules: modules.haptics || !genesisHaptics ? modules : { ...modules, haptics: genesisHaptics },
46
+ copy: resolveChatCopy(copy),
47
+ person: (id) => (id && getPerson ? getPerson(id) : undefined),
48
+ }),
49
+ [modules, genesisHaptics, copy, getPerson],
43
50
  );
44
51
  return <Context.Provider value={value}>{children}</Context.Provider>;
45
52
  }
@@ -16,7 +16,7 @@
16
16
  import { memo, useCallback, useMemo, useRef, useState } from "react";
17
17
  import { Animated, PanResponder, Pressable, View } from "react-native";
18
18
  import { NativeAvatar, NativeText } from "@marktiderman/genesis-ui-native/components";
19
- import { useThemeRoles } from "@marktiderman/genesis-ui-native/hooks";
19
+ import { sentBubbleColor, useThemeRoles } from "@marktiderman/genesis-ui-native/hooks";
20
20
  import { summarizeReactions } from "../core/thread";
21
21
  import type { ChatLinkPreview, ChatMessage, PendingFile } from "../core/types";
22
22
  import type { ChatAttachmentKind } from "../react/index";
@@ -269,7 +269,7 @@ function MessageBubbleImpl(props: MessageBubbleProps) {
269
269
  const quoted = quote && repliedTo ? repliedTo : null;
270
270
  // A message that is only app attachments the slot drew nothing for has nothing to show or read.
271
271
  const invisible = Boolean(message && !message.deletedAt && !body && !attachments.length && !preview && !quote && !moderation && cards.length && !shownCards.length);
272
- const bubbleColor = mine ? colors.tint : colors.surface;
272
+ const bubbleColor = mine ? sentBubbleColor(colors) : colors.surface;
273
273
  const fg = mine ? "text-primary-foreground" : undefined;
274
274
  const textStyle = mine ? { fontSize: 17, lineHeight: 22 } : { fontSize: 17, lineHeight: 22, color: colors.label };
275
275
 
@@ -278,7 +278,7 @@ function MessageBubbleImpl(props: MessageBubbleProps) {
278
278
  testID={testID}
279
279
  accessibilityElementsHidden={invisible || undefined}
280
280
  importantForAccessibility={invisible ? "no-hide-descendants" : undefined}
281
- style={{ paddingHorizontal: 8, paddingTop: row.groupStart ? 8 : 2, backgroundColor: props.highlighted ? colors.fill : undefined, display: invisible ? "none" : undefined }}
281
+ style={{ paddingTop: row.groupStart ? 8 : 2, borderRadius: 12, backgroundColor: props.highlighted ? colors.fill : undefined, display: invisible ? "none" : undefined }}
282
282
  >
283
283
  {row.showName && sender?.name ? (
284
284
  <NativeText preset="caption" style={{ marginLeft: group ? 48 : 12, marginBottom: 2, color: colors.secondaryLabel }}>
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * import * as Audio from "expo-audio"; // voice notes
8
8
  * import * as ImagePicker from "expo-image-picker"; // photos and videos
9
- * import * as Haptics from "expo-haptics"; // send and record
9
+ * import * as Haptics from "expo-haptics"; // send and record (Genesis's module is used when this is left out)
10
10
  * import * as Clipboard from "expo-clipboard"; // copy, paste a picture
11
11
  * import { KeyboardAvoidingView } from "react-native-keyboard-controller";
12
12
  * import AsyncStorage from "@react-native-async-storage/async-storage"; // drafts
@@ -22,6 +22,7 @@
22
22
  * The shapes follow the SDK 58 packages' own type declarations.
23
23
  */
24
24
  import type { ComponentType, ReactNode } from "react";
25
+ import { playHaptic, type HapticKind } from "@marktiderman/genesis-ui-native/hooks";
25
26
 
26
27
  /** `RecorderState` from expo-audio (`recorder.getStatus()`). */
27
28
  export interface RecorderStateLike {
@@ -255,23 +256,17 @@ export interface ChatNativeModules {
255
256
 
256
257
  export type HapticEvent = "send" | "record-start" | "record-lock" | "record-cancel" | "select" | "error";
257
258
 
259
+ /** What each of chat's moments plays, in genesis-ui-native's vocabulary. */
260
+ const HAPTIC_KIND: Record<HapticEvent, HapticKind> = {
261
+ send: "light",
262
+ "record-lock": "light",
263
+ "record-start": "medium",
264
+ select: "select",
265
+ error: "error",
266
+ "record-cancel": "warning",
267
+ };
268
+
258
269
  /** Plays a haptic when the app gave expo-haptics; never throws. */
259
270
  export function haptic(haptics: HapticsLike | undefined, event: HapticEvent): void {
260
- if (!haptics) return;
261
- try {
262
- const style = (s: unknown) => s as never;
263
- const p =
264
- event === "send" || event === "record-lock"
265
- ? haptics.impactAsync(style(haptics.ImpactFeedbackStyle.Light))
266
- : event === "record-start"
267
- ? haptics.impactAsync(style(haptics.ImpactFeedbackStyle.Medium))
268
- : event === "select"
269
- ? haptics.selectionAsync()
270
- : haptics.notificationAsync(
271
- style(event === "error" ? haptics.NotificationFeedbackType.Error : haptics.NotificationFeedbackType.Warning),
272
- );
273
- void p?.catch?.(() => undefined);
274
- } catch {
275
- // A haptic is never worth an error.
276
- }
271
+ playHaptic(haptics, HAPTIC_KIND[event]);
277
272
  }
@@ -25,6 +25,8 @@ export interface ChatOrganiseCopy {
25
25
  topicReopenedDone: string;
26
26
  // Scheduled send
27
27
  schedule: string;
28
+ /** The hint on Send when it can schedule. */
29
+ scheduleHoldHint: string;
28
30
  scheduleTitle: string;
29
31
  scheduleHint: string;
30
32
  schedulePick: string;
@@ -122,6 +124,7 @@ export const chatOrganiseCopy: ChatOrganiseCopy = {
122
124
  topicClosedDone: "Closed {name}",
123
125
  topicReopenedDone: "Reopened {name}",
124
126
  schedule: "Schedule message",
127
+ scheduleHoldHint: "Touch and hold to schedule",
125
128
  scheduleTitle: "Schedule message",
126
129
  scheduleHint: "It sends at this time, in your time zone, as if you'd sent it then.",
127
130
  schedulePick: "Pick a date and time",