opendesk-react-native 0.1.3 → 0.1.6

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 CHANGED
@@ -47,6 +47,23 @@ Both adapters store the token as *after first unlock, this device only*. It's re
47
47
 
48
48
  Leave `storage` out and the token lives in memory only, so every launch starts a new visitor. Any `{ getItem, setItem, removeItem }` object also works. AsyncStorage fits that shape, but it writes plain text, so don't use it for this.
49
49
 
50
+ ## Reply sound
51
+
52
+ The SDK can play the web widget's reply chime when an agent or AI replies in a conversation the visitor doesn't have open. It follows the widget's **Sound** setting in openDesk, the same as on the web. Install `expo-audio` and pass it in:
53
+
54
+ ```tsx
55
+ // npx expo install expo-audio
56
+ import * as ExpoAudio from 'expo-audio';
57
+ import { expoAudioSound } from 'opendesk-react-native';
58
+
59
+ export const support = new OpenDesk({
60
+ // …
61
+ sound: expoAudioSound(ExpoAudio), // or expoAudioSound(ExpoAudio, { volume: 0.5 })
62
+ });
63
+ ```
64
+
65
+ The chime ships with the package (`assets/chime.wav`). The SDK leaves your app's audio mode alone; under expo-audio's default the chime mixes with other audio rather than pausing it. To play something else, pass any function as `sound`. Leave `sound` out for no sound.
66
+
50
67
  ## Identify the signed-in user
51
68
 
