@cobbai/react-native-sdk 1.0.0-beta.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/CobbaiMobileRnSdk.podspec +22 -0
- package/LICENSE +32 -0
- package/README.md +386 -0
- package/dist/ChatPlaceholder.d.ts +13 -0
- package/dist/ChatPlaceholder.d.ts.map +1 -0
- package/dist/ChatPlaceholder.js +87 -0
- package/dist/CobbaiChatScreen.d.ts +4 -0
- package/dist/CobbaiChatScreen.d.ts.map +1 -0
- package/dist/CobbaiChatScreen.js +196 -0
- package/dist/CobbaiInAppBanner.d.ts +15 -0
- package/dist/CobbaiInAppBanner.d.ts.map +1 -0
- package/dist/CobbaiInAppBanner.js +159 -0
- package/dist/CobbaiLauncher.d.ts +19 -0
- package/dist/CobbaiLauncher.d.ts.map +1 -0
- package/dist/CobbaiLauncher.js +149 -0
- package/dist/CobbaiWebView.d.ts +28 -0
- package/dist/CobbaiWebView.d.ts.map +1 -0
- package/dist/CobbaiWebView.js +141 -0
- package/dist/adapters/expoAdapter.d.ts +85 -0
- package/dist/adapters/expoAdapter.d.ts.map +1 -0
- package/dist/adapters/expoAdapter.js +152 -0
- package/dist/adapters/firebaseAdapter.d.ts +41 -0
- package/dist/adapters/firebaseAdapter.d.ts.map +1 -0
- package/dist/adapters/firebaseAdapter.js +139 -0
- package/dist/adapters/iosRelayAdapter.d.ts +26 -0
- package/dist/adapters/iosRelayAdapter.d.ts.map +1 -0
- package/dist/adapters/iosRelayAdapter.js +101 -0
- package/dist/androidKeyboardFrame.d.ts +16 -0
- package/dist/androidKeyboardFrame.d.ts.map +1 -0
- package/dist/androidKeyboardFrame.js +34 -0
- package/dist/bridge/messages.d.ts +20 -0
- package/dist/bridge/messages.d.ts.map +1 -0
- package/dist/bridge/messages.js +20 -0
- package/dist/bridge/nativeEvent.d.ts +10 -0
- package/dist/bridge/nativeEvent.d.ts.map +1 -0
- package/dist/bridge/nativeEvent.js +15 -0
- package/dist/bridge/parser.d.ts +29 -0
- package/dist/bridge/parser.d.ts.map +1 -0
- package/dist/bridge/parser.js +109 -0
- package/dist/chatPresentation.d.ts +19 -0
- package/dist/chatPresentation.d.ts.map +1 -0
- package/dist/chatPresentation.js +51 -0
- package/dist/chatScreen/useInAppBannerQueue.d.ts +22 -0
- package/dist/chatScreen/useInAppBannerQueue.d.ts.map +1 -0
- package/dist/chatScreen/useInAppBannerQueue.js +60 -0
- package/dist/chatScreen/useKeyboardFrame.d.ts +14 -0
- package/dist/chatScreen/useKeyboardFrame.d.ts.map +1 -0
- package/dist/chatScreen/useKeyboardFrame.js +63 -0
- package/dist/chatScreen/useLauncherPresentation.d.ts +20 -0
- package/dist/chatScreen/useLauncherPresentation.d.ts.map +1 -0
- package/dist/chatScreen/useLauncherPresentation.js +76 -0
- package/dist/chatScreen/useNativeToWebSync.d.ts +17 -0
- package/dist/chatScreen/useNativeToWebSync.d.ts.map +1 -0
- package/dist/chatScreen/useNativeToWebSync.js +36 -0
- package/dist/chatScreen/usePushIntegration.d.ts +19 -0
- package/dist/chatScreen/usePushIntegration.d.ts.map +1 -0
- package/dist/chatScreen/usePushIntegration.js +129 -0
- package/dist/chatScreen/useReadyLifecycle.d.ts +33 -0
- package/dist/chatScreen/useReadyLifecycle.d.ts.map +1 -0
- package/dist/chatScreen/useReadyLifecycle.js +138 -0
- package/dist/chatScreen/useSheetPresentation.d.ts +25 -0
- package/dist/chatScreen/useSheetPresentation.d.ts.map +1 -0
- package/dist/chatScreen/useSheetPresentation.js +98 -0
- package/dist/chatUnavailable.d.ts +23 -0
- package/dist/chatUnavailable.d.ts.map +1 -0
- package/dist/chatUnavailable.js +36 -0
- package/dist/externalLinks.d.ts +4 -0
- package/dist/externalLinks.d.ts.map +1 -0
- package/dist/externalLinks.js +48 -0
- package/dist/host/buildHostHtml.d.ts +7 -0
- package/dist/host/buildHostHtml.d.ts.map +1 -0
- package/dist/host/buildHostHtml.js +101 -0
- package/dist/host/hostPageKey.d.ts +7 -0
- package/dist/host/hostPageKey.d.ts.map +1 -0
- package/dist/host/hostPageKey.js +18 -0
- package/dist/inAppBanner.d.ts +19 -0
- package/dist/inAppBanner.d.ts.map +1 -0
- package/dist/inAppBanner.js +42 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/launcher.d.ts +25 -0
- package/dist/launcher.d.ts.map +1 -0
- package/dist/launcher.js +55 -0
- package/dist/launcherGlyph.d.ts +2 -0
- package/dist/launcherGlyph.d.ts.map +1 -0
- package/dist/launcherGlyph.js +5 -0
- package/dist/openChatScreen.d.ts +13 -0
- package/dist/openChatScreen.d.ts.map +1 -0
- package/dist/openChatScreen.js +63 -0
- package/dist/push.d.ts +59 -0
- package/dist/push.d.ts.map +1 -0
- package/dist/push.js +309 -0
- package/dist/pushIntegration.d.ts +76 -0
- package/dist/pushIntegration.d.ts.map +1 -0
- package/dist/pushIntegration.js +244 -0
- package/dist/pushLogout.d.ts +57 -0
- package/dist/pushLogout.d.ts.map +1 -0
- package/dist/pushLogout.js +225 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/version.d.ts +8 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +10 -0
- package/ios/CobbaiPush.m +96 -0
- package/ios/CobbaiPushRelay.h +59 -0
- package/ios/CobbaiPushRelay.m +364 -0
- package/package.json +69 -0
- package/src/ChatPlaceholder.tsx +132 -0
- package/src/CobbaiChatScreen.tsx +348 -0
- package/src/CobbaiInAppBanner.tsx +237 -0
- package/src/CobbaiLauncher.tsx +223 -0
- package/src/CobbaiWebView.tsx +242 -0
- package/src/adapters/expoAdapter.ts +227 -0
- package/src/adapters/firebaseAdapter.ts +201 -0
- package/src/adapters/iosRelayAdapter.ts +137 -0
- package/src/androidKeyboardFrame.ts +56 -0
- package/src/bridge/messages.ts +24 -0
- package/src/bridge/nativeEvent.ts +12 -0
- package/src/bridge/parser.ts +159 -0
- package/src/chatPresentation.ts +73 -0
- package/src/chatScreen/useInAppBannerQueue.ts +91 -0
- package/src/chatScreen/useKeyboardFrame.ts +89 -0
- package/src/chatScreen/useLauncherPresentation.ts +121 -0
- package/src/chatScreen/useNativeToWebSync.ts +54 -0
- package/src/chatScreen/usePushIntegration.ts +191 -0
- package/src/chatScreen/useReadyLifecycle.ts +186 -0
- package/src/chatScreen/useSheetPresentation.ts +147 -0
- package/src/chatUnavailable.ts +58 -0
- package/src/externalLinks.ts +56 -0
- package/src/host/buildHostHtml.ts +117 -0
- package/src/host/hostPageKey.ts +17 -0
- package/src/inAppBanner.ts +58 -0
- package/src/index.ts +53 -0
- package/src/launcher.ts +79 -0
- package/src/launcherGlyph.ts +3 -0
- package/src/openChatScreen.ts +78 -0
- package/src/push.ts +424 -0
- package/src/pushIntegration.ts +338 -0
- package/src/pushLogout.ts +277 -0
- package/src/types.ts +46 -0
- package/src/version.ts +8 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLauncherPresentation = useLauncherPresentation;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const react_native_1 = require("react-native");
|
|
6
|
+
const launcher_1 = require("../launcher");
|
|
7
|
+
/** Launcher colors (from cobbai:launcher, with a default fallback) and its fade in/out. */
|
|
8
|
+
function useLauncherPresentation({ prewarm, launcherVisible, visible, presented, }) {
|
|
9
|
+
const [launcherAppearance, setLauncherAppearance] = (0, react_1.useState)(prewarm ? null : launcher_1.DEFAULT_LAUNCHER_APPEARANCE);
|
|
10
|
+
const launcherOpacity = (0, react_1.useRef)(new react_native_1.Animated.Value(0)).current;
|
|
11
|
+
const previousLauncherPresentedRef = (0, react_1.useRef)(false);
|
|
12
|
+
const previousShowLauncherRef = (0, react_1.useRef)(false);
|
|
13
|
+
(0, react_1.useEffect)(() => {
|
|
14
|
+
if (launcherAppearance) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (!prewarm) {
|
|
18
|
+
setLauncherAppearance(launcher_1.DEFAULT_LAUNCHER_APPEARANCE);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const fallbackTimer = setTimeout(() => {
|
|
22
|
+
setLauncherAppearance((previousAppearance) => previousAppearance !== null && previousAppearance !== void 0 ? previousAppearance : launcher_1.DEFAULT_LAUNCHER_APPEARANCE);
|
|
23
|
+
}, launcher_1.LAUNCHER_DEFAULT_FALLBACK_DELAY_MS);
|
|
24
|
+
return () => {
|
|
25
|
+
clearTimeout(fallbackTimer);
|
|
26
|
+
};
|
|
27
|
+
}, [launcherAppearance, prewarm]);
|
|
28
|
+
const showLauncher = (0, launcher_1.shouldShowLauncher)({
|
|
29
|
+
launcherVisible,
|
|
30
|
+
visible,
|
|
31
|
+
presented,
|
|
32
|
+
appearance: launcherAppearance,
|
|
33
|
+
});
|
|
34
|
+
const launcherMounted = launcherAppearance != null;
|
|
35
|
+
(0, react_1.useEffect)(() => {
|
|
36
|
+
const wasPresented = previousLauncherPresentedRef.current;
|
|
37
|
+
const wasShowingLauncher = previousShowLauncherRef.current;
|
|
38
|
+
if (!launcherMounted || !showLauncher) {
|
|
39
|
+
launcherOpacity.stopAnimation();
|
|
40
|
+
launcherOpacity.setValue(0);
|
|
41
|
+
previousLauncherPresentedRef.current = presented;
|
|
42
|
+
previousShowLauncherRef.current = showLauncher;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const becameVisible = !wasShowingLauncher;
|
|
46
|
+
const didFinishCloseSlide = wasPresented && !presented;
|
|
47
|
+
if (didFinishCloseSlide) {
|
|
48
|
+
launcherOpacity.stopAnimation();
|
|
49
|
+
launcherOpacity.setValue(1);
|
|
50
|
+
previousLauncherPresentedRef.current = presented;
|
|
51
|
+
previousShowLauncherRef.current = showLauncher;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (becameVisible) {
|
|
55
|
+
launcherOpacity.stopAnimation();
|
|
56
|
+
launcherOpacity.setValue(0);
|
|
57
|
+
const launcherFadeIn = react_native_1.Animated.timing(launcherOpacity, {
|
|
58
|
+
toValue: 1,
|
|
59
|
+
duration: launcher_1.LAUNCHER_FADE_IN_DURATION_MS,
|
|
60
|
+
easing: react_native_1.Easing.linear,
|
|
61
|
+
useNativeDriver: true,
|
|
62
|
+
});
|
|
63
|
+
launcherFadeIn.start();
|
|
64
|
+
previousLauncherPresentedRef.current = presented;
|
|
65
|
+
previousShowLauncherRef.current = showLauncher;
|
|
66
|
+
return () => {
|
|
67
|
+
launcherFadeIn.stop();
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
launcherOpacity.stopAnimation();
|
|
71
|
+
launcherOpacity.setValue(1);
|
|
72
|
+
previousLauncherPresentedRef.current = presented;
|
|
73
|
+
previousShowLauncherRef.current = showLauncher;
|
|
74
|
+
}, [launcherMounted, launcherOpacity, presented, showLauncher]);
|
|
75
|
+
return { launcherAppearance, setLauncherAppearance, showLauncher, launcherOpacity };
|
|
76
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type MutableRefObject } from 'react';
|
|
2
|
+
import type { CobbaiWebViewRef } from '../CobbaiWebView';
|
|
3
|
+
import type { CobbaiSafeAreaInsets } from '../types';
|
|
4
|
+
type NativeToWebSyncInput = {
|
|
5
|
+
webViewRef: MutableRefObject<CobbaiWebViewRef | null>;
|
|
6
|
+
visible: boolean;
|
|
7
|
+
ready: boolean;
|
|
8
|
+
readySignal: number;
|
|
9
|
+
safeAreaForWeb: CobbaiSafeAreaInsets;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Native state pushed to the host page: app state and network on open,
|
|
13
|
+
* visibility once ready, and safe-area insets whenever they change.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useNativeToWebSync({ webViewRef, visible, ready, readySignal, safeAreaForWeb, }: NativeToWebSyncInput): void;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=useNativeToWebSync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNativeToWebSync.d.ts","sourceRoot":"","sources":["../../src/chatScreen/useNativeToWebSync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAa,MAAM,OAAO,CAAC;AAGzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAErD,KAAK,oBAAoB,GAAG;IAC1B,UAAU,EAAE,gBAAgB,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IACtD,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,oBAAoB,CAAC;CACtC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,UAAU,EACV,OAAO,EACP,KAAK,EACL,WAAW,EACX,cAAc,GACf,EAAE,oBAAoB,GAAG,IAAI,CA6B7B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useNativeToWebSync = useNativeToWebSync;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const messages_1 = require("../bridge/messages");
|
|
6
|
+
const nativeEvent_1 = require("../bridge/nativeEvent");
|
|
7
|
+
/**
|
|
8
|
+
* Native state pushed to the host page: app state and network on open,
|
|
9
|
+
* visibility once ready, and safe-area insets whenever they change.
|
|
10
|
+
*/
|
|
11
|
+
function useNativeToWebSync({ webViewRef, visible, ready, readySignal, safeAreaForWeb, }) {
|
|
12
|
+
// App state and network: constant values for now, not read by the chat page.
|
|
13
|
+
(0, react_1.useEffect)(() => {
|
|
14
|
+
if (!visible || !webViewRef.current)
|
|
15
|
+
return;
|
|
16
|
+
const appStateScript = (0, nativeEvent_1.serializeNativeEvent)(messages_1.NATIVE_TO_WEB_MESSAGES.APP_STATE, {
|
|
17
|
+
state: 'active',
|
|
18
|
+
});
|
|
19
|
+
webViewRef.current.injectJavaScript(appStateScript);
|
|
20
|
+
const networkScript = (0, nativeEvent_1.serializeNativeEvent)(messages_1.NATIVE_TO_WEB_MESSAGES.NETWORK, { online: true });
|
|
21
|
+
webViewRef.current.injectJavaScript(networkScript);
|
|
22
|
+
}, [visible, webViewRef]);
|
|
23
|
+
(0, react_1.useEffect)(() => {
|
|
24
|
+
if (!ready || !webViewRef.current) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const visibilityScript = (0, nativeEvent_1.serializeNativeEvent)(messages_1.NATIVE_TO_WEB_MESSAGES.VISIBILITY, { visible });
|
|
28
|
+
webViewRef.current.injectJavaScript(visibilityScript);
|
|
29
|
+
}, [ready, readySignal, visible, webViewRef]);
|
|
30
|
+
(0, react_1.useEffect)(() => {
|
|
31
|
+
if (!webViewRef.current)
|
|
32
|
+
return;
|
|
33
|
+
const safeAreaScript = (0, nativeEvent_1.serializeNativeEvent)(messages_1.NATIVE_TO_WEB_MESSAGES.SAFE_AREA, safeAreaForWeb);
|
|
34
|
+
webViewRef.current.injectJavaScript(safeAreaScript);
|
|
35
|
+
}, [ready, safeAreaForWeb, webViewRef]);
|
|
36
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type MutableRefObject } from 'react';
|
|
2
|
+
import type { CobbaiWebViewRef } from '../CobbaiWebView';
|
|
3
|
+
type PushIntegrationInput = {
|
|
4
|
+
chatId: string;
|
|
5
|
+
webViewRef: MutableRefObject<CobbaiWebViewRef | null>;
|
|
6
|
+
ready: boolean;
|
|
7
|
+
readySignal: number;
|
|
8
|
+
failed: boolean;
|
|
9
|
+
shouldRenderWebView: boolean;
|
|
10
|
+
chatSurfaceOnScreen: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Bridges the global push store and the mounted chat: which chat is mounted, whether it is live
|
|
14
|
+
* (foreground pushes are then dropped), token register/unregister, and opening a tapped push's
|
|
15
|
+
* conversation.
|
|
16
|
+
*/
|
|
17
|
+
export declare function usePushIntegration({ chatId, webViewRef, ready, readySignal, failed, shouldRenderWebView, chatSurfaceOnScreen, }: PushIntegrationInput): void;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=usePushIntegration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePushIntegration.d.ts","sourceRoot":"","sources":["../../src/chatScreen/usePushIntegration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAuB,MAAM,OAAO,CAAC;AAInE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAoBzD,KAAK,oBAAoB,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,gBAAgB,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IACtD,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,mBAAmB,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,MAAM,EACN,UAAU,EACV,KAAK,EACL,WAAW,EACX,MAAM,EACN,mBAAmB,EACnB,mBAAmB,GACpB,EAAE,oBAAoB,GAAG,IAAI,CA+I7B"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePushIntegration = usePushIntegration;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const react_native_1 = require("react-native");
|
|
6
|
+
const messages_1 = require("../bridge/messages");
|
|
7
|
+
const nativeEvent_1 = require("../bridge/nativeEvent");
|
|
8
|
+
const openChatScreen_1 = require("../openChatScreen");
|
|
9
|
+
const push_1 = require("../push");
|
|
10
|
+
function formatTokenSuffix(token) {
|
|
11
|
+
if (token.length <= 6) {
|
|
12
|
+
return '...<redacted>';
|
|
13
|
+
}
|
|
14
|
+
return `...${token.slice(-6)}`;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Bridges the global push store and the mounted chat: which chat is mounted, whether it is live
|
|
18
|
+
* (foreground pushes are then dropped), token register/unregister, and opening a tapped push's
|
|
19
|
+
* conversation.
|
|
20
|
+
*/
|
|
21
|
+
function usePushIntegration({ chatId, webViewRef, ready, readySignal, failed, shouldRenderWebView, chatSurfaceOnScreen, }) {
|
|
22
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
23
|
+
const [pushStore, setPushStore] = (0, react_1.useState)(push_1.getPushStoreSnapshot);
|
|
24
|
+
const [appState, setAppState] = (0, react_1.useState)((_a = react_native_1.AppState.currentState) !== null && _a !== void 0 ? _a : 'active');
|
|
25
|
+
(0, react_1.useEffect)(() => {
|
|
26
|
+
const unsubscribe = (0, push_1.subscribePushStore)(() => {
|
|
27
|
+
setPushStore((0, push_1.getPushStoreSnapshot)());
|
|
28
|
+
});
|
|
29
|
+
return unsubscribe;
|
|
30
|
+
}, []);
|
|
31
|
+
(0, react_1.useEffect)(() => {
|
|
32
|
+
(0, push_1.setMountedChatId)(chatId);
|
|
33
|
+
return () => {
|
|
34
|
+
(0, push_1.clearMountedChatId)(chatId);
|
|
35
|
+
};
|
|
36
|
+
}, [chatId]);
|
|
37
|
+
(0, react_1.useEffect)(() => {
|
|
38
|
+
const subscription = react_native_1.AppState.addEventListener('change', (nextAppState) => {
|
|
39
|
+
setAppState(nextAppState);
|
|
40
|
+
});
|
|
41
|
+
return () => {
|
|
42
|
+
subscription.remove();
|
|
43
|
+
};
|
|
44
|
+
}, []);
|
|
45
|
+
const connected = ready && !failed && shouldRenderWebView && appState === 'active';
|
|
46
|
+
(0, react_1.useEffect)(() => {
|
|
47
|
+
(0, push_1.setPushConnected)(connected);
|
|
48
|
+
}, [connected]);
|
|
49
|
+
(0, react_1.useEffect)(() => {
|
|
50
|
+
return () => {
|
|
51
|
+
(0, push_1.setPushConnected)(false);
|
|
52
|
+
};
|
|
53
|
+
}, []);
|
|
54
|
+
// Effects below depend on token fields, not on snapshot objects: every store change yields a
|
|
55
|
+
// new snapshot, and only a real change of these values must re-send anything.
|
|
56
|
+
const tokenValue = (_b = pushStore.token) === null || _b === void 0 ? void 0 : _b.token;
|
|
57
|
+
const tokenProvider = (_c = pushStore.token) === null || _c === void 0 ? void 0 : _c.provider;
|
|
58
|
+
const tokenApnsEnvironment = (_d = pushStore.token) === null || _d === void 0 ? void 0 : _d.apnsEnvironment;
|
|
59
|
+
(0, react_1.useEffect)(() => {
|
|
60
|
+
if (!ready || !webViewRef.current || !tokenValue || !tokenProvider) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const registerPayload = {
|
|
64
|
+
action: 'register',
|
|
65
|
+
token: tokenValue,
|
|
66
|
+
provider: tokenProvider,
|
|
67
|
+
};
|
|
68
|
+
if (tokenProvider === 'apns' && tokenApnsEnvironment) {
|
|
69
|
+
registerPayload.apns_environment = tokenApnsEnvironment;
|
|
70
|
+
}
|
|
71
|
+
const registerScript = (0, nativeEvent_1.serializeNativeEvent)(messages_1.NATIVE_TO_WEB_MESSAGES.PUSH_TOKEN, registerPayload);
|
|
72
|
+
webViewRef.current.injectJavaScript(registerScript);
|
|
73
|
+
if (__DEV__) {
|
|
74
|
+
console.log(`[cobbai][push] register provider=${tokenProvider} token=${formatTokenSuffix(tokenValue)}`);
|
|
75
|
+
}
|
|
76
|
+
// readySignal: re-register after every ready, a remounted page starts from nothing.
|
|
77
|
+
}, [ready, readySignal, tokenApnsEnvironment, tokenProvider, tokenValue, webViewRef]);
|
|
78
|
+
const unregisterValue = (_e = pushStore.pendingUnregister) === null || _e === void 0 ? void 0 : _e.token;
|
|
79
|
+
const unregisterProvider = (_f = pushStore.pendingUnregister) === null || _f === void 0 ? void 0 : _f.provider;
|
|
80
|
+
const unregisterApnsEnvironment = (_g = pushStore.pendingUnregister) === null || _g === void 0 ? void 0 : _g.apnsEnvironment;
|
|
81
|
+
(0, react_1.useEffect)(() => {
|
|
82
|
+
if (!ready || !webViewRef.current || !unregisterValue || !unregisterProvider) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const pendingUnregister = {
|
|
86
|
+
token: unregisterValue,
|
|
87
|
+
provider: unregisterProvider,
|
|
88
|
+
apnsEnvironment: unregisterApnsEnvironment,
|
|
89
|
+
};
|
|
90
|
+
const unregisterScript = (0, nativeEvent_1.serializeNativeEvent)(messages_1.NATIVE_TO_WEB_MESSAGES.PUSH_TOKEN, {
|
|
91
|
+
action: 'unregister',
|
|
92
|
+
token: pendingUnregister.token,
|
|
93
|
+
provider: pendingUnregister.provider,
|
|
94
|
+
});
|
|
95
|
+
webViewRef.current.injectJavaScript(unregisterScript);
|
|
96
|
+
if (__DEV__) {
|
|
97
|
+
console.log(`[cobbai][push] unregister provider=${pendingUnregister.provider} token=${formatTokenSuffix(pendingUnregister.token)}`);
|
|
98
|
+
}
|
|
99
|
+
(0, push_1.clearPendingUnregister)(pendingUnregister);
|
|
100
|
+
}, [ready, unregisterApnsEnvironment, unregisterProvider, unregisterValue, webViewRef]);
|
|
101
|
+
(0, react_1.useEffect)(() => {
|
|
102
|
+
const pendingOpen = pushStore.pendingOpen;
|
|
103
|
+
if (!pendingOpen) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
if (pendingOpen.chatId !== chatId) {
|
|
107
|
+
if (__DEV__) {
|
|
108
|
+
console.log('[cobbai][push] drop pending open for mismatched chat');
|
|
109
|
+
}
|
|
110
|
+
(0, push_1.clearPendingOpen)(pendingOpen);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (!chatSurfaceOnScreen) {
|
|
114
|
+
(0, openChatScreen_1.openChatScreen)();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (!ready || !webViewRef.current) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const openConversationScript = (0, nativeEvent_1.serializeNativeEvent)(messages_1.NATIVE_TO_WEB_MESSAGES.OPEN_CONVERSATION, {
|
|
121
|
+
conversation_id: pendingOpen.conversationId,
|
|
122
|
+
});
|
|
123
|
+
webViewRef.current.injectJavaScript(openConversationScript);
|
|
124
|
+
(0, push_1.clearPendingOpen)(pendingOpen);
|
|
125
|
+
if (__DEV__) {
|
|
126
|
+
console.log(`[cobbai][push] open-conversation id=${pendingOpen.conversationId}`);
|
|
127
|
+
}
|
|
128
|
+
}, [chatSurfaceOnScreen, chatId, pushStore.pendingOpen, ready, webViewRef]);
|
|
129
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type MutableRefObject } from 'react';
|
|
2
|
+
import type { ProcessGoneEvent } from '../CobbaiWebView';
|
|
3
|
+
import type { CobbaiChatConfig, CobbaiError } from '../types';
|
|
4
|
+
export declare const READY_TIMEOUT_MS = 10000;
|
|
5
|
+
type ReadyLifecycleInput = {
|
|
6
|
+
visible: boolean;
|
|
7
|
+
/** Latest config; callbacks are read from it so a new config object restarts nothing. */
|
|
8
|
+
configRef: MutableRefObject<CobbaiChatConfig>;
|
|
9
|
+
/** Identifies the page the WebView loads (hostPageKey): a change is a new page. */
|
|
10
|
+
pageKey: string;
|
|
11
|
+
};
|
|
12
|
+
export type ReadyLifecycle = {
|
|
13
|
+
ready: boolean;
|
|
14
|
+
failed: boolean;
|
|
15
|
+
/** Bumped on every cobbai:ready, including after a remount, so state can be re-sent. */
|
|
16
|
+
readySignal: number;
|
|
17
|
+
/** WebView key: bumping it remounts the WebView. */
|
|
18
|
+
webViewGeneration: number;
|
|
19
|
+
handleReady: () => void;
|
|
20
|
+
handleError: (error: CobbaiError) => void;
|
|
21
|
+
handleProcessGone: (event: ProcessGoneEvent) => void;
|
|
22
|
+
/** Remounts the WebView by hand (Retry button). */
|
|
23
|
+
retry: () => void;
|
|
24
|
+
/** The WebView went away with the sheet (no prewarm): the next open waits for ready again. */
|
|
25
|
+
resetReady: () => void;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Ready handshake, ready timeout, failure state and WebView remounts (retry, auto-retry on open,
|
|
29
|
+
* content process death).
|
|
30
|
+
*/
|
|
31
|
+
export declare function useReadyLifecycle({ visible, configRef, pageKey, }: ReadyLifecycleInput): ReadyLifecycle;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=useReadyLifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useReadyLifecycle.d.ts","sourceRoot":"","sources":["../../src/chatScreen/useReadyLifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAA4C,MAAM,OAAO,CAAC;AAGxF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE9D,eAAO,MAAM,gBAAgB,QAAS,CAAC;AASvC,KAAK,mBAAmB,GAAG;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,yFAAyF;IACzF,SAAS,EAAE,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IAC9C,mFAAmF;IACnF,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,wFAAwF;IACxF,WAAW,EAAE,MAAM,CAAC;IACpB,oDAAoD;IACpD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,WAAW,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAC1C,iBAAiB,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACrD,mDAAmD;IACnD,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,8FAA8F;IAC9F,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,OAAO,EACP,SAAS,EACT,OAAO,GACR,EAAE,mBAAmB,GAAG,cAAc,CA0ItC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.READY_TIMEOUT_MS = void 0;
|
|
4
|
+
exports.useReadyLifecycle = useReadyLifecycle;
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const chatPresentation_1 = require("../chatPresentation");
|
|
7
|
+
const chatUnavailable_1 = require("../chatUnavailable");
|
|
8
|
+
exports.READY_TIMEOUT_MS = 10000;
|
|
9
|
+
function normalizeError(error) {
|
|
10
|
+
return {
|
|
11
|
+
code: error.code || 'chat_error',
|
|
12
|
+
message: error.message || 'Unknown chat error',
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Ready handshake, ready timeout, failure state and WebView remounts (retry, auto-retry on open,
|
|
17
|
+
* content process death).
|
|
18
|
+
*/
|
|
19
|
+
function useReadyLifecycle({ visible, configRef, pageKey, }) {
|
|
20
|
+
const [ready, setReady] = (0, react_1.useState)(false);
|
|
21
|
+
const [failed, setFailed] = (0, react_1.useState)(false);
|
|
22
|
+
const [readySignal, setReadySignal] = (0, react_1.useState)(0);
|
|
23
|
+
const [remountCount, setRemountCount] = (0, react_1.useState)(0);
|
|
24
|
+
const [loadedPage, setLoadedPage] = (0, react_1.useState)({ key: pageKey, count: 0 });
|
|
25
|
+
// Bumped by a retry, a process-death remount, and a new page.
|
|
26
|
+
const webViewGeneration = remountCount + loadedPage.count;
|
|
27
|
+
const previousVisibleRef = (0, react_1.useRef)(false);
|
|
28
|
+
const processGoneOccurrencesRef = (0, react_1.useRef)([]);
|
|
29
|
+
const readyTimeoutRef = (0, react_1.useRef)(null);
|
|
30
|
+
const clearReadyTimeout = (0, react_1.useCallback)(() => {
|
|
31
|
+
if (readyTimeoutRef.current) {
|
|
32
|
+
clearTimeout(readyTimeoutRef.current);
|
|
33
|
+
readyTimeoutRef.current = null;
|
|
34
|
+
}
|
|
35
|
+
}, []);
|
|
36
|
+
const remountWebView = (0, react_1.useCallback)(() => {
|
|
37
|
+
clearReadyTimeout();
|
|
38
|
+
setReady(false);
|
|
39
|
+
setFailed(false);
|
|
40
|
+
setRemountCount((count) => count + 1);
|
|
41
|
+
}, [clearReadyTimeout]);
|
|
42
|
+
// A new source is a new page (login, logout): the WebView is remounted and
|
|
43
|
+
// `ready` drops in this same render, before any effect runs. Resetting it in an effect left one
|
|
44
|
+
// commit where the other hooks saw the new config with `ready` still true and injected into the
|
|
45
|
+
// page being replaced (a logout unregister or a conversation to open was then lost), and the
|
|
46
|
+
// replaced page could still send a late cobbai:ready. The ready timer restarts through its
|
|
47
|
+
// webViewGeneration dependency.
|
|
48
|
+
if (loadedPage.key !== pageKey) {
|
|
49
|
+
setLoadedPage({ key: pageKey, count: loadedPage.count + 1 });
|
|
50
|
+
setReady(false);
|
|
51
|
+
setFailed(false);
|
|
52
|
+
}
|
|
53
|
+
(0, react_1.useEffect)(() => {
|
|
54
|
+
const wasVisible = previousVisibleRef.current;
|
|
55
|
+
const becameVisible = !wasVisible && visible;
|
|
56
|
+
previousVisibleRef.current = visible;
|
|
57
|
+
if ((0, chatUnavailable_1.shouldAutoRetryOnOpen)({ becameVisible, ready, failed })) {
|
|
58
|
+
remountWebView();
|
|
59
|
+
}
|
|
60
|
+
}, [failed, ready, remountWebView, visible]);
|
|
61
|
+
(0, react_1.useEffect)(() => {
|
|
62
|
+
// Already failed: the unavailable state is shown and onError was reported; a ready_timeout
|
|
63
|
+
// on top would be a second error for the same failure.
|
|
64
|
+
if (!visible || ready || failed)
|
|
65
|
+
return;
|
|
66
|
+
readyTimeoutRef.current = setTimeout(() => {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
const timeoutError = {
|
|
69
|
+
code: 'ready_timeout',
|
|
70
|
+
message: 'Chat did not become ready in time',
|
|
71
|
+
};
|
|
72
|
+
setFailed(true);
|
|
73
|
+
(_b = (_a = configRef.current).onError) === null || _b === void 0 ? void 0 : _b.call(_a, timeoutError);
|
|
74
|
+
}, exports.READY_TIMEOUT_MS);
|
|
75
|
+
return clearReadyTimeout;
|
|
76
|
+
}, [clearReadyTimeout, configRef, failed, ready, visible, webViewGeneration]);
|
|
77
|
+
const handleReady = () => {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
clearReadyTimeout();
|
|
80
|
+
setFailed(false);
|
|
81
|
+
setReadySignal((currentSignal) => currentSignal + 1);
|
|
82
|
+
setReady(true);
|
|
83
|
+
(_b = (_a = configRef.current).onReady) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
84
|
+
};
|
|
85
|
+
const handleError = (error) => {
|
|
86
|
+
var _a, _b;
|
|
87
|
+
if (!ready) {
|
|
88
|
+
setFailed(true);
|
|
89
|
+
}
|
|
90
|
+
(_b = (_a = configRef.current).onError) === null || _b === void 0 ? void 0 : _b.call(_a, normalizeError(error));
|
|
91
|
+
};
|
|
92
|
+
const handleProcessGone = (event) => {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
const decision = (0, chatPresentation_1.getProcessGoneRecoveryDecision)(processGoneOccurrencesRef.current, Date.now());
|
|
95
|
+
processGoneOccurrencesRef.current = decision.nextOccurrenceTimestampsMs;
|
|
96
|
+
const nextGeneration = webViewGeneration + (decision.shouldRemount ? 1 : 0);
|
|
97
|
+
if (__DEV__) {
|
|
98
|
+
console.log('[cobbai][process-gone]', JSON.stringify({
|
|
99
|
+
platform: event.platform,
|
|
100
|
+
didCrash: event.didCrash,
|
|
101
|
+
generation: nextGeneration,
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
const recoveryHint = decision.shouldRemount
|
|
105
|
+
? 'Attempting automatic remount.'
|
|
106
|
+
: 'Automatic remount disabled after repeated failures.';
|
|
107
|
+
const platformDetails = event.platform === 'android'
|
|
108
|
+
? `platform=android didCrash=${event.didCrash === true ? 'true' : 'false'}`
|
|
109
|
+
: 'platform=ios';
|
|
110
|
+
(_b = (_a = configRef.current).onError) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
111
|
+
code: 'webview_process_gone',
|
|
112
|
+
message: `WebView content process was terminated (${platformDetails}). ${recoveryHint}`,
|
|
113
|
+
});
|
|
114
|
+
if (!decision.shouldRemount) {
|
|
115
|
+
// The WebView is dead and will not come back on its own. Leaving `ready` set would show a
|
|
116
|
+
// blank sheet whose only close button lived in the dead page (no way out on iOS); fall back
|
|
117
|
+
// to the unavailable placeholder, which has native close and retry buttons.
|
|
118
|
+
setReady(false);
|
|
119
|
+
setFailed(true);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
remountWebView();
|
|
123
|
+
};
|
|
124
|
+
const resetReady = (0, react_1.useCallback)(() => {
|
|
125
|
+
setReady(false);
|
|
126
|
+
}, []);
|
|
127
|
+
return {
|
|
128
|
+
ready,
|
|
129
|
+
failed,
|
|
130
|
+
readySignal,
|
|
131
|
+
webViewGeneration,
|
|
132
|
+
handleReady,
|
|
133
|
+
handleError,
|
|
134
|
+
handleProcessGone,
|
|
135
|
+
retry: remountWebView,
|
|
136
|
+
resetReady,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Animated } from 'react-native';
|
|
2
|
+
type SheetPresentationInput = {
|
|
3
|
+
/** Called once the close slide has finished and the sheet is off screen. */
|
|
4
|
+
onDismissed: () => void;
|
|
5
|
+
};
|
|
6
|
+
export type SheetPresentation = {
|
|
7
|
+
/** Open requested (openChatScreen) and not yet closed. */
|
|
8
|
+
visible: boolean;
|
|
9
|
+
/** On screen, including during the close slide. */
|
|
10
|
+
presented: boolean;
|
|
11
|
+
overlayTranslateY: Animated.Value;
|
|
12
|
+
backdropOpacity: Animated.AnimatedInterpolation<number>;
|
|
13
|
+
};
|
|
14
|
+
/** Open/close state from the visibility store, and the sheet's slide and backdrop. */
|
|
15
|
+
export declare function useSheetPresentation({ onDismissed }: SheetPresentationInput): SheetPresentation;
|
|
16
|
+
/**
|
|
17
|
+
* Keeps the loading/unavailable placeholder mounted while it is shown, and fades it out once the
|
|
18
|
+
* chat is ready (unmounted at once when the sheet is closed).
|
|
19
|
+
*/
|
|
20
|
+
export declare function useLoaderFade(loaderVisible: boolean, visible: boolean): {
|
|
21
|
+
loaderMounted: boolean;
|
|
22
|
+
loaderOpacity: Animated.Value;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=useSheetPresentation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSheetPresentation.d.ts","sourceRoot":"","sources":["../../src/chatScreen/useSheetPresentation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAA2C,MAAM,cAAc,CAAC;AASjF,KAAK,sBAAsB,GAAG;IAC5B,4EAA4E;IAC5E,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,0DAA0D;IAC1D,OAAO,EAAE,OAAO,CAAC;IACjB,mDAAmD;IACnD,SAAS,EAAE,OAAO,CAAC;IACnB,iBAAiB,EAAE,QAAQ,CAAC,KAAK,CAAC;IAClC,eAAe,EAAE,QAAQ,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;CACzD,CAAC;AAEF,sFAAsF;AACtF,wBAAgB,oBAAoB,CAAC,EAAE,WAAW,EAAE,EAAE,sBAAsB,GAAG,iBAAiB,CAgE/F;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,aAAa,EAAE,OAAO,EACtB,OAAO,EAAE,OAAO,GACf;IACD,aAAa,EAAE,OAAO,CAAC;IACvB,aAAa,EAAE,QAAQ,CAAC,KAAK,CAAC;CAC/B,CA6CA"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSheetPresentation = useSheetPresentation;
|
|
4
|
+
exports.useLoaderFade = useLoaderFade;
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const react_native_1 = require("react-native");
|
|
7
|
+
const chatPresentation_1 = require("../chatPresentation");
|
|
8
|
+
const openChatScreen_1 = require("../openChatScreen");
|
|
9
|
+
/** Open/close state from the visibility store, and the sheet's slide and backdrop. */
|
|
10
|
+
function useSheetPresentation({ onDismissed }) {
|
|
11
|
+
const [visible, setVisible] = (0, react_1.useState)(false);
|
|
12
|
+
const [presented, setPresented] = (0, react_1.useState)(false);
|
|
13
|
+
const onDismissedRef = (0, react_1.useRef)(onDismissed);
|
|
14
|
+
onDismissedRef.current = onDismissed;
|
|
15
|
+
const overlayTranslateY = (0, react_1.useRef)(new react_native_1.Animated.Value((0, chatPresentation_1.getOffscreenTranslateY)(react_native_1.Dimensions.get('window').height))).current;
|
|
16
|
+
const { height: windowHeight } = (0, react_native_1.useWindowDimensions)();
|
|
17
|
+
const offscreenTranslateY = (0, react_1.useMemo)(() => (0, chatPresentation_1.getOffscreenTranslateY)(windowHeight), [windowHeight]);
|
|
18
|
+
(0, react_1.useEffect)(() => {
|
|
19
|
+
const unsubscribe = (0, openChatScreen_1.subscribeChatVisibility)((nextVisible) => {
|
|
20
|
+
setVisible(nextVisible);
|
|
21
|
+
if (nextVisible) {
|
|
22
|
+
setPresented(true);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return unsubscribe;
|
|
26
|
+
}, []);
|
|
27
|
+
(0, react_1.useEffect)(() => {
|
|
28
|
+
if (!visible && !presented) {
|
|
29
|
+
overlayTranslateY.stopAnimation();
|
|
30
|
+
overlayTranslateY.setValue(offscreenTranslateY);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
overlayTranslateY.stopAnimation();
|
|
34
|
+
const slideAnimation = react_native_1.Animated.timing(overlayTranslateY, {
|
|
35
|
+
toValue: visible ? 0 : offscreenTranslateY,
|
|
36
|
+
duration: chatPresentation_1.SHEET_TRANSITION_DURATION_MS,
|
|
37
|
+
easing: visible ? react_native_1.Easing.out(react_native_1.Easing.cubic) : react_native_1.Easing.in(react_native_1.Easing.cubic),
|
|
38
|
+
useNativeDriver: true,
|
|
39
|
+
});
|
|
40
|
+
slideAnimation.start(({ finished }) => {
|
|
41
|
+
if (!finished || visible) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
setPresented(false);
|
|
45
|
+
onDismissedRef.current();
|
|
46
|
+
});
|
|
47
|
+
return () => {
|
|
48
|
+
slideAnimation.stop();
|
|
49
|
+
};
|
|
50
|
+
}, [offscreenTranslateY, overlayTranslateY, presented, visible]);
|
|
51
|
+
const backdropOpacity = (0, react_1.useMemo)(() => overlayTranslateY.interpolate({
|
|
52
|
+
...(0, chatPresentation_1.getBackdropOpacityInterpolationRanges)(offscreenTranslateY),
|
|
53
|
+
extrapolate: 'clamp',
|
|
54
|
+
}), [offscreenTranslateY, overlayTranslateY]);
|
|
55
|
+
return { visible, presented, overlayTranslateY, backdropOpacity };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Keeps the loading/unavailable placeholder mounted while it is shown, and fades it out once the
|
|
59
|
+
* chat is ready (unmounted at once when the sheet is closed).
|
|
60
|
+
*/
|
|
61
|
+
function useLoaderFade(loaderVisible, visible) {
|
|
62
|
+
const [loaderMounted, setLoaderMounted] = (0, react_1.useState)(false);
|
|
63
|
+
const loaderOpacity = (0, react_1.useRef)(new react_native_1.Animated.Value(0)).current;
|
|
64
|
+
(0, react_1.useEffect)(() => {
|
|
65
|
+
if (loaderVisible) {
|
|
66
|
+
setLoaderMounted(true);
|
|
67
|
+
loaderOpacity.stopAnimation();
|
|
68
|
+
loaderOpacity.setValue(1);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (!loaderMounted) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (!visible) {
|
|
75
|
+
loaderOpacity.stopAnimation();
|
|
76
|
+
loaderOpacity.setValue(0);
|
|
77
|
+
setLoaderMounted(false);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
loaderOpacity.stopAnimation();
|
|
81
|
+
const fadeOutAnimation = react_native_1.Animated.timing(loaderOpacity, {
|
|
82
|
+
toValue: 0,
|
|
83
|
+
duration: chatPresentation_1.LOADER_FADE_OUT_DURATION_MS,
|
|
84
|
+
easing: react_native_1.Easing.linear,
|
|
85
|
+
useNativeDriver: true,
|
|
86
|
+
});
|
|
87
|
+
fadeOutAnimation.start(({ finished }) => {
|
|
88
|
+
if (!finished) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
setLoaderMounted(false);
|
|
92
|
+
});
|
|
93
|
+
return () => {
|
|
94
|
+
fadeOutAnimation.stop();
|
|
95
|
+
};
|
|
96
|
+
}, [loaderMounted, loaderOpacity, loaderVisible, visible]);
|
|
97
|
+
return { loaderMounted, loaderOpacity };
|
|
98
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type ChatPlaceholderState = 'hidden' | 'loading' | 'unavailable';
|
|
2
|
+
type PlaceholderStateInput = {
|
|
3
|
+
visible: boolean;
|
|
4
|
+
ready: boolean;
|
|
5
|
+
failed: boolean;
|
|
6
|
+
};
|
|
7
|
+
type AutoRetryInput = {
|
|
8
|
+
becameVisible: boolean;
|
|
9
|
+
ready: boolean;
|
|
10
|
+
failed: boolean;
|
|
11
|
+
};
|
|
12
|
+
export type ChatUnavailableCopy = {
|
|
13
|
+
title: string;
|
|
14
|
+
body: string;
|
|
15
|
+
retry: string;
|
|
16
|
+
close: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function isFrenchLocale(locale: string | undefined): boolean;
|
|
19
|
+
export declare function getChatUnavailableCopy(locale: string | undefined): ChatUnavailableCopy;
|
|
20
|
+
export declare function deriveChatPlaceholderState(input: PlaceholderStateInput): ChatPlaceholderState;
|
|
21
|
+
export declare function shouldAutoRetryOnOpen(input: AutoRetryInput): boolean;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=chatUnavailable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatUnavailable.d.ts","sourceRoot":"","sources":["../src/chatUnavailable.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,SAAS,GAAG,aAAa,CAAC;AAExE,KAAK,qBAAqB,GAAG;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAgBF,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAMlE;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,mBAAmB,CAEtF;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,qBAAqB,GAAG,oBAAoB,CAM7F;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAEpE"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFrenchLocale = isFrenchLocale;
|
|
4
|
+
exports.getChatUnavailableCopy = getChatUnavailableCopy;
|
|
5
|
+
exports.deriveChatPlaceholderState = deriveChatPlaceholderState;
|
|
6
|
+
exports.shouldAutoRetryOnOpen = shouldAutoRetryOnOpen;
|
|
7
|
+
const ENGLISH_COPY = {
|
|
8
|
+
title: 'Chat unavailable',
|
|
9
|
+
body: 'Check your connection and try again.',
|
|
10
|
+
retry: 'Try again',
|
|
11
|
+
close: 'Close',
|
|
12
|
+
};
|
|
13
|
+
const FRENCH_COPY = {
|
|
14
|
+
title: 'Chat indisponible',
|
|
15
|
+
body: 'Vérifiez votre connexion et réessayez.',
|
|
16
|
+
retry: 'Réessayer',
|
|
17
|
+
close: 'Fermer',
|
|
18
|
+
};
|
|
19
|
+
function isFrenchLocale(locale) {
|
|
20
|
+
if (!locale) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return locale.trim().toLowerCase().startsWith('fr');
|
|
24
|
+
}
|
|
25
|
+
function getChatUnavailableCopy(locale) {
|
|
26
|
+
return isFrenchLocale(locale) ? FRENCH_COPY : ENGLISH_COPY;
|
|
27
|
+
}
|
|
28
|
+
function deriveChatPlaceholderState(input) {
|
|
29
|
+
if (!input.visible || input.ready) {
|
|
30
|
+
return 'hidden';
|
|
31
|
+
}
|
|
32
|
+
return input.failed ? 'unavailable' : 'loading';
|
|
33
|
+
}
|
|
34
|
+
function shouldAutoRetryOnOpen(input) {
|
|
35
|
+
return input.becameVisible && input.failed && !input.ready;
|
|
36
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function isExternalOpenableUrl(url: string): boolean;
|
|
2
|
+
export declare function isHostDocumentUrl(url: string, baseUrl: string): boolean;
|
|
3
|
+
export declare function isFromHostOrigin(url: string | undefined, baseUrl: string): boolean;
|
|
4
|
+
//# sourceMappingURL=externalLinks.d.ts.map
|