@shotik/react-native 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/LICENSE +26 -0
- package/README.md +39 -3
- package/README.ru.md +40 -3
- package/dist/analytics/core.d.ts +96 -11
- package/dist/analytics/core.js +295 -22
- package/dist/analytics/privacy.d.ts +4 -0
- package/dist/analytics/privacy.js +46 -0
- package/dist/analytics/replay.d.ts +41 -0
- package/dist/analytics/replay.js +192 -0
- package/dist/analytics/rn.d.ts +52 -2
- package/dist/analytics/rn.js +669 -62
- package/dist/analytics/wire.d.ts +54 -2
- package/dist/analytics/wire.js +44 -4
- package/dist/client.d.ts +94 -1
- package/dist/client.js +254 -17
- package/dist/flow.d.ts +48 -0
- package/dist/flow.js +56 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/parts.d.ts +42 -1
- package/dist/parts.js +72 -14
- package/dist/react.d.ts +24 -3
- package/dist/react.js +42 -15
- package/dist/sheet.d.ts +2 -1
- package/dist/sheet.js +207 -16
- package/dist/support.js +2 -2
- package/dist/theme.d.ts +43 -0
- package/dist/theme.js +90 -4
- package/package.json +15 -2
- package/recipe.json +1 -1
- package/src/analytics/README.md +10 -6
- package/src/analytics/core.ts +314 -25
- package/src/analytics/privacy.ts +50 -0
- package/src/analytics/recipe.json +1 -1
- package/src/analytics/replay.ts +190 -0
- package/src/analytics/rn.tsx +620 -63
- package/src/analytics/wire.ts +99 -8
- package/src/client.ts +344 -19
- package/src/flow.ts +100 -0
- package/src/index.ts +4 -4
- package/src/parts.tsx +102 -14
- package/src/react.tsx +57 -16
- package/src/sheet.tsx +423 -20
- package/src/support.ts +2 -2
- package/src/theme.ts +90 -4
package/src/parts.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Small building blocks:
|
|
1
|
+
// Small building blocks: Pikaicons glyphs (drawn with react-native-svg when the app has it, else plain View stand-ins),
|
|
2
2
|
// the typing dots, the floating launcher, motion tokens and the optional photo / screenshot / svg peers.
|
|
3
3
|
|
|
4
4
|
import { useEffect, useRef, useState } from 'react'
|
|
@@ -15,7 +15,8 @@ export const motion = {
|
|
|
15
15
|
sheet: { damping: 30, stiffness: 320, mass: 1 },
|
|
16
16
|
bubble: { duration: 170, easing: Easing.bezier(0.25, 0.1, 0.25, 1) },
|
|
17
17
|
chips: { duration: 200, stagger: 40 },
|
|
18
|
-
dots: { period: 900, gap: 150 }
|
|
18
|
+
dots: { period: 900, gap: 150 },
|
|
19
|
+
reveal: { duration: 200, y: 6 }
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export function useReduceMotion(): boolean {
|
|
@@ -36,15 +37,21 @@ export function T({ c, bold, style, ...p }: { c: Resolved; bold?: boolean; style
|
|
|
36
37
|
|
|
37
38
|
const flip = I18nManager.isRTL ? [{ scaleX: -1 }] : []
|
|
38
39
|
|
|
39
|
-
//
|
|
40
|
+
// Pikaicons free pack (@pikaicons/core-free 0.1.0, MIT, stroke style), 24x24 paths; names in REFS.md, notice in LICENSE.
|
|
40
41
|
const icons = {
|
|
41
|
-
back: ['M15
|
|
42
|
-
close: ['
|
|
43
|
-
send: ['
|
|
44
|
-
attach: ['M12
|
|
45
|
-
clock: ['
|
|
46
|
-
ai: ['
|
|
47
|
-
|
|
42
|
+
back: ['M15 18a30.6 30.6 0 0 1-5.817-5.49.8.8 0 0 1 0-1.02A30.6 30.6 0 0 1 15 6'],
|
|
43
|
+
close: ['m6 18 6-6m0 0 6-6m-6 6L6 6m6 6 6 6'],
|
|
44
|
+
send: ['M6 9.83a30.2 30.2 0 0 1 5.406-5.62A.95.95 0 0 1 12 4m6 5.83a30.2 30.2 0 0 0-5.406-5.62A.95.95 0 0 0 12 4m0 0v16'],
|
|
45
|
+
attach: ['M12 19v-7m0 0V5m0 7H5m7 0h7'],
|
|
46
|
+
clock: ['M12 8v4.816a.5.5 0 0 0 .231.422L15 15m6.15-3a9.15 9.15 0 1 1-18.3 0 9.15 9.15 0 0 1 18.3 0Z'],
|
|
47
|
+
ai: ['M5 17.65V19m0 0v1.35M5 19h1.35M5 19H3.65M12.9 3c.64 5.037 2.63 8.142 8.1 9-5.19.814-7.43 3.728-8.1 9-.67-5.272-2.91-8.186-8.1-9 5.19-.814 7.43-3.728 8.1-9ZM5.7 3c.248 1.506 1.151 2.445 2.7 2.7-1.549.255-2.452 1.194-2.7 2.7C5.452 6.894 4.548 5.955 3 5.7 4.506 5.452 5.445 4.548 5.7 3Z'],
|
|
48
|
+
forward: ['M9 18a30.6 30.6 0 0 0 5.817-5.49.8.8 0 0 0 0-1.02A30.6 30.6 0 0 0 9 6'],
|
|
49
|
+
tick: ['m8.5 12.513 2.341 2.338A15 15 0 0 1 15.4 9.915l.101-.069M21.15 12a9.15 9.15 0 1 1-18.3 0 9.15 9.15 0 0 1 18.3 0Z'],
|
|
50
|
+
trash: ['m16 6-1.106-2.211a3.236 3.236 0 0 0-5.788 0L8 6M4 6h16M6 6h12v9c0 1.864 0 2.796-.305 3.53a4 4 0 0 1-2.164 2.165C14.796 21 13.864 21 12 21s-2.796 0-3.53-.305a4 4 0 0 1-2.166-2.164C6 17.796 6 16.864 6 15z'],
|
|
51
|
+
alert: ['M12 12.624v-4M12 16zm9-4a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z'],
|
|
52
|
+
thumbUp: ['m15.162 7.17.047-.123a7 7 0 0 0 .157-.426 3 3 0 0 0-.602-2.846 7 7 0 0 0-.315-.325 3 3 0 0 0-.184-.176 1 1 0 0 0-1.382.123c-.035.04-.073.095-.15.205L9.721 7.928c-.64.919-.959 1.378-1.185 1.878-.202.443-.348.91-.436 1.389-.1.54-.1 1.1-.1 2.218v1.788c0 1.68 0 2.52.327 3.162a3 3 0 0 0 1.311 1.31c.642.328 1.482.328 3.162.328h3.509c1.467 0 2.2 0 2.792-.27a3 3 0 0 0 1.276-1.098c.354-.546.462-1.271.68-2.722l.53-3.555c.143-.95.214-1.425.072-1.794a1.5 1.5 0 0 0-.66-.766c-.344-.195-.825-.195-1.785-.195h-2.386c-.372 0-.557 0-.694-.026a1.5 1.5 0 0 1-1.199-1.748c.026-.137.093-.31.226-.657Z', 'M3 11.5a2.5 2.5 0 0 1 5 0v6a2.5 2.5 0 1 1-5 0z'],
|
|
53
|
+
thumbDown: ['M16 11.064V12.5a2.5 2.5 0 0 0 5 0v-6a2.5 2.5 0 0 0-5 0v1.768m0 2.796c-.002.813-.015 1.285-.1 1.742a6 6 0 0 1-.436 1.389c-.226.5-.546.959-1.185 1.878l-3.012 4.326c-.077.11-.115.164-.15.205a1 1 0 0 1-1.382.123 3 3 0 0 1-.184-.176c-.164-.164-.245-.245-.315-.326a3 3 0 0 1-.602-2.845c.032-.102.073-.21.157-.426l.048-.124c.133-.346.2-.52.226-.656a1.5 1.5 0 0 0-1.199-1.748c-.137-.026-.322-.026-.694-.026H4.786c-.96 0-1.44 0-1.785-.195a1.5 1.5 0 0 1-.66-.766c-.142-.37-.07-.844.071-1.794l.532-3.555c.217-1.451.325-2.177.679-2.722A3 3 0 0 1 4.899 4.27C5.49 4 6.224 4 7.69 4h3.51c1.68 0 2.52 0 3.162.327a3 3 0 0 1 1.311 1.311c.29.57.323 1.297.327 2.63m0 2.796V8.268'],
|
|
54
|
+
chat: ['M8 10h8m-8 4h4m9-2a9 9 0 0 1-10.272 8.91c-1.203-.17-1.805-.255-1.964-.267-.257-.02-.165-.016-.423-.014-.159 0-.34.014-.702.04l-2.153.153c-.857.062-1.286.092-1.607-.06a1.35 1.35 0 0 1-.641-.641c-.152-.32-.122-.75-.06-1.607l.153-2.153c.026-.362.04-.543.04-.702.002-.258.006-.166-.014-.423-.012-.159-.098-.76-.268-1.964A9 9 0 1 1 21 12Z'],
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
// Stroke scaled so every glyph renders about 1.7 pt wide whatever its size.
|
|
@@ -95,15 +102,87 @@ export function ArrowUp({ color }: { color: string }) {
|
|
|
95
102
|
)
|
|
96
103
|
}
|
|
97
104
|
|
|
98
|
-
export function Clock({ color }: { color: string }) {
|
|
99
|
-
return hi('clock', color,
|
|
105
|
+
export function Clock({ color, size = 12 }: { color: string; size?: number }) {
|
|
106
|
+
return hi('clock', color, size) ?? (
|
|
100
107
|
<View style={[g.clock, { borderColor: color }]}>
|
|
101
108
|
<View style={[g.hand, { backgroundColor: color }]} />
|
|
102
109
|
</View>
|
|
103
110
|
)
|
|
104
111
|
}
|
|
105
112
|
|
|
106
|
-
|
|
113
|
+
export function Forward({ color }: { color: string }) {
|
|
114
|
+
return hi('forward', color, 18, { transform: flip }) ?? (
|
|
115
|
+
<View style={[g.box, { transform: [{ scaleX: -1 }, ...flip] }]}>
|
|
116
|
+
<View style={[g.chev, { borderColor: color, width: 7, height: 7 }]} />
|
|
117
|
+
</View>
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function Tick({ color, size = 14 }: { color: string; size?: number }) {
|
|
122
|
+
return hi('tick', color, size) ?? <View style={[g.tick, { borderColor: color }]} />
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function Alert({ color, size = 14 }: { color: string; size?: number }) {
|
|
126
|
+
return hi('alert', color, size) ?? (
|
|
127
|
+
<View style={[g.clock, { borderColor: color, width: size - 2, height: size - 2, borderRadius: size / 2 }]}>
|
|
128
|
+
<View style={[g.hand, { backgroundColor: color }]} />
|
|
129
|
+
</View>
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function Trash({ color, size = 24 }: { color: string; size?: number }) {
|
|
134
|
+
return hi('trash', color, size) ?? <View style={[g.trash, { borderColor: color }]} />
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Without react-native-svg the Yes / No label carries the meaning on its own.
|
|
138
|
+
export function Thumb({ up, color }: { up: boolean; color: string }) {
|
|
139
|
+
return hi(up ? 'thumbUp' : 'thumbDown', color, 16)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Pending action: a short bar sliding in a track (dee68144 "loads then lands on a check"), native driver; Reduce Motion: static.
|
|
143
|
+
export function LoadingBar({ color, reduce }: { color: string; reduce: boolean }) {
|
|
144
|
+
const v = useRef(new Animated.Value(0)).current
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
if (reduce) return
|
|
147
|
+
const loop = Animated.loop(Animated.timing(v, { toValue: 1, duration: motion.dots.period, easing: Easing.inOut(Easing.ease), useNativeDriver: true }))
|
|
148
|
+
loop.start()
|
|
149
|
+
return () => loop.stop()
|
|
150
|
+
}, [reduce, v])
|
|
151
|
+
const translateX = v.interpolate({ inputRange: [0, 0.5, 1], outputRange: [0, 10, 0] })
|
|
152
|
+
return (
|
|
153
|
+
<View style={[g.track, { backgroundColor: color + '33' }]}>
|
|
154
|
+
<Animated.View style={[g.bar6, { backgroundColor: color, opacity: reduce ? 0.6 : 1, transform: [{ translateX: reduce ? 5 : translateX }] }]} />
|
|
155
|
+
</View>
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Fade + y 6 -> 0 for things that appear in place (consent line, rating, chip); Reduce Motion: fade only.
|
|
160
|
+
export function Reveal({ reduce, style, children }: { reduce: boolean; style?: StyleProp<ViewStyle>; children?: ReactNode }) {
|
|
161
|
+
const v = useRef(new Animated.Value(0)).current
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
Animated.timing(v, { toValue: 1, duration: motion.reveal.duration, easing: motion.bubble.easing, useNativeDriver: true }).start()
|
|
164
|
+
}, [v])
|
|
165
|
+
const y = reduce ? 0 : v.interpolate({ inputRange: [0, 1], outputRange: [motion.reveal.y, 0] })
|
|
166
|
+
return <Animated.View style={[style, { opacity: v, transform: [{ translateY: y }] }]}>{children}</Animated.View>
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Non-modal help chip after friction (77f37af3 feedback pill + d2671762 toast close): text opens support, x is "Not now".
|
|
170
|
+
export function FrictionChip({ c, t, reduce, onOpen, onClose, style }: { c: Resolved; t: Copy; reduce: boolean; onOpen: () => void; onClose: () => void; style?: StyleProp<ViewStyle> }) {
|
|
171
|
+
return (
|
|
172
|
+
<View pointerEvents="box-none" style={[g.chipWrap, style]}>
|
|
173
|
+
<Reveal reduce={reduce} style={[g.chip, { backgroundColor: c.bg, borderColor: c.line }]}>
|
|
174
|
+
<Pressable onPress={onOpen} accessibilityRole="button" accessibilityLabel={t.friction} style={g.chipText}>
|
|
175
|
+
<T c={c} style={g.chipLabel} numberOfLines={1}>{t.friction}</T>
|
|
176
|
+
</Pressable>
|
|
177
|
+
<Pressable onPress={onClose} hitSlop={6} accessibilityRole="button" accessibilityLabel={t.frictionClose} style={[g.chipX, { backgroundColor: c.raised }]}>
|
|
178
|
+
<Cross color={c.sub} size={9} />
|
|
179
|
+
</Pressable>
|
|
180
|
+
</Reveal>
|
|
181
|
+
</View>
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// AI mark: Pikaicons sparkle-ai-01 (a small accent diamond without react-native-svg).
|
|
107
186
|
export function Spark({ color, size = 7 }: { color: string; size?: number }) {
|
|
108
187
|
return hi('ai', color, Math.round(size * 1.7)) ?? <View style={{ width: size, height: size, borderRadius: 1.5, backgroundColor: color, transform: [{ rotate: '45deg' }] }} />
|
|
109
188
|
}
|
|
@@ -239,5 +318,14 @@ const g = StyleSheet.create({
|
|
|
239
318
|
gdot: { width: 3.5, height: 3.5, borderRadius: 2 },
|
|
240
319
|
tail: { width: 0, height: 0, borderStartWidth: 5, borderEndWidth: 0, borderTopWidth: 5, borderStartColor: 'transparent', borderEndColor: 'transparent', marginStart: -10, marginTop: -1 },
|
|
241
320
|
badge: { position: 'absolute', top: -4, end: -4, minWidth: 22, height: 22, borderRadius: 11, borderWidth: 2, paddingHorizontal: 5, alignItems: 'center', justifyContent: 'center' },
|
|
242
|
-
badgeText: { color: '#FFFFFF', fontSize: 12, fontWeight: '600', fontVariant: ['tabular-nums'] }
|
|
321
|
+
badgeText: { color: '#FFFFFF', fontSize: 12, fontWeight: '600', fontVariant: ['tabular-nums'] },
|
|
322
|
+
tick: { width: 10, height: 6, borderStartWidth: 1.7, borderBottomWidth: 1.7, transform: [{ rotate: '-45deg' }], marginTop: -2 },
|
|
323
|
+
track: { width: 16, height: 3, borderRadius: 1.5, overflow: 'hidden' },
|
|
324
|
+
trash: { width: 14, height: 16, borderWidth: 1.7, borderTopWidth: 3, borderRadius: 2 },
|
|
325
|
+
bar6: { width: 6, height: 3, borderRadius: 1.5 },
|
|
326
|
+
chipWrap: { position: 'absolute', start: 16, end: 16, bottom: Platform.OS === 'ios' ? 40 : 24, alignItems: 'center' },
|
|
327
|
+
chip: { flexDirection: 'row', alignItems: 'center', gap: 4, minHeight: 44, maxWidth: '100%', borderRadius: 22, borderWidth: StyleSheet.hairlineWidth, paddingStart: 14, paddingEnd: 6, shadowColor: '#000', shadowOpacity: 0.12, shadowRadius: 16, shadowOffset: { width: 0, height: 6 }, elevation: 4 },
|
|
328
|
+
chipText: { flexShrink: 1, justifyContent: 'center', minHeight: 44 },
|
|
329
|
+
chipLabel: { fontSize: 15, lineHeight: 20, flexShrink: 1 },
|
|
330
|
+
chipX: { width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center', marginStart: 4 }
|
|
243
331
|
})
|
package/src/react.tsx
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
// React bindings: <ShotikSupportProvider> (state, AppState catch-up, the widget), useSupport()
|
|
2
|
-
//
|
|
1
|
+
// React bindings: <ShotikSupportProvider> (state, AppState catch-up, the widget), useSupport(), <SupportWidget/> (an
|
|
2
|
+
// optional floating launcher with an unread badge, the friction chip, and the chat sheet, mounted on first open only)
|
|
3
|
+
// and <SupportFrictionChip/> for hosts that place the chip themselves.
|
|
3
4
|
|
|
4
5
|
import { createContext, useContext, useEffect, useMemo, useState, useSyncExternalStore } from 'react'
|
|
5
6
|
import type { ReactNode } from 'react'
|
|
6
|
-
import { AppState, useColorScheme } from 'react-native'
|
|
7
|
+
import { AppState, Platform, StyleSheet, useColorScheme } from 'react-native'
|
|
7
8
|
import type { StyleProp, ViewStyle } from 'react-native'
|
|
8
9
|
import { SupportClient } from './client'
|
|
9
|
-
import type { LocalAttachment, SupportState, UserInfo } from './client'
|
|
10
|
+
import type { ActionKind, ActionResult, CancelReason, LocalAttachment, SupportAction, SupportEventKind, SupportState, UserInfo } from './client'
|
|
10
11
|
import { nativeDevice } from './native'
|
|
11
|
-
import { Launcher } from './parts'
|
|
12
|
+
import { FrictionChip, Launcher, useReduceMotion } from './parts'
|
|
12
13
|
import { Sheet } from './sheet'
|
|
13
14
|
import { ShotikSupport } from './support'
|
|
14
15
|
import { copyFor, resolveTheme } from './theme'
|
|
@@ -32,6 +33,10 @@ export interface WidgetProps {
|
|
|
32
33
|
locale?: string
|
|
33
34
|
// Deprecated: use theme.accent.
|
|
34
35
|
accentColor?: string
|
|
36
|
+
// Your app's name for the "Rate {app}" row (default "Rate the app").
|
|
37
|
+
appName?: string
|
|
38
|
+
// Show the "Something wrong? Write to us" chip after friction (default true; false when you place <SupportFrictionChip/>).
|
|
39
|
+
frictionChip?: boolean
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
export interface ProviderProps extends WidgetProps {
|
|
@@ -65,7 +70,7 @@ export function ShotikSupportProvider({ appKey, serverUrl, children, widget = tr
|
|
|
65
70
|
)
|
|
66
71
|
}
|
|
67
72
|
|
|
68
|
-
const idle: SupportState = { status: 'idle', userId: null, conversations: [], messages: {}, unread: 0, unreadBy: {}, open: false, activeConversationId: null, error: null, typing: {} }
|
|
73
|
+
const idle: SupportState = { status: 'idle', userId: null, conversations: [], messages: {}, unread: 0, unreadBy: {}, open: false, activeConversationId: null, error: null, typing: {}, aiConsent: null, subscription: null, widget: null, friction: null }
|
|
69
74
|
const noop = () => () => {}
|
|
70
75
|
|
|
71
76
|
export function useSupport() {
|
|
@@ -83,7 +88,18 @@ export function useSupport() {
|
|
|
83
88
|
open: (conversationId?: string | null) => client?.open(conversationId),
|
|
84
89
|
close: () => client?.close(),
|
|
85
90
|
select: (conversationId: string | null) => client?.select(conversationId),
|
|
86
|
-
identify: (user?: UserInfo) => client?.identify(user) ?? Promise.resolve()
|
|
91
|
+
identify: (user?: UserInfo) => client?.identify(user) ?? Promise.resolve(),
|
|
92
|
+
setAiConsent: (allowed: boolean) => client?.setAiConsent(allowed).catch(() => {}),
|
|
93
|
+
runAction: (action: SupportAction, conversationId?: string | null): Promise<ActionResult> => client?.runAction(action, conversationId) ?? Promise.resolve('failed'),
|
|
94
|
+
// Whether an action can do anything here: the host's onAction, or a store URL fallback it can open.
|
|
95
|
+
canRun: (kind: ActionKind, value?: string) => !!client && (!!client.config.onAction || (!!client.config.openUrl && !!client.fallbackUrl({ kind, value }))),
|
|
96
|
+
track: (kind: SupportEventKind, data?: Record<string, string | number | boolean>, conversationId?: string | null) => client?.track(kind, data, conversationId),
|
|
97
|
+
rate: (conversationId: string, score: 1 | -1, comment?: string) => client?.rate(conversationId, score, comment).catch(() => {}),
|
|
98
|
+
askForOffer: (reason: CancelReason) => client?.askForOffer(reason),
|
|
99
|
+
// Delete my data (§3.13): 'done' once the server erased it, 'pending' while the request waits for the network.
|
|
100
|
+
deleteMyData: (): Promise<'done' | 'pending'> => client?.deleteMyData() ?? Promise.resolve('done'),
|
|
101
|
+
openFriction: () => client?.openFriction(),
|
|
102
|
+
dismissFriction: () => client?.dismissFriction()
|
|
87
103
|
}),
|
|
88
104
|
[state, client]
|
|
89
105
|
)
|
|
@@ -98,13 +114,33 @@ export interface SheetViewProps extends Omit<WidgetProps, 'launcher' | 'launcher
|
|
|
98
114
|
presentation?: 'modal' | 'inline'
|
|
99
115
|
}
|
|
100
116
|
|
|
101
|
-
|
|
102
|
-
const live = useSupport()
|
|
103
|
-
const s = api ?? live
|
|
117
|
+
function useLook(theme?: SupportTheme, accentColor?: string, locale?: string) {
|
|
104
118
|
const system = useColorScheme() === 'dark' ? 'dark' : 'light'
|
|
105
119
|
const c = useMemo(() => resolveTheme(accentColor && !theme?.accent ? { ...theme, accent: accentColor } : theme, system), [theme, accentColor, system])
|
|
106
120
|
const t = useMemo(() => copyFor(locale ?? nativeDevice().locale), [locale])
|
|
107
|
-
return
|
|
121
|
+
return { c, t }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function SupportSheet({ api, presentation = 'inline', title, teamName, theme, quickReplies = [], locale, accentColor, appName }: SheetViewProps) {
|
|
125
|
+
const live = useSupport()
|
|
126
|
+
const s = api ?? live
|
|
127
|
+
const { c, t } = useLook(theme, accentColor, locale)
|
|
128
|
+
return <Sheet s={s} c={c} t={t} title={title ?? t.title} team={teamName ?? t.team} quickReplies={quickReplies} presentation={presentation} appName={appName} />
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// The friction chip on its own, for hosts that place it (pass style to position it). Shows while state.friction is set.
|
|
132
|
+
export interface FrictionChipProps {
|
|
133
|
+
theme?: SupportTheme
|
|
134
|
+
locale?: string
|
|
135
|
+
style?: StyleProp<ViewStyle>
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function SupportFrictionChip({ theme, locale, style }: FrictionChipProps) {
|
|
139
|
+
const s = useSupport()
|
|
140
|
+
const { c, t } = useLook(theme, undefined, locale)
|
|
141
|
+
const reduce = useReduceMotion()
|
|
142
|
+
if (!s.friction || s.visible) return null
|
|
143
|
+
return <FrictionChip c={c} t={t} reduce={reduce} onOpen={s.openFriction} onClose={s.dismissFriction} style={style} />
|
|
108
144
|
}
|
|
109
145
|
|
|
110
146
|
// A route that opens the widget and steps back, so <scheme>://support deep links and push taps land in support.
|
|
@@ -122,19 +158,24 @@ export function SupportRoute() {
|
|
|
122
158
|
}
|
|
123
159
|
|
|
124
160
|
// Nothing but the (optional) launcher renders until the first open; the sheet stays mounted afterwards.
|
|
125
|
-
export function SupportWidget({ title, teamName, theme, launcher = false, launcherStyle, quickReplies = [], locale, accentColor }: WidgetProps) {
|
|
161
|
+
export function SupportWidget({ title, teamName, theme, launcher = false, launcherStyle, quickReplies = [], locale, accentColor, appName, frictionChip = true }: WidgetProps) {
|
|
126
162
|
const s = useSupport()
|
|
127
|
-
const
|
|
128
|
-
const
|
|
129
|
-
const t = useMemo(() => copyFor(locale ?? nativeDevice().locale), [locale])
|
|
163
|
+
const { c, t } = useLook(theme, accentColor, locale)
|
|
164
|
+
const reduce = useReduceMotion()
|
|
130
165
|
const [mounted, setMounted] = useState(s.visible)
|
|
131
166
|
useEffect(() => {
|
|
132
167
|
if (s.visible) setMounted(true)
|
|
133
168
|
}, [s.visible])
|
|
134
169
|
return (
|
|
135
170
|
<>
|
|
171
|
+
{frictionChip && s.friction && !s.visible ? <FrictionChip c={c} t={t} reduce={reduce} onOpen={s.openFriction} onClose={s.dismissFriction} style={launcher ? st.aboveLauncher : undefined} /> : null}
|
|
136
172
|
{launcher && !s.visible ? <Launcher c={c} t={t} unread={s.unread} onPress={() => s.open()} style={launcherStyle} /> : null}
|
|
137
|
-
{mounted ? <Sheet s={s} c={c} t={t} title={title ?? t.title} team={teamName ?? t.team} quickReplies={quickReplies} /> : null}
|
|
173
|
+
{mounted ? <Sheet s={s} c={c} t={t} title={title ?? t.title} team={teamName ?? t.team} quickReplies={quickReplies} appName={appName} /> : null}
|
|
138
174
|
</>
|
|
139
175
|
)
|
|
140
176
|
}
|
|
177
|
+
|
|
178
|
+
const st = StyleSheet.create({
|
|
179
|
+
// The chip sits above the 56 pt launcher with a 16 pt gap.
|
|
180
|
+
aboveLauncher: { bottom: (Platform.OS === 'ios' ? 40 : 24) + 56 + 16, end: 20, start: 20, alignItems: 'flex-end' }
|
|
181
|
+
})
|