52
69
  To attach chats to a known contact, pass `{ user_id, user_hash, email, name }` as `identity`. `user_hash` is `hex(HMAC-SHA256(widget_secret, user_id))`, as described in [Identity verification](https://docs.opendesk.sh/guides/live-chat/identity-verification/). Compute it on your server, never in the app, and serve it from an authenticated endpoint of your own:
@@ -76,7 +93,6 @@ import { OpenDeskChat, OpenDeskLauncher } from 'opendesk-react-native';
76
93
 
77
94
  <OpenDeskChat
78
95
  onClose={() => navigation.goBack()}
79
- keyboardVerticalOffset={headerHeight}
80
96
  pickAttachment={async () => {
81
97
  const result = await DocumentPicker.getDocumentAsync({ type: ['image/*', 'application/pdf'] });
82
98
  const file = result.assets?.[0];
@@ -93,6 +109,14 @@ import { OpenDeskChat, OpenDeskLauncher } from 'opendesk-react-native';
93
109
  - `accentColor`
94
110
  - `strings`: replaces any of the built-in English copy (`defaultStrings` lists every key)
95
111
  - `initialConversationId`
112
+ - `keyboardVerticalOffset`: extra space between the composer and the keyboard (see below)
113
+
114
+ The chat keeps its composer above the keyboard by measuring where it sits on screen, so it needs no offset under a navigation header. Two cases it can't measure past:
115
+
116
+ - **React Native's `<Modal>` on Android** is a separate window that gets no keyboard events, so the composer stays under the keyboard. Show the chat as a screen, or as a full-screen view over your app, instead.
117
+ - **An iOS page sheet** (`presentationStyle="pageSheet"`, or a sheet-style navigation modal) starts below the top of the screen. Pass the sheet's distance from the top as `keyboardVerticalOffset`, or present it full screen.
118
+
119
+ Tapping an attached image opens it inside the chat. On Android, the back button closes it.
96
120
 
97
121
  For an in-app banner while the chat is closed, use `support.onMessage(({ conversationId, from, message }) => …)`.
98
122
 
Binary file
package/lib/api.js CHANGED
@@ -63,13 +63,14 @@ class OpenDeskApi {
63
63
  const form = new FormData();
64
64
  if (isBlob(file)) {
65
65
  form.append('file', file, 'name' in file && typeof file.name === 'string' ? file.name : 'upload');
66
+ return this.request('POST', '/v1/widget/attachments', form);
66
67
  }
67
- else {
68
- form.append('file', { uri: file.uri, name: file.name, type: file.type || 'application/octet-stream' });
69
- }
70
- return this.request('POST', '/v1/widget/attachments', form);
68
+ form.append('file', { uri: file.uri, name: file.name, type: file.type || 'application/octet-stream' });
69
+ // Expo replaces `fetch` with expo/fetch, which can't send `{ uri }` parts; React Native's
70
+ // XMLHttpRequest reads the file from disk itself.
71
+ return this.request('POST', '/v1/widget/attachments', form, true, typeof XMLHttpRequest === 'undefined' ? this.fetcher : xhrFetch);
71
72
  }
72
- async request(method, path, body, authenticated = true) {
73
+ async request(method, path, body, authenticated = true, fetcher = this.fetcher) {
73
74
  const headers = { Accept: 'application/json' };
74
75
  let payload;
75
76
  if (body instanceof FormData) {
@@ -84,10 +85,10 @@ class OpenDeskApi {
84
85
  }
85
86
  let response;
86
87
  try {
87
- response = await this.fetcher(this.baseUrl + path, { method, headers, body: payload });
88
+ response = await fetcher(this.baseUrl + path, { method, headers, body: payload });
88
89
  }
89
- catch {
90
- throw new errors_1.OpenDeskError(0, 'network_error', "Can't reach the server");
90
+ catch (cause) {
91
+ throw new errors_1.OpenDeskError(0, 'network_error', "Can't reach the server", cause);
91
92
  }
92
93
  if (!response.ok) {
93
94
  let code = 'error';
@@ -112,3 +113,19 @@ exports.OpenDeskApi = OpenDeskApi;
112
113
  function isBlob(file) {
113
114
  return typeof Blob !== 'undefined' && file instanceof Blob;
114
115
  }
116
+ /** `fetch` over XMLHttpRequest, for the multipart uploads expo/fetch can't send. */
117
+ const xhrFetch = (input, init) => new Promise((resolve, reject) => {
118
+ const xhr = new XMLHttpRequest();
119
+ xhr.open(init?.method ?? 'GET', String(input));
120
+ Object.entries((init?.headers ?? {})).forEach(([name, value]) => xhr.setRequestHeader(name, value));
121
+ xhr.onload = () => {
122
+ const empty = xhr.status === 204 || xhr.status === 205 || xhr.status === 304;
123
+ resolve(new Response(empty ? null : xhr.responseText, {
124
+ status: xhr.status,
125
+ headers: { 'content-type': xhr.getResponseHeader('content-type') ?? '' },
126
+ }));
127
+ };
128
+ xhr.onerror = () => reject(new TypeError('Network request failed'));
129
+ xhr.ontimeout = xhr.onerror;
130
+ xhr.send((init?.body ?? null));
131
+ });
package/lib/client.d.ts CHANGED
@@ -9,8 +9,14 @@ export interface OpenDeskOptions {
9
9
  widgetKey: string;
10
10
  /** Persists the visitor token so conversations survive restarts. Defaults to memory. */
11
11
  storage?: TokenStorage;
12
+ /** Replaces `fetch`. Native `{ uri }` uploads still go over XMLHttpRequest, which can read the file. */
12
13
  fetcher?: Fetcher;
13
14
  socketFactory?: SocketFactory;
15
+ /**
16
+ * Played when an agent or AI reply arrives in a conversation that isn't open, if the widget
17
+ * has sound on. `expoAudioSound(ExpoAudio)` plays the web widget's chime.
18
+ */
19
+ sound?: () => void;
14
20
  }
15
21
  /** An AI answer being streamed before it lands as a message. */
16
22
  export interface AIReply {
@@ -61,6 +67,7 @@ export declare class OpenDesk {
61
67
  private readonly storage;
62
68
  private readonly storageKey;
63
69
  private readonly socketFactory;
70
+ private readonly sound;
64
71
  private readonly subscribers;
65
72
  private readonly messageListeners;
66
73
  private readonly typingTimers;
@@ -103,6 +110,8 @@ export declare class OpenDesk {
103
110
  private authorized;
104
111
  private catchUp;
105
112
  private onRealtimeEvent;
113
+ /** The widget's sound setting decides, as on the web; the app decides what plays. */
114
+ private playSound;
106
115
  private onLiveEvent;
107
116
  private onAgentTyping;
108
117
  private clearTyping;
package/lib/client.js CHANGED
@@ -45,6 +45,7 @@ class OpenDesk {
45
45
  this.storage = options.storage ?? (0, storage_1.memoryStorage)();
46
46
  this.storageKey = `opendesk.visitor.${options.widgetKey}`;
47
47
  this.socketFactory = options.socketFactory ?? realtime_1.phoenixSocketFactory;
48
+ this.sound = options.sound ?? null;
48
49
  }
49
50
  /** Called for every agent or AI reply, e.g. to show an in-app banner. */
50
51
  onMessage(listener) {
@@ -290,6 +291,7 @@ class OpenDesk {
290
291
  this.set((state) => ({
291
292
  unread: { ...state.unread, [conversationId]: (state.unread[conversationId] ?? 0) + 1 },
292
293
  }));
294
+ this.playSound();
293
295
  }
294
296
  const from = message.author.user?.name || message.author.bot?.name || this.state.config?.workspace_name || 'Support';
295
297
  this.messageListeners.forEach((listener) => {
@@ -301,6 +303,18 @@ class OpenDesk {
301
303
  }
302
304
  });
303
305
  }
306
+ /** The widget's sound setting decides, as on the web; the app decides what plays. */
307
+ playSound() {
308
+ if (!this.sound || this.state.config?.sound !== true) {
309
+ return;
310
+ }
311
+ try {
312
+ this.sound();
313
+ }
314
+ catch {
315
+ // A sound that fails must not break the stream.
316
+ }
317
+ }
304
318
  onLiveEvent(event) {
305
319
  const { reply_id: replyId, ticket_id: conversationId } = event.data;
306
320
  if (typeof replyId !== 'string' || typeof conversationId !== 'string') {
package/lib/errors.d.ts CHANGED
@@ -1,8 +1,12 @@
1
- /** A failed openDesk request; `status` is 0 when the server could not be reached. */
1
+ /**
2
+ * A failed openDesk request; `status` is 0 when the server could not be reached, and then
3
+ * `cause` holds what `fetch` threw.
4
+ */
2
5
  export declare class OpenDeskError extends Error {
3
6
  readonly status: number;
4
7
  readonly code: string;
5
- constructor(status: number, code: string, message: string);
8
+ readonly cause?: unknown | undefined;
9
+ constructor(status: number, code: string, message: string, cause?: unknown | undefined);
6
10
  /** The visitor token is unknown or revoked; a fresh session is needed. */
7
11
  get isUnauthorized(): boolean;
8
12
  }
package/lib/errors.js CHANGED
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OpenDeskError = void 0;
4
- /** A failed openDesk request; `status` is 0 when the server could not be reached. */
4
+ /**
5
+ * A failed openDesk request; `status` is 0 when the server could not be reached, and then
6
+ * `cause` holds what `fetch` threw.
7
+ */
5
8
  class OpenDeskError extends Error {
6
- constructor(status, code, message) {
9
+ constructor(status, code, message, cause) {
7
10
  super(message);
8
11
  this.status = status;
9
12
  this.code = code;
13
+ this.cause = cause;
10
14
  this.name = 'OpenDeskError';
11
15
  }
12
16
  /** The visitor token is unknown or revoked; a fresh session is needed. */
package/lib/index.d.ts CHANGED
@@ -7,6 +7,8 @@ export { OpenDeskRealtime, phoenixSocketFactory } from './realtime';
7
7
  export type { RealtimeChannel, RealtimeSocket, SocketFactory } from './realtime';
8
8
  export { keychainStorage, memoryStorage, secureStoreStorage } from './storage';
9
9
  export type { ExpoSecureStoreModule, KeychainModule, TokenStorage } from './storage';
10
+ export { expoAudioSound } from './sound';
11
+ export type { ExpoAudioModule, ExpoAudioPlayer } from './sound';
10
12
  export { OpenDeskProvider, useConversation, useConversations, useOpenDesk, useOpenDeskState, useUnreadCount, } from './react';
11
13
  export type { ConversationView, OpenDeskProviderProps } from './react';
12
14
  export { OpenDeskChat } from './ui/OpenDeskChat';
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defaultStrings = exports.OpenDeskLauncher = exports.OpenDeskChat = exports.useUnreadCount = exports.useOpenDeskState = exports.useOpenDesk = exports.useConversations = exports.useConversation = exports.OpenDeskProvider = exports.secureStoreStorage = exports.memoryStorage = exports.keychainStorage = exports.phoenixSocketFactory = exports.OpenDeskRealtime = exports.OpenDeskError = exports.OpenDeskApi = exports.OpenDesk = void 0;
3
+ exports.defaultStrings = exports.OpenDeskLauncher = exports.OpenDeskChat = exports.useUnreadCount = exports.useOpenDeskState = exports.useOpenDesk = exports.useConversations = exports.useConversation = exports.OpenDeskProvider = exports.expoAudioSound = exports.secureStoreStorage = exports.memoryStorage = exports.keychainStorage = exports.phoenixSocketFactory = exports.OpenDeskRealtime = exports.OpenDeskError = exports.OpenDeskApi = exports.OpenDesk = void 0;
4
4
  var client_1 = require("./client");
5
5
  Object.defineProperty(exports, "OpenDesk", { enumerable: true, get: function () { return client_1.OpenDesk; } });
6
6
  var api_1 = require("./api");
@@ -14,6 +14,8 @@ var storage_1 = require("./storage");
14
14
  Object.defineProperty(exports, "keychainStorage", { enumerable: true, get: function () { return storage_1.keychainStorage; } });
15
15
  Object.defineProperty(exports, "memoryStorage", { enumerable: true, get: function () { return storage_1.memoryStorage; } });
16
16
  Object.defineProperty(exports, "secureStoreStorage", { enumerable: true, get: function () { return storage_1.secureStoreStorage; } });
17
+ var sound_1 = require("./sound");
18
+ Object.defineProperty(exports, "expoAudioSound", { enumerable: true, get: function () { return sound_1.expoAudioSound; } });
17
19
  var react_1 = require("./react");
18
20
  Object.defineProperty(exports, "OpenDeskProvider", { enumerable: true, get: function () { return react_1.OpenDeskProvider; } });
19
21
  Object.defineProperty(exports, "useConversation", { enumerable: true, get: function () { return react_1.useConversation; } });
package/lib/sound.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /** The parts of `expo-audio` the adapter uses; pass the module itself. */
2
+ export interface ExpoAudioModule {
3
+ createAudioPlayer(source: number): ExpoAudioPlayer;
4
+ }
5
+ export interface ExpoAudioPlayer {
6
+ volume: number;
7
+ play(): void;
8
+ seekTo(seconds: number): Promise<void>;
9
+ }
10
+ /**
11
+ * Plays the web widget's reply chime with `expo-audio`. Takes the module as an argument, so the
12
+ * SDK has no dependency on Expo:
13
+ *
14
+ * import * as ExpoAudio from 'expo-audio';
15
+ * new OpenDesk({ …, sound: expoAudioSound(ExpoAudio) });
16
+ *
17
+ * The player is made on the first reply and kept for the next. The app's audio mode is left
18
+ * alone; under expo-audio's default the chime mixes with other audio instead of pausing it.
19
+ */
20
+ export declare function expoAudioSound(ExpoAudio: ExpoAudioModule, options?: {
21
+ volume?: number;
22
+ }): () => void;
package/lib/sound.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.expoAudioSound = expoAudioSound;
7
+ const chime_wav_1 = __importDefault(require("../assets/chime.wav"));
8
+ /**
9
+ * Plays the web widget's reply chime with `expo-audio`. Takes the module as an argument, so the
10
+ * SDK has no dependency on Expo:
11
+ *
12
+ * import * as ExpoAudio from 'expo-audio';
13
+ * new OpenDesk({ …, sound: expoAudioSound(ExpoAudio) });
14
+ *
15
+ * The player is made on the first reply and kept for the next. The app's audio mode is left
16
+ * alone; under expo-audio's default the chime mixes with other audio instead of pausing it.
17
+ */
18
+ function expoAudioSound(ExpoAudio, options = {}) {
19
+ let player = null;
20
+ return () => {
21
+ if (!player) {
22
+ player = ExpoAudio.createAudioPlayer(chime_wav_1.default);
23
+ if (options.volume !== undefined) {
24
+ player.volume = options.volume;
25
+ }
26
+ }
27
+ const current = player;
28
+ void current
29
+ .seekTo(0)
30
+ .catch(() => undefined)
31
+ .then(() => current.play());
32
+ };
33
+ }
package/lib/types.d.ts CHANGED
@@ -20,6 +20,8 @@ export interface WidgetConfig {
20
20
  locale: string;
21
21
  language: string;
22
22
  open: boolean;
23
+ /** Whether replies play a sound while the visitor isn't looking at them. */
24
+ sound: boolean;
23
25
  require_email: boolean;
24
26
  chat_welcome: boolean;
25
27
  help_center_url: string;
@@ -17,7 +17,11 @@ export interface OpenDeskChatProps {
17
17
  theme?: 'light' | 'dark' | 'auto';
18
18
  /** Replaces any of the built-in English strings. */
19
19
  strings?: Partial<ChatStrings>;
20
- /** Height of any navigation header above the chat, so the keyboard never covers the composer on iOS. */
20
+ /**
21
+ * Extra space to keep between the composer and the keyboard. The chat measures its own position,
22
+ * so navigation headers need nothing here; inside an iOS page sheet, which it can't see past,
23
+ * pass the sheet's distance from the top of the screen.
24
+ */
21
25
  keyboardVerticalOffset?: number;
22
26
  }
23
27
  /**
@@ -7,6 +7,7 @@ const react_native_1 = require("react-native");
7
7
  const react_2 = require("../react");
8
8
  const BotFace_1 = require("./BotFace");
9
9
  const icons_1 = require("./icons");
10
+ const keyboard_1 = require("./keyboard");
10
11
  const strings_1 = require("./strings");
11
12
  const theme_1 = require("./theme");
12
13
  const MAX_UPLOAD_BYTES = 25 * 1024 * 1024;
@@ -26,8 +27,10 @@ function OpenDeskChat({ initialConversationId, onClose, pickAttachment, accentCo
26
27
  const strings = (0, react_1.useMemo)(() => ({ ...strings_1.defaultStrings, ...stringOverrides }), [stringOverrides]);
27
28
  const styles = (0, react_1.useMemo)(() => createStyles(theme), [theme]);
28
29
  const ui = (0, react_1.useMemo)(() => ({ theme, strings, styles, bot: config?.bot ?? null }), [theme, strings, styles, config?.bot]);
30
+ const rootRef = (0, react_1.useRef)(null);
31
+ const keyboard = (0, keyboard_1.useKeyboardInset)(rootRef, keyboardVerticalOffset);
29
32
  const inThread = conversationId !== null || composing;
30
- return ((0, jsx_runtime_1.jsx)(react_native_1.KeyboardAvoidingView, { style: styles.root, behavior: react_native_1.Platform.OS === 'ios' ? 'padding' : undefined, keyboardVerticalOffset: keyboardVerticalOffset, children: inThread ? ((0, jsx_runtime_1.jsx)(Thread, { ui: ui, conversationId: conversationId, pickAttachment: pickAttachment, onBack: () => {
33
+ return ((0, jsx_runtime_1.jsx)(react_native_1.View, { ref: rootRef, style: [styles.root, { paddingBottom: keyboard.inset }], onLayout: keyboard.onLayout, children: inThread ? ((0, jsx_runtime_1.jsx)(Thread, { ui: ui, conversationId: conversationId, pickAttachment: pickAttachment, onBack: () => {
31
34
  setConversationId(null);
32
35
  setComposing(false);
33
36
  }, onClose: onClose, onStarted: (id) => {
@@ -67,6 +70,12 @@ function Thread({ ui, conversationId, pickAttachment, onBack, onClose, onStarted
67
70
  const [focused, setFocused] = (0, react_1.useState)(false);
68
71
  const [inputHeight, setInputHeight] = (0, react_1.useState)(30);
69
72
  const [error, setError] = (0, react_1.useState)(null);
73
+ const [viewing, setViewing] = (0, react_1.useState)(null);
74
+ const openImage = (0, react_1.useCallback)((attachment) => {
75
+ react_native_1.Keyboard.dismiss();
76
+ setViewing(attachment);
77
+ }, []);
78
+ const closeImage = (0, react_1.useCallback)(() => setViewing(null), []);
70
79
  const topics = config?.topics ?? [];
71
80
  const topic = topics.find((t) => t.id === topicId) ?? null;
72
81
  const needsTopic = conversationId === null && topics.length > 0 && topic === null;
@@ -160,14 +169,14 @@ function Thread({ ui, conversationId, pickAttachment, onBack, onClose, onStarted
160
169
  }, [client, config?.attachment_extensions, pickAttachment, strings]);
161
170
  const showAttach = Boolean(pickAttachment) && config?.attachments !== false && (config?.attachment_extensions?.length ?? 1) > 0;
162
171
  const bot = config?.ai_answers ? config.bot : null;
163
- return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.flex, children: [(0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.head, children: [(0, jsx_runtime_1.jsx)(IconButton, { ui: ui, label: strings.back, onPress: onBack, icon: (0, jsx_runtime_1.jsx)(icons_1.ChevronIcon, { color: theme.fg3, direction: "left" }) }), bot ? ((0, jsx_runtime_1.jsx)(BotFace_1.BotFace, { size: 26, look: bot.look, avatarUrl: bot.avatar_url })) : ((0, jsx_runtime_1.jsx)(Glyph, { ui: ui, name: name, url: config?.avatar_url ?? null })), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.headMain, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.title, numberOfLines: 1, children: conversation?.subject || name }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.titleSub, numberOfLines: 1, children: subtitleFor(config, strings) })] }), onClose ? (0, jsx_runtime_1.jsx)(IconButton, { ui: ui, label: strings.closeChat, onPress: onClose, icon: (0, jsx_runtime_1.jsx)(icons_1.CloseIcon, { color: theme.fg3 }) }) : null] }), rows.length === 0 ? ((0, jsx_runtime_1.jsx)(react_native_1.ScrollView, { style: styles.flex, contentContainerStyle: styles.emptyScroll, keyboardShouldPersistTaps: "handled", children: needsTopic ? ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.card, styles.picker], children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.pickerTitle, children: strings.topicsTitle }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.pickerHint, children: strings.topicsHint }), topics.map((item, index) => ((0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { accessibilityRole: "button", onPress: () => setTopicId(item.id), style: ({ pressed }) => [styles.topic, index > 0 && styles.convBorder, pressed && { backgroundColor: theme.bg2 }], children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.topicText, children: item.label }), (0, jsx_runtime_1.jsx)(icons_1.ChevronIcon, { color: theme.fg4, size: 14, direction: "right" })] }, item.id)))] })) : ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.empty, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.emptyTitle, children: config?.greeting || strings.greeting }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.emptyText, children: config?.intro || strings.emptyHint })] })) })) : ((0, jsx_runtime_1.jsx)(react_native_1.FlatList, { inverted: true, style: styles.flex, data: rows, keyExtractor: (row) => row.key, contentContainerStyle: styles.thread, keyboardShouldPersistTaps: "handled", renderItem: ({ item }) => ((0, jsx_runtime_1.jsx)(ThreadRow, { ui: ui, row: item, showHandoff: item.kind === 'message' && item.message.id === handoffMessageId, onDecide: decide, onRequestHuman: requestHuman })) })), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.composer, children: [topic && conversationId === null ? ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.topicRow, children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.topicChip, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.topicChipText, numberOfLines: 1, children: topic.label }), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: strings.changeTopic, onPress: () => setTopicId(null), style: styles.topicChipX, children: (0, jsx_runtime_1.jsx)(icons_1.CloseIcon, { color: theme.fg3, size: 10 }) })] }) })) : null, attachments.length > 0 || uploadingName ? ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.pendingFiles, children: [attachments.map((attachment) => ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.chip, styles.pendingChip], children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.chipText, numberOfLines: 1, children: attachment.filename }), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: (0, strings_1.format)(strings.removeFile, { name: attachment.filename }), onPress: () => setAttachments((current) => current.filter((a) => a.id !== attachment.id)), hitSlop: 8, children: (0, jsx_runtime_1.jsx)(icons_1.CloseIcon, { color: theme.fg3, size: 10 }) })] }, attachment.id))), uploadingName ? ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.chip, styles.pendingChip], children: [(0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { size: "small", color: theme.fg3, style: styles.chipSpinner }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.chipText, numberOfLines: 1, children: uploadingName })] })) : null] })) : null, error ? (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.err, children: error }) : null, (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.cbar, showAttach && styles.cbarLead, focused && styles.cbarFocus, needsTopic && styles.cbarOff], children: [showAttach ? ((0, jsx_runtime_1.jsx)(IconButton, { ui: ui, label: strings.attach, onPress: attach, disabled: uploadingName !== null || needsTopic, icon: (0, jsx_runtime_1.jsx)(icons_1.PaperclipIcon, { color: theme.fg3 }) })) : null, (0, jsx_runtime_1.jsx)(react_native_1.TextInput, { style: [styles.input, { height: inputHeight }], value: draft, onContentSizeChange: (event) => setInputHeight(Math.min(120, Math.max(30, Math.ceil(event.nativeEvent.contentSize.height)))), ...(react_native_1.Platform.OS === 'web' ? { rows: 1 } : {}), editable: !needsTopic, onFocus: () => setFocused(true), onBlur: () => setFocused(false), onChangeText: (text) => {
172
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.flex, children: [(0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.head, children: [(0, jsx_runtime_1.jsx)(IconButton, { ui: ui, label: strings.back, onPress: onBack, icon: (0, jsx_runtime_1.jsx)(icons_1.ChevronIcon, { color: theme.fg3, direction: "left" }) }), bot ? ((0, jsx_runtime_1.jsx)(BotFace_1.BotFace, { size: 26, look: bot.look, avatarUrl: bot.avatar_url })) : ((0, jsx_runtime_1.jsx)(Glyph, { ui: ui, name: name, url: config?.avatar_url ?? null })), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.headMain, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.title, numberOfLines: 1, children: conversation?.subject || name }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.titleSub, numberOfLines: 1, children: subtitleFor(config, strings) })] }), onClose ? (0, jsx_runtime_1.jsx)(IconButton, { ui: ui, label: strings.closeChat, onPress: onClose, icon: (0, jsx_runtime_1.jsx)(icons_1.CloseIcon, { color: theme.fg3 }) }) : null] }), rows.length === 0 ? ((0, jsx_runtime_1.jsx)(react_native_1.ScrollView, { style: styles.flex, contentContainerStyle: styles.emptyScroll, keyboardShouldPersistTaps: "handled", children: needsTopic ? ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.card, styles.picker], children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.pickerTitle, children: strings.topicsTitle }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.pickerHint, children: strings.topicsHint }), topics.map((item, index) => ((0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { accessibilityRole: "button", onPress: () => setTopicId(item.id), style: ({ pressed }) => [styles.topic, index > 0 && styles.convBorder, pressed && { backgroundColor: theme.bg2 }], children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.topicText, children: item.label }), (0, jsx_runtime_1.jsx)(icons_1.ChevronIcon, { color: theme.fg4, size: 14, direction: "right" })] }, item.id)))] })) : ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.empty, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.emptyTitle, children: config?.greeting || strings.greeting }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.emptyText, children: config?.intro || strings.emptyHint })] })) })) : ((0, jsx_runtime_1.jsx)(react_native_1.FlatList, { inverted: true, style: styles.flex, data: rows, keyExtractor: (row) => row.key, contentContainerStyle: styles.thread, keyboardShouldPersistTaps: "handled", renderItem: ({ item }) => ((0, jsx_runtime_1.jsx)(ThreadRow, { ui: ui, row: item, showHandoff: item.kind === 'message' && item.message.id === handoffMessageId, onDecide: decide, onRequestHuman: requestHuman, onOpenImage: openImage })) })), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.composer, children: [topic && conversationId === null ? ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.topicRow, children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.topicChip, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.topicChipText, numberOfLines: 1, children: topic.label }), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: strings.changeTopic, onPress: () => setTopicId(null), style: styles.topicChipX, children: (0, jsx_runtime_1.jsx)(icons_1.CloseIcon, { color: theme.fg3, size: 10 }) })] }) })) : null, attachments.length > 0 || uploadingName ? ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.pendingFiles, children: [attachments.map((attachment) => ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.chip, styles.pendingChip], children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.chipText, numberOfLines: 1, children: attachment.filename }), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: (0, strings_1.format)(strings.removeFile, { name: attachment.filename }), onPress: () => setAttachments((current) => current.filter((a) => a.id !== attachment.id)), hitSlop: 8, children: (0, jsx_runtime_1.jsx)(icons_1.CloseIcon, { color: theme.fg3, size: 10 }) })] }, attachment.id))), uploadingName ? ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.chip, styles.pendingChip], children: [(0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { size: "small", color: theme.fg3, style: styles.chipSpinner }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.chipText, numberOfLines: 1, children: uploadingName })] })) : null] })) : null, error ? (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.err, children: error }) : null, (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.cbar, showAttach && styles.cbarLead, focused && styles.cbarFocus, needsTopic && styles.cbarOff], children: [showAttach ? ((0, jsx_runtime_1.jsx)(IconButton, { ui: ui, label: strings.attach, onPress: attach, disabled: uploadingName !== null || needsTopic, icon: (0, jsx_runtime_1.jsx)(icons_1.PaperclipIcon, { color: theme.fg3 }) })) : null, (0, jsx_runtime_1.jsx)(react_native_1.TextInput, { style: [styles.input, { height: inputHeight }], value: draft, onContentSizeChange: (event) => setInputHeight(Math.min(120, Math.max(30, Math.ceil(event.nativeEvent.contentSize.height)))), ...(react_native_1.Platform.OS === 'web' ? { rows: 1 } : {}), editable: !needsTopic, onFocus: () => setFocused(true), onBlur: () => setFocused(false), onChangeText: (text) => {
164
173
  setDraft(text);
165
174
  if (conversationId) {
166
175
  client.typing(conversationId);
167
176
  }
168
- }, placeholder: needsTopic ? strings.placeholderTopic : strings.placeholder, placeholderTextColor: theme.fg4, accessibilityLabel: strings.placeholder, multiline: true }), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: strings.send, disabled: !ready, onPress: send, style: [styles.send, ready && styles.sendReady], children: (0, jsx_runtime_1.jsx)(icons_1.ArrowIcon, { color: theme.accentFg, size: 14, angle: -90 }) })] })] })] }));
177
+ }, placeholder: needsTopic ? strings.placeholderTopic : strings.placeholder, placeholderTextColor: theme.fg4, accessibilityLabel: strings.placeholder, multiline: true }), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: strings.send, disabled: !ready, onPress: send, style: [styles.send, ready && styles.sendReady], children: (0, jsx_runtime_1.jsx)(icons_1.ArrowIcon, { color: theme.accentFg, size: 14, angle: -90 }) })] })] }), viewing ? (0, jsx_runtime_1.jsx)(ImageViewer, { ui: ui, attachment: viewing, onClose: closeImage }) : null] }));
169
178
  }
170
- const ThreadRow = (0, react_1.memo)(function ThreadRow({ ui, row, showHandoff, onDecide, onRequestHuman, }) {
179
+ const ThreadRow = (0, react_1.memo)(function ThreadRow({ ui, row, showHandoff, onDecide, onRequestHuman, onOpenImage, }) {
171
180
  const { theme, strings, styles } = ui;
172
181
  switch (row.kind) {
173
182
  case 'day':
@@ -177,16 +186,16 @@ const ThreadRow = (0, react_1.memo)(function ThreadRow({ ui, row, showHandoff, o
177
186
  case 'handed':
178
187
  return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.handed, children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.handedIc, children: (0, jsx_runtime_1.jsx)(icons_1.PersonIcon, { color: theme.fg2 }) }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.flex, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.handedTitle, children: strings.handedOff }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.handedText, children: strings.handedOffHint })] })] }));
179
188
  case 'reply':
180
- return (0, jsx_runtime_1.jsx)(Bubble, { ui: ui, reply: row.reply, first: true, last: true, gap: true, showHandoff: false, onDecide: onDecide, onRequestHuman: onRequestHuman });
189
+ return ((0, jsx_runtime_1.jsx)(Bubble, { ui: ui, reply: row.reply, first: true, last: true, gap: true, showHandoff: false, onDecide: onDecide, onRequestHuman: onRequestHuman, onOpenImage: onOpenImage }));
181
190
  case 'message':
182
- return ((0, jsx_runtime_1.jsx)(Bubble, { ui: ui, message: row.message, first: row.first, last: row.last, gap: row.gap, showHandoff: showHandoff, onDecide: onDecide, onRequestHuman: onRequestHuman }));
191
+ return ((0, jsx_runtime_1.jsx)(Bubble, { ui: ui, message: row.message, first: row.first, last: row.last, gap: row.gap, showHandoff: showHandoff, onDecide: onDecide, onRequestHuman: onRequestHuman, onOpenImage: onOpenImage }));
183
192
  }
184
193
  });
185
194
  /**
186
195
  * One bubble for a stored message or an AI answer still streaming. Both share one element
187
196
  * tree, so when the stored message replaces the stream (same row key) nothing remounts.
188
197
  */
189
- function Bubble({ ui, message, reply, first, last, gap, showHandoff, onDecide, onRequestHuman, }) {
198
+ function Bubble({ ui, message, reply, first, last, gap, showHandoff, onDecide, onRequestHuman, onOpenImage, }) {
190
199
  const { theme, strings, styles, bot: fallbackBot } = ui;
191
200
  const mine = message?.direction === 'inbound';
192
201
  const ai = reply !== undefined || message?.ai === true;
@@ -210,7 +219,7 @@ function Bubble({ ui, message, reply, first, last, gap, showHandoff, onDecide, o
210
219
  mine ? styles.msgMe : ai ? styles.msgAi : styles.msgThem,
211
220
  corners,
212
221
  local && styles.sendingMsg,
213
- ], children: text ? (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: [styles.msgText, mine && { color: theme.accentFg }], children: text }) : (0, jsx_runtime_1.jsx)(Dots, { color: theme.ai }) })) : null, images.map((attachment) => ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onPress: () => react_native_1.Linking.openURL(attachment.url), style: styles.fileGap, children: (0, jsx_runtime_1.jsx)(react_native_1.Image, { source: { uri: attachment.url }, style: styles.thumb, accessibilityLabel: attachment.filename, resizeMode: "cover" }) }, attachment.id))), files.map((attachment) => ((0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { onPress: () => react_native_1.Linking.openURL(attachment.url), style: [styles.chip, styles.fileGap], children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.chipText, numberOfLines: 1, children: attachment.filename }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.chipSize, children: fileSize(attachment.size_bytes) })] }, attachment.id))), message && action ? (0, jsx_runtime_1.jsx)(ActionCard, { ui: ui, message: message, onDecide: onDecide }) : null, message && showHandoff ? ((0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { accessibilityRole: "button", onPress: () => onRequestHuman(message), style: ({ pressed }) => [styles.handoff, pressed && { backgroundColor: theme.bg2 }], children: [(0, jsx_runtime_1.jsx)(icons_1.PersonIcon, { color: theme.fg, size: 14 }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.handoffText, children: strings.talkToPerson })] })) : null, last && message ? (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.meta, children: local ? strings.sending : clockTime(message.created_at) }) : null] }));
222
+ ], children: text ? (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: [styles.msgText, mine && { color: theme.accentFg }], children: text }) : (0, jsx_runtime_1.jsx)(Dots, { color: theme.ai }) })) : null, images.map((attachment) => ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "imagebutton", accessibilityLabel: (0, strings_1.format)(strings.viewImage, { name: attachment.filename }), onPress: () => onOpenImage(attachment), style: ({ pressed }) => [styles.fileGap, pressed && styles.pressed], children: (0, jsx_runtime_1.jsx)(react_native_1.Image, { source: { uri: attachment.url }, style: styles.thumb, resizeMode: "cover" }) }, attachment.id))), files.map((attachment) => ((0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { onPress: () => react_native_1.Linking.openURL(attachment.url), style: [styles.chip, styles.fileGap], children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.chipText, numberOfLines: 1, children: attachment.filename }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.chipSize, children: fileSize(attachment.size_bytes) })] }, attachment.id))), message && action ? (0, jsx_runtime_1.jsx)(ActionCard, { ui: ui, message: message, onDecide: onDecide }) : null, message && showHandoff ? ((0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { accessibilityRole: "button", onPress: () => onRequestHuman(message), style: ({ pressed }) => [styles.handoff, pressed && { backgroundColor: theme.bg2 }], children: [(0, jsx_runtime_1.jsx)(icons_1.PersonIcon, { color: theme.fg, size: 14 }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.handoffText, children: strings.talkToPerson })] })) : null, last && message ? (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.meta, children: local ? strings.sending : clockTime(message.created_at) }) : null] }));
214
223
  }
