@shotik/react-native 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +193 -2
- package/README.ru.md +192 -0
- package/dist/analytics/core.d.ts +104 -0
- package/dist/analytics/core.js +345 -0
- package/dist/analytics/index.d.ts +5 -0
- package/dist/analytics/index.js +3 -0
- package/dist/analytics/rn.d.ts +84 -0
- package/dist/analytics/rn.js +413 -0
- package/dist/analytics/wire.d.ts +53 -0
- package/dist/analytics/wire.js +56 -0
- package/dist/client.d.ts +153 -0
- package/dist/client.js +595 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +6 -0
- package/dist/native.d.ts +3 -0
- package/dist/native.js +77 -0
- package/dist/parts.d.ts +103 -0
- package/dist/parts.js +157 -0
- package/dist/react.d.ts +51 -0
- package/dist/react.js +88 -0
- package/dist/sheet.d.ts +12 -0
- package/dist/sheet.js +273 -0
- package/dist/support.d.ts +12 -0
- package/dist/support.js +60 -0
- package/dist/theme.d.ts +72 -0
- package/dist/theme.js +95 -0
- package/guide.json +136 -0
- package/package.json +114 -4
- package/recipe.json +263 -0
- package/src/analytics/README.md +32 -0
- package/src/analytics/core.ts +380 -0
- package/src/analytics/index.ts +7 -0
- package/src/analytics/recipe.json +263 -0
- package/src/analytics/rn.tsx +425 -0
- package/src/analytics/wire.ts +123 -0
- package/src/client.ts +685 -0
- package/src/index.ts +10 -0
- package/src/native.ts +90 -0
- package/src/parts.tsx +243 -0
- package/src/react.tsx +140 -0
- package/src/sheet.tsx +538 -0
- package/src/support.ts +55 -0
- package/src/theme.ts +141 -0
package/dist/sheet.js
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// The chat sheet: a bottom sheet (drag handle, spring open and close, keyboard-avoiding) holding the conversation list
|
|
3
|
+
// or one thread with receipts, typing, quick replies, the handoff to a person, attachments and the offline queue.
|
|
4
|
+
// Every visual and motion decision is logged in REFS.md.
|
|
5
|
+
import { memo, useEffect, useMemo, useRef, useState } from 'react';
|
|
6
|
+
import { AccessibilityInfo, ActionSheetIOS, Animated, Dimensions, FlatList, Image, Keyboard, LayoutAnimation, Modal, PanResponder, Platform, Pressable, StatusBar, StyleSheet, TextInput, View, useWindowDimensions } from 'react-native';
|
|
7
|
+
import { attachmentsOf, receiptOf } from './client';
|
|
8
|
+
import { ArrowUp, Avatar, Chevron, Clock, Cross, Dots, Plus, Spark, T, attachPeers, captureScreen, font, motion, pickPhoto, useReduceMotion } from './parts';
|
|
9
|
+
import { fill } from './theme';
|
|
10
|
+
function insets() {
|
|
11
|
+
try {
|
|
12
|
+
const m = require('react-native-safe-area-context')?.initialWindowMetrics?.insets;
|
|
13
|
+
if (m)
|
|
14
|
+
return { top: m.top, bottom: m.bottom };
|
|
15
|
+
}
|
|
16
|
+
catch { }
|
|
17
|
+
return Platform.OS === 'ios' ? { top: 50, bottom: 20 } : { top: StatusBar.currentHeight ?? 24, bottom: 0 };
|
|
18
|
+
}
|
|
19
|
+
const clock = (at) => {
|
|
20
|
+
const d = new Date(at);
|
|
21
|
+
return new Date().toDateString() === d.toDateString() ? d.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' }) : d.toLocaleDateString([], { month: 'short', day: 'numeric' });
|
|
22
|
+
};
|
|
23
|
+
export function Sheet({ s, c, t, title, team, quickReplies, presentation = 'modal' }) {
|
|
24
|
+
const inline = presentation === 'inline';
|
|
25
|
+
const { height } = useWindowDimensions();
|
|
26
|
+
const inset = useMemo(insets, []);
|
|
27
|
+
const H = Math.round(height - inset.top - 10);
|
|
28
|
+
const reduce = useReduceMotion();
|
|
29
|
+
const [shown, setShown] = useState(false);
|
|
30
|
+
const y = useRef(new Animated.Value(H)).current;
|
|
31
|
+
const fade = useRef(new Animated.Value(0)).current;
|
|
32
|
+
const [composing, setComposing] = useState(false);
|
|
33
|
+
const [draft, setDraft] = useState('');
|
|
34
|
+
const [pending, setPending] = useState([]);
|
|
35
|
+
const animate = (open, done) => {
|
|
36
|
+
const slide = reduce
|
|
37
|
+
? Animated.timing(y, { toValue: open ? 0 : H, duration: 0, useNativeDriver: true })
|
|
38
|
+
: Animated.spring(y, { toValue: open ? 0 : H, useNativeDriver: true, ...motion.sheet, overshootClamping: !open, restDisplacementThreshold: 0.5, restSpeedThreshold: 0.5 });
|
|
39
|
+
Animated.parallel([Animated.timing(fade, { toValue: open ? 1 : 0, duration: open ? 260 : 200, useNativeDriver: true }), slide]).start(({ finished }) => finished && done?.());
|
|
40
|
+
};
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (inline)
|
|
43
|
+
return;
|
|
44
|
+
if (s.visible) {
|
|
45
|
+
setShown(true);
|
|
46
|
+
y.setValue(H);
|
|
47
|
+
requestAnimationFrame(() => animate(true));
|
|
48
|
+
}
|
|
49
|
+
else if (shown) {
|
|
50
|
+
Keyboard.dismiss();
|
|
51
|
+
animate(false, () => setShown(false));
|
|
52
|
+
}
|
|
53
|
+
}, [s.visible]);
|
|
54
|
+
const pan = useMemo(() => PanResponder.create({
|
|
55
|
+
onMoveShouldSetPanResponder: (_, g) => g.dy > 6 && Math.abs(g.dy) > Math.abs(g.dx),
|
|
56
|
+
onPanResponderMove: (_, g) => y.setValue(Math.max(0, g.dy)),
|
|
57
|
+
onPanResponderRelease: (_, g) => (g.dy > 120 || g.vy > 1 ? s.close() : animate(true)),
|
|
58
|
+
onPanResponderTerminate: () => animate(true)
|
|
59
|
+
}), [s.close, H, reduce]);
|
|
60
|
+
// Screenshot of the app: the sheet steps aside, the screen is captured, the sheet comes back with the image attached.
|
|
61
|
+
const screenshot = () => {
|
|
62
|
+
Keyboard.dismiss();
|
|
63
|
+
animate(false, () => setTimeout(() => {
|
|
64
|
+
captureScreen()
|
|
65
|
+
.then((a) => a && setPending((p) => [...p, a]))
|
|
66
|
+
.catch(() => { })
|
|
67
|
+
.finally(() => animate(true));
|
|
68
|
+
}, 120));
|
|
69
|
+
};
|
|
70
|
+
const active = s.activeConversationId ? s.conversations.find((x) => x.id === s.activeConversationId) ?? null : null;
|
|
71
|
+
const inThread = !!s.activeConversationId || composing || s.conversations.length === 0;
|
|
72
|
+
const back = () => {
|
|
73
|
+
setComposing(false);
|
|
74
|
+
s.select(null);
|
|
75
|
+
};
|
|
76
|
+
const queued = Object.values(s.messages).reduce((n, l) => n + l.filter((m) => m.pending && m.pending !== 'failed').length, 0);
|
|
77
|
+
const status = s.status === 'live' ? { color: c.ok, text: t.online }
|
|
78
|
+
: s.status === 'offline' ? { color: c.danger, text: queued ? t.offline + ' · ' + fill(t.queuedN, { n: queued }) : t.offline }
|
|
79
|
+
: s.status === 'error' ? { color: c.danger, text: t.error + ' · ' + t.retry }
|
|
80
|
+
: { color: c.faint, text: t.connecting };
|
|
81
|
+
const bottom = inline ? 0 : inset.bottom;
|
|
82
|
+
const body = (_jsxs(_Fragment, { children: [_jsxs(View, { ...(inline ? {} : pan.panHandlers), children: [_jsx(View, { style: [st.grabber, { backgroundColor: c.line }] }), _jsxs(View, { style: st.header, children: [inThread && s.conversations.length > 0 ? (_jsx(Pressable, { onPress: back, hitSlop: 10, accessibilityRole: "button", accessibilityLabel: t.back, style: st.back, children: _jsx(Chevron, { color: c.text }) })) : null, _jsx(Avatar, { c: c, label: title, size: 32 }), _jsxs(View, { style: st.fill, children: [_jsx(T, { c: c, bold: true, style: st.title, numberOfLines: 1, accessibilityRole: "header", children: title }), _jsxs(Pressable, { disabled: s.status !== 'error', onPress: () => s.identify(), style: st.statusRow, accessibilityRole: s.status === 'error' ? 'button' : undefined, accessibilityLiveRegion: "polite", children: [_jsx(View, { style: [st.dot, { backgroundColor: status.color }] }), _jsx(T, { c: c, style: [st.status, { color: c.sub }], numberOfLines: 1, children: status.text })] })] }), _jsx(Pressable, { onPress: s.close, hitSlop: 10, accessibilityRole: "button", accessibilityLabel: t.close, style: [st.close, { backgroundColor: c.raised }], children: _jsx(Cross, { color: c.sub, size: 9 }) })] })] }), _jsx(View, { style: [st.hair, { backgroundColor: c.line }] }), inThread ? (_jsx(Thread, { s: s, c: c, t: t, team: team, conversation: active, quickReplies: quickReplies, reduce: reduce, inset: bottom, draft: draft, setDraft: setDraft, pending: pending, setPending: setPending, onScreenshot: screenshot, onSent: () => setComposing(false) })) : (_jsx(List, { s: s, c: c, t: t, inset: bottom, onNew: () => setComposing(true) }))] }));
|
|
83
|
+
if (inline)
|
|
84
|
+
return _jsx(View, { style: [st.fill, { backgroundColor: c.bg }], children: body });
|
|
85
|
+
return (_jsxs(Modal, { visible: shown, transparent: true, animationType: "none", statusBarTranslucent: true, onRequestClose: s.close, children: [_jsx(Animated.View, { style: [StyleSheet.absoluteFill, { backgroundColor: c.backdrop, opacity: fade }], children: _jsx(Pressable, { style: st.fill, onPress: s.close, accessibilityLabel: t.close }) }), _jsx(Animated.View, { accessibilityViewIsModal: true, style: [st.sheet, { height: H, backgroundColor: c.bg, borderTopStartRadius: c.radius + 10, borderTopEndRadius: c.radius + 10, opacity: reduce ? fade : 1, transform: [{ translateY: y }] }], children: body })] }));
|
|
86
|
+
}
|
|
87
|
+
function List({ s, c, t, inset, onNew }) {
|
|
88
|
+
return (_jsxs(View, { style: st.fill, children: [_jsx(FlatList, { data: s.conversations, keyExtractor: (x) => x.id, contentContainerStyle: st.listPad, renderItem: ({ item }) => _jsx(ConvRow, { c: c, t: t, conv: item, unread: !!s.unreadBy[item.id], onPress: () => s.select(item.id) }) }), _jsx(View, { style: [st.footer, { paddingBottom: 12 + inset }], children: _jsxs(Pressable, { onPress: onNew, accessibilityRole: "button", style: ({ pressed }) => [st.cta, { backgroundColor: c.accent, opacity: pressed ? 0.85 : 1 }], children: [_jsx(Plus, { color: c.onAccent }), _jsx(T, { c: c, bold: true, style: [st.ctaText, { color: c.onAccent }], children: t.newMessage })] }) })] }));
|
|
89
|
+
}
|
|
90
|
+
const ConvRow = memo(function ConvRow({ c, t, conv, unread, onPress }) {
|
|
91
|
+
const pill = conv.status === 'needs_human' ? { text: t.person, color: c.warn } : conv.status === 'resolved' || conv.status === 'closed' ? { text: t.resolved, color: c.ok } : null;
|
|
92
|
+
const who = conv.lastAuthor === 'user' ? t.you + ': ' : conv.lastAuthor === 'ai' ? t.ai + ': ' : '';
|
|
93
|
+
return (_jsxs(Pressable, { onPress: onPress, accessibilityRole: "button", style: ({ pressed }) => [st.row, pressed && { backgroundColor: c.raised }], children: [_jsx(Avatar, { c: c, label: conv.subject ?? '?', size: 36, ai: conv.lastAuthor === 'ai' }), _jsxs(View, { style: st.fill, children: [_jsxs(View, { style: st.rowTop, children: [_jsx(T, { c: c, bold: unread, style: st.rowTitle, numberOfLines: 1, children: conv.subject ?? t.newMessage }), _jsx(T, { c: c, style: [st.meta, { color: c.faint }], children: clock(conv.lastMessageAt) })] }), _jsxs(View, { style: st.rowTop, children: [_jsx(T, { c: c, style: [st.preview, { color: unread ? c.text : c.sub }], numberOfLines: 1, children: who + (conv.lastPreview ?? '') }), pill ? (_jsx(View, { style: [st.pill, { backgroundColor: pill.color + '22' }], children: _jsx(T, { c: c, bold: true, style: [st.pillText, { color: pill.color }], children: pill.text }) })) : null, unread ? _jsx(View, { style: [st.unread, { backgroundColor: c.accent }] }) : null] })] })] }));
|
|
94
|
+
});
|
|
95
|
+
function Thread({ s, c, t, team, conversation, quickReplies, reduce, inset, draft, setDraft, pending, setPending, onScreenshot, onSent }) {
|
|
96
|
+
const id = s.activeConversationId;
|
|
97
|
+
const messages = (id && s.messages[id]) || [];
|
|
98
|
+
const typing = id ? s.typing[id] : undefined;
|
|
99
|
+
const offline = s.status !== 'live';
|
|
100
|
+
const handed = conversation?.status === 'needs_human';
|
|
101
|
+
const closed = conversation?.status === 'resolved' || conversation?.status === 'closed';
|
|
102
|
+
const since = useRef(Date.now()).current;
|
|
103
|
+
const rows = useMemo(() => {
|
|
104
|
+
const out = [];
|
|
105
|
+
const lastMine = messages.reduce((at, m, i) => (m.author === 'user' ? i : at), -1);
|
|
106
|
+
messages.forEach((m, i) => {
|
|
107
|
+
const prev = messages[i - 1];
|
|
108
|
+
const first = !prev || prev.author !== m.author || m.createdAt - prev.createdAt > 5 * 60000;
|
|
109
|
+
const label = m.author === 'ai' || m.author === 'founder' ? (first ? (m.author === 'ai' ? t.ai : team) : null) : null;
|
|
110
|
+
const receipt = i === lastMine || m.pending ? receiptOf(m, messages, conversation ?? undefined, offline) : null;
|
|
111
|
+
out.push({ k: m.localId ?? m.id, kind: 'msg', m, label, receipt, gap: first ? 12 : 3 });
|
|
112
|
+
});
|
|
113
|
+
const last = messages[messages.length - 1];
|
|
114
|
+
if (typing)
|
|
115
|
+
out.push({ k: 'typing', kind: 'typing', who: typing === 'ai' ? t.ai : team });
|
|
116
|
+
else if (last?.author === 'ai' && !handed && !closed) {
|
|
117
|
+
const q = Array.isArray(last.meta?.['quickReplies']) ? last.meta['quickReplies'] : [];
|
|
118
|
+
out.push({ k: 'chips' + last.id, kind: 'chips', items: q.slice(0, 3), talk: true });
|
|
119
|
+
}
|
|
120
|
+
return out.reverse();
|
|
121
|
+
}, [messages, typing, conversation, offline, handed, closed, t, team]);
|
|
122
|
+
const last = messages[messages.length - 1];
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
if (last && last.author !== 'user' && last.createdAt > since)
|
|
125
|
+
AccessibilityInfo.announceForAccessibility?.((last.author === 'ai' ? t.ai : team) + ': ' + last.body);
|
|
126
|
+
}, [last?.id]);
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
if (typing)
|
|
129
|
+
AccessibilityInfo.announceForAccessibility?.(fill(t.typing, { who: typing === 'ai' ? t.ai : team }));
|
|
130
|
+
}, [typing]);
|
|
131
|
+
const send = (body, atts = []) => {
|
|
132
|
+
s.send(body, id, atts);
|
|
133
|
+
onSent();
|
|
134
|
+
};
|
|
135
|
+
const kb = useKeyboardInset();
|
|
136
|
+
const empty = !messages.length;
|
|
137
|
+
return (_jsxs(View, { style: [st.fill, { paddingBottom: kb }], children: [empty ? (_jsxs(View, { style: st.empty, children: [_jsx(Avatar, { c: c, label: team, size: 44 }), _jsx(T, { c: c, bold: true, style: st.greet, accessibilityRole: "header", children: t.greeting }), _jsx(Chips, { c: c, items: quickReplies, reduce: reduce, onPick: (q) => send(q), center: true })] })) : (_jsx(FlatList, { inverted: true, data: rows, keyExtractor: (r) => r.k, contentContainerStyle: st.thread, keyboardShouldPersistTaps: "handled", keyboardDismissMode: "interactive", initialNumToRender: 14, windowSize: 9, removeClippedSubviews: Platform.OS === 'android', renderItem: ({ item }) => item.kind === 'msg' ? (_jsx(Bubble, { r: item, c: c, t: t, fresh: item.m.createdAt > since - 1000, reduce: reduce, url: s.url, onRetry: s.retry })) : item.kind === 'typing' ? (_jsxs(View, { style: [st.theirs, st.typing], accessible: true, accessibilityLabel: fill(t.typing, { who: item.who }), children: [_jsx(T, { c: c, style: [st.label, { color: c.sub }], children: item.who }), _jsx(View, { style: [st.bubble, { backgroundColor: c.raised, borderRadius: c.radius }], children: _jsx(Dots, { color: c.sub, reduce: reduce }) })] })) : (_jsx(Chips, { c: c, items: item.items, reduce: reduce, onPick: (q) => send(q), talk: t.talk, onTalk: () => id && s.handoff(id) })) })), handed ? (_jsxs(View, { style: [st.strip, { borderColor: c.line }], accessibilityLiveRegion: "polite", children: [_jsx(View, { style: [st.stripBar, { backgroundColor: c.warn }] }), _jsx(T, { c: c, style: [st.stripText, { color: c.sub }], children: t.handedOff })] })) : null, _jsx(Composer, { c: c, t: t, inset: inset, draft: draft, setDraft: setDraft, pending: pending, setPending: setPending, onScreenshot: onScreenshot, onSend: () => {
|
|
138
|
+
send(draft, pending);
|
|
139
|
+
setDraft('');
|
|
140
|
+
setPending(() => []);
|
|
141
|
+
} })] }));
|
|
142
|
+
}
|
|
143
|
+
const Bubble = memo(function Bubble({ r, c, t, fresh, reduce, url, onRetry }) {
|
|
144
|
+
const { m } = r;
|
|
145
|
+
const v = useRef(new Animated.Value(fresh && !reduce ? 0 : 1)).current;
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
if (fresh && !reduce)
|
|
148
|
+
Animated.timing(v, { toValue: 1, useNativeDriver: true, ...motion.bubble }).start();
|
|
149
|
+
}, []);
|
|
150
|
+
if (m.author === 'system')
|
|
151
|
+
return (_jsx(View, { style: [st.system, { marginTop: r.gap }], children: _jsx(T, { c: c, style: [st.systemText, { color: c.sub }], children: m.body }) }));
|
|
152
|
+
const mine = m.author === 'user';
|
|
153
|
+
const atts = attachmentsOf(m);
|
|
154
|
+
const rc = r.receipt;
|
|
155
|
+
const receiptText = rc ? (rc === 'failed' ? t.failed : t[rc] + (rc === 'seen' || rc === 'delivered' || rc === 'sent' ? ' · ' + clock(m.createdAt) : '')) : null;
|
|
156
|
+
const anim = { opacity: v, transform: [{ translateY: v.interpolate({ inputRange: [0, 1], outputRange: [4, 0] }) }] };
|
|
157
|
+
return (_jsxs(Animated.View, { style: [mine ? st.mine : st.theirs, { marginTop: r.gap }, anim], accessible: true, accessibilityLabel: (mine ? t.you : r.label ?? '') + ': ' + (m.body || t.photo) + (receiptText ? '. ' + receiptText : ''), children: [r.label ? (_jsxs(View, { style: st.labelRow, children: [m.author === 'ai' ? _jsx(Spark, { color: c.accent, size: 6 }) : null, _jsx(T, { c: c, style: [st.label, { color: c.sub }], children: r.label })] })) : null, atts.map((a, i) => {
|
|
158
|
+
const w = 200;
|
|
159
|
+
const h = a.width && a.height ? Math.min(260, Math.round((w * a.height) / a.width)) : 150;
|
|
160
|
+
return _jsx(Image, { source: { uri: a.uri ?? url(a.path ?? '') }, style: [st.image, { width: w, height: h, borderRadius: c.radius - 4, backgroundColor: c.raised, opacity: m.pending ? 0.6 : 1 }], accessibilityIgnoresInvertColors: true }, i);
|
|
161
|
+
}), m.body ? (_jsx(View, { style: [st.bubble, { backgroundColor: mine ? c.accent : c.raised, borderRadius: c.radius, opacity: m.pending === 'failed' ? 0.6 : 1 }], children: _jsx(T, { c: c, style: [st.body, { color: mine ? c.onAccent : c.text }], children: m.body }) })) : null, receiptText ? (_jsxs(Pressable, { disabled: rc !== 'failed', onPress: () => m.localId && onRetry(m.localId), hitSlop: 8, style: st.receipt, accessibilityRole: rc === 'failed' ? 'button' : undefined, children: [rc === 'queued' ? _jsx(Clock, { color: c.faint }) : null, _jsx(T, { c: c, style: [st.receiptText, { color: rc === 'failed' ? c.danger : c.faint }], children: receiptText })] })) : null] }));
|
|
162
|
+
});
|
|
163
|
+
function Chips({ c, items, reduce, onPick, talk, onTalk, center }) {
|
|
164
|
+
const all = talk ? [...items, talk] : items;
|
|
165
|
+
const vals = useRef(all.map(() => new Animated.Value(reduce ? 1 : 0))).current;
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
if (!reduce)
|
|
168
|
+
Animated.stagger(motion.chips.stagger, vals.map((v) => Animated.timing(v, { toValue: 1, duration: motion.chips.duration, useNativeDriver: true }))).start();
|
|
169
|
+
}, []);
|
|
170
|
+
if (!all.length)
|
|
171
|
+
return null;
|
|
172
|
+
return (_jsx(View, { style: [st.chips, center && st.chipsCenter], children: all.map((q, i) => {
|
|
173
|
+
const isTalk = !!talk && i === all.length - 1;
|
|
174
|
+
const v = vals[i] ?? new Animated.Value(1);
|
|
175
|
+
return (_jsx(Animated.View, { style: { opacity: v, transform: [{ translateY: v.interpolate({ inputRange: [0, 1], outputRange: [6, 0] }) }] }, children: _jsx(Pressable, { onPress: () => (isTalk ? onTalk?.() : onPick(q)), accessibilityRole: "button", style: ({ pressed }) => [st.chip, { borderColor: isTalk ? c.accent + '55' : c.line, backgroundColor: pressed ? c.raised : c.bg }], children: _jsx(T, { c: c, style: [st.chipText, { color: isTalk ? c.accent : c.text }], children: q }) }) }, q + i));
|
|
176
|
+
}) }));
|
|
177
|
+
}
|
|
178
|
+
function useKeyboardInset() {
|
|
179
|
+
const [h, setH] = useState(0);
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
if (Platform.OS !== 'ios')
|
|
182
|
+
return;
|
|
183
|
+
const move = (e, next) => {
|
|
184
|
+
LayoutAnimation.configureNext({ duration: e.duration || 250, update: { type: LayoutAnimation.Types.keyboard } });
|
|
185
|
+
setH(next);
|
|
186
|
+
};
|
|
187
|
+
const a = Keyboard.addListener('keyboardWillChangeFrame', (e) => {
|
|
188
|
+
const screen = Dimensions.get('screen').height;
|
|
189
|
+
move(e, Math.max(0, screen - e.endCoordinates.screenY));
|
|
190
|
+
});
|
|
191
|
+
const b = Keyboard.addListener('keyboardWillHide', (e) => move(e, 0));
|
|
192
|
+
return () => (a.remove(), b.remove());
|
|
193
|
+
}, []);
|
|
194
|
+
return h;
|
|
195
|
+
}
|
|
196
|
+
function Composer({ c, t, inset, draft, setDraft, pending, setPending, onScreenshot, onSend }) {
|
|
197
|
+
const [kb, setKb] = useState(false);
|
|
198
|
+
const [menu, setMenu] = useState(false);
|
|
199
|
+
useEffect(() => {
|
|
200
|
+
const ios = Platform.OS === 'ios';
|
|
201
|
+
const a = Keyboard.addListener(ios ? 'keyboardWillShow' : 'keyboardDidShow', () => setKb(true));
|
|
202
|
+
const b = Keyboard.addListener(ios ? 'keyboardWillHide' : 'keyboardDidHide', () => setKb(false));
|
|
203
|
+
return () => (a.remove(), b.remove());
|
|
204
|
+
}, []);
|
|
205
|
+
const peers = attachPeers();
|
|
206
|
+
const photo = () => pickPhoto().then((a) => a && setPending((p) => [...p, a]), () => { });
|
|
207
|
+
const options = [peers.picker ? { label: t.photo, run: photo } : null, peers.shot ? { label: t.screenshot, run: onScreenshot } : null].filter((x) => !!x);
|
|
208
|
+
const attach = () => {
|
|
209
|
+
if (options.length === 1)
|
|
210
|
+
return options[0].run();
|
|
211
|
+
if (Platform.OS === 'ios')
|
|
212
|
+
return ActionSheetIOS.showActionSheetWithOptions({ options: [...options.map((o) => o.label), t.cancel], cancelButtonIndex: options.length }, (i) => options[i]?.run());
|
|
213
|
+
setMenu((x) => !x);
|
|
214
|
+
};
|
|
215
|
+
const ready = !!draft.trim() || pending.length > 0;
|
|
216
|
+
return (_jsxs(View, { style: [st.composer, { paddingBottom: kb ? 8 : 8 + inset }], children: [menu ? (_jsx(View, { style: st.chips, children: options.map((o) => (_jsx(Pressable, { onPress: () => (setMenu(false), o.run()), accessibilityRole: "button", style: [st.chip, { borderColor: c.line }], children: _jsx(T, { c: c, style: st.chipText, children: o.label }) }, o.label))) })) : null, pending.length ? (_jsx(View, { style: st.pending, children: pending.map((a, i) => (_jsxs(View, { children: [_jsx(Image, { source: { uri: a.uri }, style: [st.thumb, { borderRadius: c.radius / 2, backgroundColor: c.raised }] }), _jsx(Pressable, { onPress: () => setPending((p) => p.filter((_, j) => j !== i)), hitSlop: 8, accessibilityRole: "button", accessibilityLabel: t.remove, style: [st.thumbX, { backgroundColor: c.text, borderColor: c.bg }], children: _jsx(Cross, { color: c.bg, size: 7 }) })] }, a.uri + i))) })) : null, _jsxs(View, { style: [st.field, { borderColor: c.line, borderRadius: c.radius + 4, backgroundColor: c.bg }], children: [options.length ? (_jsx(Pressable, { onPress: attach, hitSlop: 6, accessibilityRole: "button", accessibilityLabel: t.attach, style: st.attach, children: _jsx(Plus, { color: c.sub }) })) : (_jsx(View, { style: st.attachGap })), _jsx(TextInput, { value: draft, onChangeText: setDraft, placeholder: t.placeholder, placeholderTextColor: c.faint, multiline: true, maxFontSizeMultiplier: 2, accessibilityLabel: t.placeholder, style: [st.input, font(c), { color: c.text }] }), _jsx(Pressable, { onPress: onSend, disabled: !ready, accessibilityRole: "button", accessibilityLabel: t.send, accessibilityState: { disabled: !ready }, style: [st.send, { backgroundColor: ready ? c.accent : c.raised }], children: _jsx(ArrowUp, { color: ready ? c.onAccent : c.faint }) })] })] }));
|
|
217
|
+
}
|
|
218
|
+
const st = StyleSheet.create({
|
|
219
|
+
fill: { flex: 1 },
|
|
220
|
+
sheet: { position: 'absolute', start: 0, end: 0, bottom: 0, overflow: 'hidden' },
|
|
221
|
+
grabber: { alignSelf: 'center', width: 36, height: 5, borderRadius: 2.5, marginTop: 8 },
|
|
222
|
+
header: { flexDirection: 'row', alignItems: 'center', gap: 10, paddingHorizontal: 16, paddingTop: 10, paddingBottom: 12 },
|
|
223
|
+
back: { width: 24, height: 32, justifyContent: 'center' },
|
|
224
|
+
title: { fontSize: 16, lineHeight: 20 },
|
|
225
|
+
statusRow: { flexDirection: 'row', alignItems: 'center', gap: 5, marginTop: 1, alignSelf: 'flex-start' },
|
|
226
|
+
dot: { width: 6, height: 6, borderRadius: 3 },
|
|
227
|
+
status: { fontSize: 12, lineHeight: 16 },
|
|
228
|
+
close: { width: 28, height: 28, borderRadius: 14, alignItems: 'center', justifyContent: 'center' },
|
|
229
|
+
hair: { height: StyleSheet.hairlineWidth },
|
|
230
|
+
listPad: { paddingVertical: 6 },
|
|
231
|
+
row: { flexDirection: 'row', alignItems: 'center', gap: 12, paddingHorizontal: 16, paddingVertical: 10 },
|
|
232
|
+
rowTop: { flexDirection: 'row', alignItems: 'center', gap: 8 },
|
|
233
|
+
rowTitle: { flex: 1, fontSize: 15, lineHeight: 20 },
|
|
234
|
+
preview: { flex: 1, fontSize: 14, lineHeight: 19 },
|
|
235
|
+
meta: { fontSize: 12, fontVariant: ['tabular-nums'] },
|
|
236
|
+
unread: { width: 8, height: 8, borderRadius: 4 },
|
|
237
|
+
pill: { borderRadius: 999, paddingHorizontal: 7, paddingVertical: 2 },
|
|
238
|
+
pillText: { fontSize: 11, lineHeight: 14 },
|
|
239
|
+
footer: { paddingHorizontal: 16, paddingTop: 8 },
|
|
240
|
+
cta: { minHeight: 46, borderRadius: 23, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 8, paddingHorizontal: 20 },
|
|
241
|
+
ctaText: { fontSize: 16 },
|
|
242
|
+
empty: { flex: 1, alignItems: 'center', justifyContent: 'center', paddingHorizontal: 24, gap: 12 },
|
|
243
|
+
greet: { fontSize: 20, lineHeight: 26, textAlign: 'center' },
|
|
244
|
+
thread: { paddingHorizontal: 14, paddingVertical: 12 },
|
|
245
|
+
mine: { alignSelf: 'flex-end', alignItems: 'flex-end', maxWidth: '82%' },
|
|
246
|
+
theirs: { alignSelf: 'flex-start', alignItems: 'flex-start', maxWidth: '82%' },
|
|
247
|
+
typing: { marginTop: 12 },
|
|
248
|
+
labelRow: { flexDirection: 'row', alignItems: 'center', gap: 5, marginBottom: 4, marginStart: 4 },
|
|
249
|
+
label: { fontSize: 12, lineHeight: 16 },
|
|
250
|
+
bubble: { paddingHorizontal: 13, paddingVertical: 8 },
|
|
251
|
+
body: { fontSize: 16, lineHeight: 21 },
|
|
252
|
+
image: { marginBottom: 3 },
|
|
253
|
+
receipt: { flexDirection: 'row', alignItems: 'center', gap: 4, marginTop: 4, marginEnd: 4 },
|
|
254
|
+
receiptText: { fontSize: 12, lineHeight: 16 },
|
|
255
|
+
system: { alignSelf: 'center', paddingVertical: 4 },
|
|
256
|
+
systemText: { fontSize: 12, lineHeight: 16, textAlign: 'center' },
|
|
257
|
+
chips: { flexDirection: 'row', flexWrap: 'wrap', gap: 8, marginTop: 12 },
|
|
258
|
+
chipsCenter: { justifyContent: 'center' },
|
|
259
|
+
chip: { minHeight: 34, borderRadius: 17, borderWidth: 1, paddingHorizontal: 14, justifyContent: 'center' },
|
|
260
|
+
chipText: { fontSize: 15, lineHeight: 20 },
|
|
261
|
+
strip: { flexDirection: 'row', alignItems: 'center', gap: 10, marginHorizontal: 12, marginBottom: 2, paddingVertical: 8 },
|
|
262
|
+
stripBar: { width: 3, height: 16, borderRadius: 1.5 },
|
|
263
|
+
stripText: { fontSize: 13, lineHeight: 18 },
|
|
264
|
+
composer: { paddingHorizontal: 12, paddingTop: 6 },
|
|
265
|
+
pending: { flexDirection: 'row', gap: 8, paddingBottom: 8, paddingHorizontal: 4 },
|
|
266
|
+
thumb: { width: 56, height: 56 },
|
|
267
|
+
thumbX: { position: 'absolute', top: -6, end: -6, width: 20, height: 20, borderRadius: 10, borderWidth: 2, alignItems: 'center', justifyContent: 'center' },
|
|
268
|
+
field: { flexDirection: 'row', alignItems: 'flex-end', borderWidth: 1, paddingEnd: 5, paddingVertical: 5 },
|
|
269
|
+
attach: { width: 38, height: 32, alignItems: 'center', justifyContent: 'center' },
|
|
270
|
+
attachGap: { width: 12 },
|
|
271
|
+
input: { flex: 1, minHeight: 32, maxHeight: 132, fontSize: 16, lineHeight: 21, paddingTop: 6, paddingBottom: 5, paddingHorizontal: 0 },
|
|
272
|
+
send: { width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center', marginStart: 6 }
|
|
273
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SupportClient } from './client';
|
|
2
|
+
import type { SupportConfig, UserInfo } from './client';
|
|
3
|
+
export declare const ShotikSupport: {
|
|
4
|
+
configure(config: SupportConfig): SupportClient;
|
|
5
|
+
readonly client: SupportClient | null;
|
|
6
|
+
onConfigure(fn: (c: SupportClient) => void): () => void;
|
|
7
|
+
identify(user?: UserInfo): Promise<void>;
|
|
8
|
+
setPushToken(token: string | null, platform?: string): Promise<void>;
|
|
9
|
+
open(conversationId?: string | null): void;
|
|
10
|
+
close(): void;
|
|
11
|
+
reset(): Promise<void>;
|
|
12
|
+
};
|
package/dist/support.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// The app-facing singleton: configure once, identify after sign-in, open the widget from anywhere. Calls made before
|
|
2
|
+
// configure() (an auth listener at module scope, a push token on launch) are held and applied when it runs.
|
|
3
|
+
import { Platform } from 'react-native';
|
|
4
|
+
import { SupportClient } from './client';
|
|
5
|
+
import { nativeDevice, nativeStorage } from './native';
|
|
6
|
+
let current = null;
|
|
7
|
+
const watchers = new Set();
|
|
8
|
+
const held = { user: null, push: null, open: false };
|
|
9
|
+
export const ShotikSupport = {
|
|
10
|
+
configure(config) {
|
|
11
|
+
if (current && current.config.appKey === config.appKey && current.config.serverUrl === config.serverUrl.replace(/\/+$/, ''))
|
|
12
|
+
return current;
|
|
13
|
+
current?.stop();
|
|
14
|
+
const c = new SupportClient({ storage: nativeStorage(), device: nativeDevice, ...config });
|
|
15
|
+
current = c;
|
|
16
|
+
if (held.push)
|
|
17
|
+
c.setPushToken(held.push.token, held.push.platform).catch(() => { });
|
|
18
|
+
if (held.user)
|
|
19
|
+
c.identify(held.user).catch(() => { });
|
|
20
|
+
if (held.open)
|
|
21
|
+
c.open();
|
|
22
|
+
held.user = held.push = null;
|
|
23
|
+
held.open = false;
|
|
24
|
+
for (const fn of watchers)
|
|
25
|
+
fn(c);
|
|
26
|
+
return c;
|
|
27
|
+
},
|
|
28
|
+
get client() {
|
|
29
|
+
return current;
|
|
30
|
+
},
|
|
31
|
+
onConfigure(fn) {
|
|
32
|
+
watchers.add(fn);
|
|
33
|
+
return () => void watchers.delete(fn);
|
|
34
|
+
},
|
|
35
|
+
identify(user = {}) {
|
|
36
|
+
if (current)
|
|
37
|
+
return current.identify(user);
|
|
38
|
+
held.user = { ...held.user, ...user };
|
|
39
|
+
return Promise.resolve();
|
|
40
|
+
},
|
|
41
|
+
setPushToken(token, platform = Platform.OS) {
|
|
42
|
+
if (current)
|
|
43
|
+
return current.setPushToken(token, platform);
|
|
44
|
+
held.push = { token, platform };
|
|
45
|
+
return Promise.resolve();
|
|
46
|
+
},
|
|
47
|
+
open(conversationId) {
|
|
48
|
+
if (current)
|
|
49
|
+
current.open(conversationId);
|
|
50
|
+
else
|
|
51
|
+
held.open = true;
|
|
52
|
+
},
|
|
53
|
+
close() {
|
|
54
|
+
current?.close();
|
|
55
|
+
},
|
|
56
|
+
reset() {
|
|
57
|
+
held.user = null;
|
|
58
|
+
return current ? current.reset() : Promise.resolve();
|
|
59
|
+
}
|
|
60
|
+
};
|
package/dist/theme.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export interface Colors {
|
|
2
|
+
bg: string;
|
|
3
|
+
raised: string;
|
|
4
|
+
line: string;
|
|
5
|
+
text: string;
|
|
6
|
+
sub: string;
|
|
7
|
+
faint: string;
|
|
8
|
+
danger: string;
|
|
9
|
+
ok: string;
|
|
10
|
+
warn: string;
|
|
11
|
+
backdrop: string;
|
|
12
|
+
}
|
|
13
|
+
export interface SupportTheme {
|
|
14
|
+
accent?: string;
|
|
15
|
+
onAccent?: string;
|
|
16
|
+
radius?: number;
|
|
17
|
+
font?: string;
|
|
18
|
+
fontBold?: string;
|
|
19
|
+
scheme?: 'light' | 'dark';
|
|
20
|
+
light?: Partial<Colors>;
|
|
21
|
+
dark?: Partial<Colors>;
|
|
22
|
+
}
|
|
23
|
+
export interface Resolved extends Colors {
|
|
24
|
+
dark: boolean;
|
|
25
|
+
accent: string;
|
|
26
|
+
onAccent: string;
|
|
27
|
+
radius: number;
|
|
28
|
+
font?: string;
|
|
29
|
+
fontBold?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare function resolveTheme(t: SupportTheme | undefined, system: 'light' | 'dark'): Resolved;
|
|
32
|
+
declare const en: {
|
|
33
|
+
title: string;
|
|
34
|
+
greeting: string;
|
|
35
|
+
online: string;
|
|
36
|
+
connecting: string;
|
|
37
|
+
offline: string;
|
|
38
|
+
queuedN: string;
|
|
39
|
+
error: string;
|
|
40
|
+
retry: string;
|
|
41
|
+
newMessage: string;
|
|
42
|
+
placeholder: string;
|
|
43
|
+
send: string;
|
|
44
|
+
close: string;
|
|
45
|
+
back: string;
|
|
46
|
+
attach: string;
|
|
47
|
+
photo: string;
|
|
48
|
+
screenshot: string;
|
|
49
|
+
cancel: string;
|
|
50
|
+
remove: string;
|
|
51
|
+
sending: string;
|
|
52
|
+
queued: string;
|
|
53
|
+
sent: string;
|
|
54
|
+
delivered: string;
|
|
55
|
+
seen: string;
|
|
56
|
+
failed: string;
|
|
57
|
+
ai: string;
|
|
58
|
+
team: string;
|
|
59
|
+
you: string;
|
|
60
|
+
talk: string;
|
|
61
|
+
handedOff: string;
|
|
62
|
+
resolved: string;
|
|
63
|
+
person: string;
|
|
64
|
+
typing: string;
|
|
65
|
+
open: string;
|
|
66
|
+
unreadN: string;
|
|
67
|
+
};
|
|
68
|
+
export type Copy = typeof en;
|
|
69
|
+
export declare const catalogs: Record<string, Copy>;
|
|
70
|
+
export declare function copyFor(locale?: string): Copy;
|
|
71
|
+
export declare const fill: (s: string, v: Record<string, string | number>) => string;
|
|
72
|
+
export {};
|
package/dist/theme.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Brand theme and copy for the widget. Colors follow the system scheme; the founder's brand sets accent, radius and
|
|
2
|
+
// font. Copy is a small en/ru catalog picked from the device locale (or the locale prop), falling back to en.
|
|
3
|
+
const base = {
|
|
4
|
+
light: { bg: '#FFFFFF', raised: '#F2F2F4', line: 'rgba(0,0,0,0.08)', text: '#0B0B0C', sub: '#6B6B73', faint: '#A3A3AB', danger: '#E5484D', ok: '#30A46C', warn: '#E38A1B', backdrop: 'rgba(0,0,0,0.32)' },
|
|
5
|
+
dark: { bg: '#161617', raised: '#252527', line: 'rgba(255,255,255,0.09)', text: '#F4F4F5', sub: '#9B9BA3', faint: '#6B6B73', danger: '#FF6369', ok: '#3DD68C', warn: '#FFB224', backdrop: 'rgba(0,0,0,0.5)' }
|
|
6
|
+
};
|
|
7
|
+
export function resolveTheme(t, system) {
|
|
8
|
+
const scheme = t?.scheme ?? system;
|
|
9
|
+
const dark = scheme === 'dark';
|
|
10
|
+
return { ...base[scheme], ...t?.[scheme], dark, accent: t?.accent ?? (dark ? '#0A84FF' : '#007AFF'), onAccent: t?.onAccent ?? '#FFFFFF', radius: t?.radius ?? 18, font: t?.font, fontBold: t?.fontBold };
|
|
11
|
+
}
|
|
12
|
+
const en = {
|
|
13
|
+
title: 'Support',
|
|
14
|
+
greeting: 'How can we help?',
|
|
15
|
+
online: 'Online',
|
|
16
|
+
connecting: 'Connecting',
|
|
17
|
+
offline: 'Offline',
|
|
18
|
+
queuedN: '{n} queued',
|
|
19
|
+
error: "Couldn't connect",
|
|
20
|
+
retry: 'Retry',
|
|
21
|
+
newMessage: 'New message',
|
|
22
|
+
placeholder: 'Message',
|
|
23
|
+
send: 'Send',
|
|
24
|
+
close: 'Close',
|
|
25
|
+
back: 'Back',
|
|
26
|
+
attach: 'Attach',
|
|
27
|
+
photo: 'Photo',
|
|
28
|
+
screenshot: 'Screenshot',
|
|
29
|
+
cancel: 'Cancel',
|
|
30
|
+
remove: 'Remove',
|
|
31
|
+
sending: 'Sending',
|
|
32
|
+
queued: "Will send when you're back online",
|
|
33
|
+
sent: 'Sent',
|
|
34
|
+
delivered: 'Delivered',
|
|
35
|
+
seen: 'Seen',
|
|
36
|
+
failed: 'Not sent · Retry',
|
|
37
|
+
ai: 'AI',
|
|
38
|
+
team: 'Team',
|
|
39
|
+
you: 'You',
|
|
40
|
+
talk: 'Talk to a person',
|
|
41
|
+
handedOff: 'A person will reply',
|
|
42
|
+
resolved: 'Resolved',
|
|
43
|
+
person: 'Person',
|
|
44
|
+
typing: '{who} is typing',
|
|
45
|
+
open: 'Open support',
|
|
46
|
+
unreadN: '{n} unread'
|
|
47
|
+
};
|
|
48
|
+
const ru = {
|
|
49
|
+
title: 'Поддержка',
|
|
50
|
+
greeting: 'Чем помочь?',
|
|
51
|
+
online: 'В сети',
|
|
52
|
+
connecting: 'Подключаемся',
|
|
53
|
+
offline: 'Нет сети',
|
|
54
|
+
queuedN: 'В очереди: {n}',
|
|
55
|
+
error: 'Не удалось подключиться',
|
|
56
|
+
retry: 'Повторить',
|
|
57
|
+
newMessage: 'Новое сообщение',
|
|
58
|
+
placeholder: 'Сообщение',
|
|
59
|
+
send: 'Отправить',
|
|
60
|
+
close: 'Закрыть',
|
|
61
|
+
back: 'Назад',
|
|
62
|
+
attach: 'Прикрепить',
|
|
63
|
+
photo: 'Фото',
|
|
64
|
+
screenshot: 'Снимок экрана',
|
|
65
|
+
cancel: 'Отмена',
|
|
66
|
+
remove: 'Убрать',
|
|
67
|
+
sending: 'Отправляется',
|
|
68
|
+
queued: 'Отправим, когда появится связь',
|
|
69
|
+
sent: 'Отправлено',
|
|
70
|
+
delivered: 'Доставлено',
|
|
71
|
+
seen: 'Прочитано',
|
|
72
|
+
failed: 'Не отправлено · Повторить',
|
|
73
|
+
ai: 'ИИ',
|
|
74
|
+
team: 'Команда',
|
|
75
|
+
you: 'Вы',
|
|
76
|
+
talk: 'Позвать человека',
|
|
77
|
+
handedOff: 'Ответит человек',
|
|
78
|
+
resolved: 'Решено',
|
|
79
|
+
person: 'Человек',
|
|
80
|
+
typing: '{who} печатает',
|
|
81
|
+
open: 'Открыть поддержку',
|
|
82
|
+
unreadN: 'Непрочитанных: {n}'
|
|
83
|
+
};
|
|
84
|
+
export const catalogs = { en, ru };
|
|
85
|
+
export function copyFor(locale) {
|
|
86
|
+
let tag = locale;
|
|
87
|
+
if (!tag) {
|
|
88
|
+
try {
|
|
89
|
+
tag = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
90
|
+
}
|
|
91
|
+
catch { }
|
|
92
|
+
}
|
|
93
|
+
return catalogs[(tag ?? 'en').slice(0, 2).toLowerCase()] ?? en;
|
|
94
|
+
}
|
|
95
|
+
export const fill = (s, v) => s.replace(/\{(\w+)\}/g, (_, k) => String(v[k] ?? ''));
|
package/guide.json
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema": "shotik.guide/1",
|
|
3
|
+
"sdk": "@shotik/react-native",
|
|
4
|
+
"variables": [
|
|
5
|
+
"APP_KEY",
|
|
6
|
+
"SERVER_URL"
|
|
7
|
+
],
|
|
8
|
+
"steps": [
|
|
9
|
+
{
|
|
10
|
+
"id": "install",
|
|
11
|
+
"title": "Add the SDK",
|
|
12
|
+
"body": "From npm. No native code: works in your current dev client, no rebuild.",
|
|
13
|
+
"code": {
|
|
14
|
+
"lang": "sh",
|
|
15
|
+
"file": "terminal",
|
|
16
|
+
"snippet": "npx expo install @shotik/react-native # or: npm install @shotik/react-native"
|
|
17
|
+
},
|
|
18
|
+
"check": {
|
|
19
|
+
"kind": "dependency",
|
|
20
|
+
"value": "@shotik/react-native"
|
|
21
|
+
},
|
|
22
|
+
"title_ru": "Добавьте SDK",
|
|
23
|
+
"body_ru": "Из npm. Без нативного кода: работает в текущем dev client, пересборка не нужна."
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"id": "provider",
|
|
27
|
+
"title": "Wrap your root",
|
|
28
|
+
"body": "Inside your outermost provider. It renders the chat sheet.",
|
|
29
|
+
"code": {
|
|
30
|
+
"lang": "tsx",
|
|
31
|
+
"file": "app/_layout.tsx",
|
|
32
|
+
"snippet": "import { ShotikSupportProvider } from '@shotik/react-native'\n\n<ShotikSupportProvider appKey=\"{{APP_KEY}}\" serverUrl=\"{{SERVER_URL}}\">\n <Stack />\n</ShotikSupportProvider>"
|
|
33
|
+
},
|
|
34
|
+
"check": {
|
|
35
|
+
"kind": "file-contains",
|
|
36
|
+
"value": "ShotikSupportProvider"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"id": "brand",
|
|
41
|
+
"title": "Match your brand",
|
|
42
|
+
"body": "Accent, radius and font. Light, dark and Russian come built in.",
|
|
43
|
+
"code": {
|
|
44
|
+
"lang": "tsx",
|
|
45
|
+
"file": "app/_layout.tsx",
|
|
46
|
+
"snippet": "<ShotikSupportProvider\n appKey=\"{{APP_KEY}}\"\n serverUrl=\"{{SERVER_URL}}\"\n launcher\n theme={{ accent: '#FF5A1F', radius: 18 }}\n quickReplies={['Billing', 'Report a bug']}\n>"
|
|
47
|
+
},
|
|
48
|
+
"check": {
|
|
49
|
+
"kind": "file-contains",
|
|
50
|
+
"value": "theme={{"
|
|
51
|
+
},
|
|
52
|
+
"optional": true
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"id": "attachments",
|
|
56
|
+
"title": "Photos and screenshots",
|
|
57
|
+
"body": "Shows the attach button when one is installed. Needs a dev client rebuild.",
|
|
58
|
+
"code": {
|
|
59
|
+
"lang": "sh",
|
|
60
|
+
"file": "terminal",
|
|
61
|
+
"snippet": "npx expo install expo-image-picker react-native-view-shot"
|
|
62
|
+
},
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"id": "help",
|
|
67
|
+
"title": "Open from Help",
|
|
68
|
+
"body": "Point your Help or Contact row at the chat.",
|
|
69
|
+
"code": {
|
|
70
|
+
"lang": "tsx",
|
|
71
|
+
"file": "settings screen",
|
|
72
|
+
"snippet": "import { ShotikSupport } from '@shotik/react-native'\n\n<Row label=\"Help\" onPress={() => ShotikSupport.open()} />"
|
|
73
|
+
},
|
|
74
|
+
"check": {
|
|
75
|
+
"kind": "file-contains",
|
|
76
|
+
"value": "ShotikSupport.open("
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"id": "route",
|
|
81
|
+
"title": "Deep link",
|
|
82
|
+
"body": "myapp://support opens the chat (push taps too).",
|
|
83
|
+
"code": {
|
|
84
|
+
"lang": "tsx",
|
|
85
|
+
"file": "app/support.tsx",
|
|
86
|
+
"snippet": "export { SupportRoute as default } from '@shotik/react-native'"
|
|
87
|
+
},
|
|
88
|
+
"check": {
|
|
89
|
+
"kind": "file-exists",
|
|
90
|
+
"value": "app/support.tsx"
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"id": "identify",
|
|
95
|
+
"title": "Identify after sign-in",
|
|
96
|
+
"body": "Anonymous chats move to the user.",
|
|
97
|
+
"code": {
|
|
98
|
+
"lang": "ts",
|
|
99
|
+
"file": "auth listener",
|
|
100
|
+
"snippet": "ShotikSupport.identify({ userId: user.id, email: user.email, name: user.name })\n// on sign-out\nShotikSupport.reset()"
|
|
101
|
+
},
|
|
102
|
+
"check": {
|
|
103
|
+
"kind": "file-contains",
|
|
104
|
+
"value": "ShotikSupport.identify("
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"id": "push",
|
|
109
|
+
"title": "Forward the push token",
|
|
110
|
+
"body": "Replies reach users who closed the app.",
|
|
111
|
+
"code": {
|
|
112
|
+
"lang": "ts",
|
|
113
|
+
"file": "notifications",
|
|
114
|
+
"snippet": "const { data: token } = await Notifications.getExpoPushTokenAsync({ projectId })\nShotikSupport.setPushToken(token, Platform.OS)"
|
|
115
|
+
},
|
|
116
|
+
"check": {
|
|
117
|
+
"kind": "push-token",
|
|
118
|
+
"value": "any user of this app"
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"id": "test",
|
|
123
|
+
"title": "Send a test message",
|
|
124
|
+
"body": "Open Help in the app and say hi.",
|
|
125
|
+
"code": {
|
|
126
|
+
"lang": "sh",
|
|
127
|
+
"file": "terminal",
|
|
128
|
+
"snippet": "xcrun simctl openurl booted \"myapp://support\""
|
|
129
|
+
},
|
|
130
|
+
"check": {
|
|
131
|
+
"kind": "first-message",
|
|
132
|
+
"value": "a conversation from this app"
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
}
|