@octovise/react-native-sdk 1.0.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 +43 -0
- package/LICENSE +21 -0
- package/README.md +160 -0
- package/android/src/main/java/com/octovise/sdk/OctoFirebaseMessagingService.kt +72 -0
- package/android/src/main/java/com/octovise/sdk/OctoPushDismissReceiver.kt +54 -0
- package/android/src/main/java/com/octovise/sdk/OctoPushModule.kt +26 -0
- package/android/src/main/java/com/octovise/sdk/OctoPushNotificationBuilder.kt +142 -0
- package/dist/api.d.ts +38 -0
- package/dist/api.js +210 -0
- package/dist/carouselStart.d.ts +1 -0
- package/dist/carouselStart.js +6 -0
- package/dist/components/OctoErrorBoundary.d.ts +15 -0
- package/dist/components/OctoErrorBoundary.js +28 -0
- package/dist/components/OctoImage.d.ts +23 -0
- package/dist/components/OctoImage.js +69 -0
- package/dist/components/OctoMessage.d.ts +9 -0
- package/dist/components/OctoMessage.js +189 -0
- package/dist/components/OctoModal.d.ts +13 -0
- package/dist/components/OctoModal.js +179 -0
- package/dist/components/OctoProvider.d.ts +14 -0
- package/dist/components/OctoProvider.js +92 -0
- package/dist/components/OctoToast.d.ts +13 -0
- package/dist/components/OctoToast.js +392 -0
- package/dist/debug.d.ts +2 -0
- package/dist/debug.js +15 -0
- package/dist/imageFit.d.ts +8 -0
- package/dist/imageFit.js +31 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +195 -0
- package/dist/latency.d.ts +17 -0
- package/dist/latency.js +11 -0
- package/dist/native.d.ts +1 -0
- package/dist/native.js +14 -0
- package/dist/navigation/reactNavigation.d.ts +12 -0
- package/dist/navigation/reactNavigation.js +24 -0
- package/dist/navigation/resolveCTA.d.ts +12 -0
- package/dist/navigation/resolveCTA.js +74 -0
- package/dist/push.d.ts +3 -0
- package/dist/push.js +129 -0
- package/dist/safeNavUrl.d.ts +2 -0
- package/dist/safeNavUrl.js +18 -0
- package/dist/screenStream.d.ts +17 -0
- package/dist/screenStream.js +126 -0
- package/dist/screenTargeting.d.ts +37 -0
- package/dist/screenTargeting.js +154 -0
- package/dist/session.d.ts +2 -0
- package/dist/session.js +22 -0
- package/dist/state.d.ts +8 -0
- package/dist/state.js +53 -0
- package/dist/telemetry.d.ts +6 -0
- package/dist/telemetry.js +65 -0
- package/dist/toastLayout.d.ts +2 -0
- package/dist/toastLayout.js +11 -0
- package/dist/types.d.ts +78 -0
- package/dist/types.js +7 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +4 -0
- package/ios/OctoviseNotificationExtension/NotificationService.swift +128 -0
- package/ios/OctoviseSDK/OctoPushModule.m +6 -0
- package/ios/OctoviseSDK/OctoPushModule.swift +27 -0
- package/package.json +57 -0
- package/react-native.config.js +16 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = OctoModal;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const react_native_1 = require("react-native");
|
|
9
|
+
const react_native_safe_area_context_1 = require("react-native-safe-area-context");
|
|
10
|
+
const OctoImage_1 = require("./OctoImage");
|
|
11
|
+
const { width: SCREEN_WIDTH } = react_native_1.Dimensions.get('window');
|
|
12
|
+
const INSETS = react_native_safe_area_context_1.initialWindowMetrics?.insets ?? { top: 0, right: 0, bottom: 0, left: 0 };
|
|
13
|
+
function getScale(size) {
|
|
14
|
+
if (size === 'small')
|
|
15
|
+
return 0.85;
|
|
16
|
+
if (size === 'large')
|
|
17
|
+
return 1.15;
|
|
18
|
+
return 1;
|
|
19
|
+
}
|
|
20
|
+
function getWidthPercent(size) {
|
|
21
|
+
if (size === 'small')
|
|
22
|
+
return 0.80;
|
|
23
|
+
if (size === 'large')
|
|
24
|
+
return 0.95;
|
|
25
|
+
return 0.90;
|
|
26
|
+
}
|
|
27
|
+
function getJustify(position) {
|
|
28
|
+
if (position === 'top')
|
|
29
|
+
return 'flex-start';
|
|
30
|
+
if (position === 'bottom')
|
|
31
|
+
return 'flex-end';
|
|
32
|
+
return 'center';
|
|
33
|
+
}
|
|
34
|
+
function modalImagePosition(imgPos) {
|
|
35
|
+
return imgPos === 'bottom' ? 'bottom' : 'top';
|
|
36
|
+
}
|
|
37
|
+
function OctoModal({ message, visible, onImpression, onCTAPress, onNoneEngagement, onDismiss, onImageError }) {
|
|
38
|
+
const scale = getScale(message.size);
|
|
39
|
+
const textScale = getScale(message.text_size);
|
|
40
|
+
const colors = message.colors || {};
|
|
41
|
+
const primary = colors.primary || '#6200ee';
|
|
42
|
+
const bg = colors.background || '#ffffff';
|
|
43
|
+
const textColor = colors.text || '#333333';
|
|
44
|
+
const modalWidth = SCREEN_WIDTH * getWidthPercent(message.size);
|
|
45
|
+
const position = message.mobile_position || 'center';
|
|
46
|
+
const clickMode = message.click_mode || 'cta';
|
|
47
|
+
const textAlign = message.text_align || 'left';
|
|
48
|
+
const imagePos = modalImagePosition(message.image_position);
|
|
49
|
+
const centeredPad = Math.max(INSETS.top, INSETS.bottom) + 16;
|
|
50
|
+
let padTop = INSETS.top + 16;
|
|
51
|
+
let padBottom = INSETS.bottom + 16;
|
|
52
|
+
if (position === 'center') {
|
|
53
|
+
padTop = centeredPad;
|
|
54
|
+
padBottom = centeredPad;
|
|
55
|
+
}
|
|
56
|
+
else if (position === 'bottom') {
|
|
57
|
+
padBottom = react_native_1.Platform.OS === 'ios' ? INSETS.bottom + 16 : Math.min(INSETS.bottom + 16, 24);
|
|
58
|
+
}
|
|
59
|
+
react_1.default.useEffect(() => {
|
|
60
|
+
if (visible)
|
|
61
|
+
onImpression();
|
|
62
|
+
}, [visible]);
|
|
63
|
+
const handlePress = () => {
|
|
64
|
+
if (clickMode === 'full')
|
|
65
|
+
onCTAPress();
|
|
66
|
+
else if (clickMode === 'none')
|
|
67
|
+
onNoneEngagement();
|
|
68
|
+
};
|
|
69
|
+
const content = (<react_native_1.View style={[styles.card, { backgroundColor: bg, width: modalWidth, borderRadius: 16 * scale }]}>
|
|
70
|
+
|
|
71
|
+
<react_native_1.TouchableOpacity style={[styles.closeBtn, { width: 32 * scale, height: 32 * scale, borderRadius: 16 * scale }]} onPress={() => onDismiss('close_button')} activeOpacity={0.7}>
|
|
72
|
+
<react_native_1.Text style={styles.closeBtnText}>×</react_native_1.Text>
|
|
73
|
+
</react_native_1.TouchableOpacity>
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
<react_native_1.View style={{ flexDirection: imagePos === 'bottom' ? 'column-reverse' : 'column' }}>
|
|
77
|
+
|
|
78
|
+
{message.image && (<OctoImage_1.OctoImage message={message} width={modalWidth} height={200 * scale} corners={imagePos === 'bottom'
|
|
79
|
+
? { bottomLeft: 16 * scale, bottomRight: 16 * scale }
|
|
80
|
+
: { topLeft: 16 * scale, topRight: 16 * scale }} bleed={imagePos === 'bottom' ? { bottom: 1, left: 1, right: 1 } : { top: 1, left: 1, right: 1 }} onError={onImageError} placeholderColor={textColor}/>)}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
<react_native_1.View style={[styles.body, { padding: 14 * scale }]}>
|
|
84
|
+
{message.title && (<react_native_1.Text style={[styles.title, { fontSize: 22 * textScale, color: textColor, textAlign }]}>
|
|
85
|
+
{message.title}
|
|
86
|
+
</react_native_1.Text>)}
|
|
87
|
+
{message.body && (<react_native_1.Text style={[styles.bodyText, { fontSize: 15 * textScale, color: textColor, textAlign }]}>
|
|
88
|
+
{message.body}
|
|
89
|
+
</react_native_1.Text>)}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
{clickMode === 'cta' && message.cta?.label && (<react_native_1.TouchableOpacity style={[styles.ctaBtn, { backgroundColor: primary, borderRadius: 10 * textScale }]} onPress={onCTAPress} activeOpacity={0.9}>
|
|
93
|
+
<react_native_1.Text style={[styles.ctaBtnText, { fontSize: 16 * textScale }]}>
|
|
94
|
+
{message.cta.label}
|
|
95
|
+
</react_native_1.Text>
|
|
96
|
+
</react_native_1.TouchableOpacity>)}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
{message.dismiss_label && clickMode !== 'full' && (<react_native_1.TouchableOpacity onPress={() => onDismiss('dismiss_button')} activeOpacity={0.7}>
|
|
100
|
+
<react_native_1.Text style={[styles.dismissText, { fontSize: 14 * textScale, color: textColor }]}>
|
|
101
|
+
{message.dismiss_label}
|
|
102
|
+
</react_native_1.Text>
|
|
103
|
+
</react_native_1.TouchableOpacity>)}
|
|
104
|
+
</react_native_1.View>
|
|
105
|
+
</react_native_1.View>
|
|
106
|
+
</react_native_1.View>);
|
|
107
|
+
return (<react_native_1.Modal transparent visible={visible} animationType="fade" statusBarTranslucent>
|
|
108
|
+
<react_native_1.TouchableOpacity style={[
|
|
109
|
+
styles.backdrop,
|
|
110
|
+
{
|
|
111
|
+
justifyContent: getJustify(position),
|
|
112
|
+
paddingTop: padTop,
|
|
113
|
+
paddingBottom: padBottom,
|
|
114
|
+
},
|
|
115
|
+
]} activeOpacity={1} onPress={() => onDismiss('backdrop')}>
|
|
116
|
+
<react_native_1.TouchableOpacity activeOpacity={1} onPress={clickMode === 'full' || clickMode === 'none' ? handlePress : undefined}>
|
|
117
|
+
{content}
|
|
118
|
+
</react_native_1.TouchableOpacity>
|
|
119
|
+
</react_native_1.TouchableOpacity>
|
|
120
|
+
</react_native_1.Modal>);
|
|
121
|
+
}
|
|
122
|
+
const styles = react_native_1.StyleSheet.create({
|
|
123
|
+
backdrop: {
|
|
124
|
+
flex: 1,
|
|
125
|
+
alignItems: 'center',
|
|
126
|
+
backgroundColor: 'rgba(0,0,0,0.5)',
|
|
127
|
+
},
|
|
128
|
+
card: {
|
|
129
|
+
overflow: 'hidden',
|
|
130
|
+
elevation: 20,
|
|
131
|
+
shadowColor: '#000',
|
|
132
|
+
shadowOffset: { width: 0, height: 20 },
|
|
133
|
+
shadowOpacity: 0.3,
|
|
134
|
+
shadowRadius: 30,
|
|
135
|
+
position: 'relative',
|
|
136
|
+
},
|
|
137
|
+
closeBtn: {
|
|
138
|
+
position: 'absolute',
|
|
139
|
+
top: 12,
|
|
140
|
+
right: 12,
|
|
141
|
+
zIndex: 10,
|
|
142
|
+
backgroundColor: 'rgba(0,0,0,0.4)',
|
|
143
|
+
alignItems: 'center',
|
|
144
|
+
justifyContent: 'center',
|
|
145
|
+
},
|
|
146
|
+
closeBtnText: {
|
|
147
|
+
color: '#fff',
|
|
148
|
+
fontSize: 18,
|
|
149
|
+
lineHeight: 20,
|
|
150
|
+
},
|
|
151
|
+
body: {
|
|
152
|
+
flexShrink: 1,
|
|
153
|
+
minWidth: 0,
|
|
154
|
+
},
|
|
155
|
+
title: {
|
|
156
|
+
fontWeight: '700',
|
|
157
|
+
marginBottom: 8,
|
|
158
|
+
lineHeight: 28,
|
|
159
|
+
},
|
|
160
|
+
bodyText: {
|
|
161
|
+
opacity: 0.8,
|
|
162
|
+
lineHeight: 22,
|
|
163
|
+
marginBottom: 24,
|
|
164
|
+
},
|
|
165
|
+
ctaBtn: {
|
|
166
|
+
paddingVertical: 14,
|
|
167
|
+
paddingHorizontal: 24,
|
|
168
|
+
alignItems: 'center',
|
|
169
|
+
},
|
|
170
|
+
ctaBtnText: {
|
|
171
|
+
color: '#fff',
|
|
172
|
+
fontWeight: '600',
|
|
173
|
+
},
|
|
174
|
+
dismissText: {
|
|
175
|
+
textAlign: 'center',
|
|
176
|
+
opacity: 0.5,
|
|
177
|
+
paddingVertical: 12,
|
|
178
|
+
},
|
|
179
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
import type { InAppMessage } from '../types';
|
|
3
|
+
interface OctoContextValue {
|
|
4
|
+
showMessage: (msg: InAppMessage, onCTA?: (url: string) => void) => void;
|
|
5
|
+
dismissMessage: () => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function useOcto(): OctoContextValue;
|
|
8
|
+
export declare function getGlobalShow(): (msg: InAppMessage, onCTA?: (url: string) => void) => void;
|
|
9
|
+
export declare function getGlobalDismiss(): () => void;
|
|
10
|
+
interface ProviderProps {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
export default function OctoProvider({ children }: ProviderProps): React.JSX.Element;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.useOcto = useOcto;
|
|
40
|
+
exports.getGlobalShow = getGlobalShow;
|
|
41
|
+
exports.getGlobalDismiss = getGlobalDismiss;
|
|
42
|
+
exports.default = OctoProvider;
|
|
43
|
+
const react_1 = __importStar(require("react"));
|
|
44
|
+
const react_native_1 = require("react-native");
|
|
45
|
+
const state_1 = require("../state");
|
|
46
|
+
const OctoMessage_1 = __importDefault(require("./OctoMessage"));
|
|
47
|
+
const OctoContext = (0, react_1.createContext)({
|
|
48
|
+
showMessage: () => { },
|
|
49
|
+
dismissMessage: () => { },
|
|
50
|
+
});
|
|
51
|
+
function useOcto() {
|
|
52
|
+
return (0, react_1.useContext)(OctoContext);
|
|
53
|
+
}
|
|
54
|
+
let globalShowMessage = () => {
|
|
55
|
+
console.warn('[OctoSDK] OctoProvider is not mounted. Wrap your app with <OctoProvider>.');
|
|
56
|
+
};
|
|
57
|
+
let globalDismissMessage = () => { };
|
|
58
|
+
function getGlobalShow() {
|
|
59
|
+
return globalShowMessage;
|
|
60
|
+
}
|
|
61
|
+
function getGlobalDismiss() {
|
|
62
|
+
return globalDismissMessage;
|
|
63
|
+
}
|
|
64
|
+
function OctoProvider({ children }) {
|
|
65
|
+
const [currentMessage, setCurrentMessage] = (0, react_1.useState)(null);
|
|
66
|
+
const [currentOnCTA, setCurrentOnCTA] = (0, react_1.useState)();
|
|
67
|
+
const showMessage = (0, react_1.useCallback)((msg, onCTA) => {
|
|
68
|
+
setCurrentMessage(msg);
|
|
69
|
+
setCurrentOnCTA(() => onCTA);
|
|
70
|
+
}, []);
|
|
71
|
+
const dismissMessage = (0, react_1.useCallback)(() => {
|
|
72
|
+
setCurrentMessage(null);
|
|
73
|
+
setCurrentOnCTA(undefined);
|
|
74
|
+
(0, state_1.clearCurrentMessage)();
|
|
75
|
+
}, []);
|
|
76
|
+
react_1.default.useEffect(() => {
|
|
77
|
+
globalShowMessage = showMessage;
|
|
78
|
+
globalDismissMessage = dismissMessage;
|
|
79
|
+
return () => {
|
|
80
|
+
globalShowMessage = () => { };
|
|
81
|
+
globalDismissMessage = () => { };
|
|
82
|
+
};
|
|
83
|
+
}, [showMessage, dismissMessage]);
|
|
84
|
+
const contextValue = react_1.default.useMemo(() => ({ showMessage, dismissMessage }), [showMessage, dismissMessage]);
|
|
85
|
+
return (<OctoContext.Provider value={contextValue}>
|
|
86
|
+
{children}
|
|
87
|
+
|
|
88
|
+
<react_native_1.View style={react_native_1.StyleSheet.absoluteFill} pointerEvents="box-none">
|
|
89
|
+
<OctoMessage_1.default message={currentMessage} onCTA={currentOnCTA} onDismissed={dismissMessage}/>
|
|
90
|
+
</react_native_1.View>
|
|
91
|
+
</OctoContext.Provider>);
|
|
92
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { InAppMessage } from '../types';
|
|
3
|
+
interface Props {
|
|
4
|
+
message: InAppMessage;
|
|
5
|
+
visible: boolean;
|
|
6
|
+
onImpression: () => void;
|
|
7
|
+
onCTAPress: () => void;
|
|
8
|
+
onNoneEngagement: () => void;
|
|
9
|
+
onDismiss: (method: string) => void;
|
|
10
|
+
onImageError?: () => void;
|
|
11
|
+
}
|
|
12
|
+
export default function OctoToast({ message, visible, onImpression, onCTAPress, onNoneEngagement, onDismiss, onImageError }: Props): React.JSX.Element;
|
|
13
|
+
export {};
|