215
224
  function ActionCard({ ui, message, onDecide, }) {
216
225
  const { theme, strings, styles } = ui;
@@ -225,6 +234,21 @@ function ActionCard({ ui, message, onDecide, }) {
225
234
  }[action.status];
226
235
  return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.action, pending && styles.actionPending], children: [(0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.actionTop, children: [(0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.actionTool, children: [(0, jsx_runtime_1.jsx)(icons_1.SparkIcon, { color: theme.ai, size: 8 }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.actionToolText, numberOfLines: 1, children: action.tool.replace(/_/g, ' ') })] }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: [styles.actionNeed, action.status === 'failed' && { color: theme.danger }], children: label })] }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.actionTitle, children: action.title }), action.summary ? (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.actionSum, children: action.summary }) : null, pending ? ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.actionBtns, children: [(0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onPress: () => onDecide(message, 'decline'), style: [styles.btn, styles.btnGhost], children: (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.btnGhostText, children: strings.cancel }) }), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { onPress: () => onDecide(message, 'confirm'), style: [styles.btn, styles.btnSolid], children: (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.btnSolidText, children: strings.confirm }) })] })) : null] }));
227
236
  }
237
+ /** An attached image shown full size over the thread, so it opens in the chat instead of a browser. */
238
+ function ImageViewer({ ui, attachment, onClose }) {
239
+ const { strings, styles } = ui;
240
+ (0, react_1.useEffect)(() => {
241
+ if (react_native_1.Platform.OS !== 'android') {
242
+ return;
243
+ }
244
+ const subscription = react_native_1.BackHandler.addEventListener('hardwareBackPress', () => {
245
+ onClose();
246
+ return true;
247
+ });
248
+ return () => subscription.remove();
249
+ }, [onClose]);
250
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.viewer, accessibilityViewIsModal: true, children: [(0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.viewerHead, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.viewerName, numberOfLines: 1, children: attachment.filename }), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: strings.closeImage, onPress: onClose, hitSlop: 6, style: ({ pressed }) => [styles.iconBtn, pressed && styles.viewerPressed], children: (0, jsx_runtime_1.jsx)(icons_1.CloseIcon, { color: "#ffffff" }) })] }), (0, jsx_runtime_1.jsx)(react_native_1.ScrollView, { style: styles.flex, contentContainerStyle: styles.viewerBody, maximumZoomScale: 4, minimumZoomScale: 1, centerContent: true, showsHorizontalScrollIndicator: false, showsVerticalScrollIndicator: false, children: (0, jsx_runtime_1.jsx)(react_native_1.Image, { source: { uri: attachment.url }, style: styles.viewerImage, resizeMode: "contain", accessibilityLabel: attachment.filename }) })] }));
251
+ }
228
252
  function IconButton({ ui, label, onPress, icon, disabled, }) {
229
253
  return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityLabel: label, onPress: onPress, disabled: disabled, hitSlop: 6, style: ({ pressed }) => [ui.styles.iconBtn, pressed && { backgroundColor: ui.theme.bg2 }, disabled && ui.styles.disabled], children: icon }));
230
254
  }
@@ -377,13 +401,13 @@ function createStyles(t) {
377
401
  alignItems: 'center',
378
402
  gap: 10,
379
403
  paddingHorizontal: 12,
380
- paddingTop: 12,
381
- paddingBottom: 11,
404
+ paddingTop: 18,
405
+ paddingBottom: 14,
382
406
  borderBottomWidth: 1,
383
407
  borderBottomColor: t.line,
384
408
  backgroundColor: t.bg,
385
409
  },
386
- headHome: { flexDirection: 'column', alignItems: 'stretch', gap: 0, padding: 16, paddingBottom: 20, backgroundColor: t.headBg },
410
+ headHome: { flexDirection: 'column', alignItems: 'stretch', gap: 0, padding: 16, paddingTop: 22, paddingBottom: 20, backgroundColor: t.headBg },
387
411
  headRow: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 8 },
388
412
  headMain: { flex: 1, minWidth: 0 },
389
413
  ws: { flexDirection: 'row', alignItems: 'center', gap: 9, flexShrink: 1 },
@@ -489,6 +513,12 @@ function createStyles(t) {
489
513
  toolText: { fontSize: 12, lineHeight: 18, color: t.fg3 },
490
514
  fileGap: { marginTop: 4 },
491
515
  thumb: { width: 220, height: 160, borderRadius: r.card, borderWidth: 1, borderColor: t.line, backgroundColor: t.bg2 },
516
+ viewer: { position: 'absolute', top: 0, right: 0, bottom: 0, left: 0, zIndex: 10, elevation: 10, backgroundColor: '#000000' },
517
+ viewerHead: { flexDirection: 'row', alignItems: 'center', gap: 10, paddingHorizontal: 12, paddingTop: 18, paddingBottom: 14 },
518
+ viewerName: { flex: 1, fontSize: 14, fontWeight: '600', color: '#ffffff' },
519
+ viewerPressed: { backgroundColor: 'rgba(255,255,255,0.16)' },
520
+ viewerBody: { flexGrow: 1 },
521
+ viewerImage: { flex: 1, width: '100%' },
492
522
  chip: {
493
523
  flexDirection: 'row',
494
524
  alignItems: 'center',
@@ -0,0 +1,15 @@
1
+ import { type RefObject } from 'react';
2
+ import { type View } from 'react-native';
3
+ /**
4
+ * How far the keyboard covers the view in `ref`, for use as its bottom padding.
5
+ *
6
+ * KeyboardAvoidingView compares the keyboard with a layout relative to its parent, so it misses
7
+ * anything above that parent (a header, a sheet), and on Android it relies on the window
8
+ * shrinking, which edge-to-edge apps no longer do. This measures the view in window coordinates
9
+ * instead and works the same on both platforms. Call `onLayout` from the view's `onLayout` so a
10
+ * window that does shrink is measured again and the padding drops back.
11
+ */
12
+ export declare function useKeyboardInset(ref: RefObject<View | null>, extraOffset?: number): {
13
+ inset: number;
14
+ onLayout: () => void;
15
+ };
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useKeyboardInset = useKeyboardInset;
4
+ const react_1 = require("react");
5
+ const react_native_1 = require("react-native");
6
+ /**
7
+ * How far the keyboard covers the view in `ref`, for use as its bottom padding.
8
+ *
9
+ * KeyboardAvoidingView compares the keyboard with a layout relative to its parent, so it misses
10
+ * anything above that parent (a header, a sheet), and on Android it relies on the window
11
+ * shrinking, which edge-to-edge apps no longer do. This measures the view in window coordinates
12
+ * instead and works the same on both platforms. Call `onLayout` from the view's `onLayout` so a
13
+ * window that does shrink is measured again and the padding drops back.
14
+ */
15
+ function useKeyboardInset(ref, extraOffset = 0) {
16
+ const [inset, setInset] = (0, react_1.useState)(0);
17
+ const keyboard = (0, react_1.useRef)(null);
18
+ const measure = (0, react_1.useCallback)(() => {
19
+ const event = keyboard.current;
20
+ const view = ref.current;
21
+ if (!event || !view) {
22
+ setInset(0);
23
+ return;
24
+ }
25
+ view.measureInWindow((_x, y, _width, height) => {
26
+ if (keyboard.current !== event) {
27
+ return;
28
+ }
29
+ const next = Math.max(0, Math.round(y + height - event.endCoordinates.screenY + extraOffset));
30
+ setInset((current) => {
31
+ if (current !== next) {
32
+ animateWithKeyboard(event);
33
+ }
34
+ return next;
35
+ });
36
+ });
37
+ }, [ref, extraOffset]);
38
+ (0, react_1.useEffect)(() => {
39
+ const show = (event) => {
40
+ keyboard.current = event;
41
+ measure();
42
+ };
43
+ const hide = (event) => {
44
+ keyboard.current = null;
45
+ animateWithKeyboard(event);
46
+ setInset(0);
47
+ };
48
+ const subscriptions = react_native_1.Platform.OS === 'ios'
49
+ ? [react_native_1.Keyboard.addListener('keyboardWillChangeFrame', show), react_native_1.Keyboard.addListener('keyboardWillHide', hide)]
50
+ : [react_native_1.Keyboard.addListener('keyboardDidShow', show), react_native_1.Keyboard.addListener('keyboardDidHide', hide)];
51
+ return () => subscriptions.forEach((subscription) => subscription.remove());
52
+ }, [measure]);
53
+ return { inset, onLayout: measure };
54
+ }
55
+ /** iOS reports the keyboard's own curve, so the padding can move in step with it. */
56
+ function animateWithKeyboard(event) {
57
+ if (react_native_1.Platform.OS !== 'ios' || !event?.duration) {
58
+ return;
59
+ }
60
+ const type = react_native_1.LayoutAnimation.Types[event.easing] ?? react_native_1.LayoutAnimation.Types.keyboard;
61
+ react_native_1.LayoutAnimation.configureNext({ duration: event.duration, update: { duration: event.duration, type } });
62
+ }
@@ -20,6 +20,8 @@ export declare const defaultStrings: {
20
20
  sending: string;
21
21
  uploading: string;
22
22
  removeFile: string;
23
+ viewImage: string;
24
+ closeImage: string;
23
25
  fileTypeRefused: string;
24
26
  fileTooLarge: string;
25
27
  uploadFailed: string;
package/lib/ui/strings.js CHANGED
@@ -24,6 +24,8 @@ exports.defaultStrings = {
24
24
  sending: 'Sending…',
25
25
  uploading: 'Uploading…',
26
26
  removeFile: 'Remove {name}',
27
+ viewImage: 'View {name}',
28
+ closeImage: 'Close image',
27
29
  fileTypeRefused: "{name} can't be sent here. Try another file type.",
28
30
  fileTooLarge: '{name} is larger than 25 MB.',
29
31
  uploadFailed: "Couldn't upload {name}. Try again.",
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "opendesk-react-native",
3
- "version": "0.1.3",
3
+ "version": "0.1.6",
4
4
  "description": "React Native SDK for openDesk live chat: headless client, realtime, hooks and a drop-in chat screen.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "files": [
8
8
  "lib",
9
9
  "src",
10
+ "assets",
10
11
  "!src/**/__tests__"
11
12
  ],
12
13
  "scripts": {