@inngageregistry/inngage-react 4.0.0-beta.2 → 4.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/README.md +60 -60
- package/dist/Inngage.d.ts +28 -0
- package/dist/Inngage.js +149 -0
- package/dist/api/api.d.ts +4 -0
- package/{src/api/api.ts → dist/api/api.js} +22 -28
- package/dist/api/handler.d.ts +1 -0
- package/dist/api/handler.js +44 -0
- package/dist/components/in_app.d.ts +6 -0
- package/dist/components/in_app.js +92 -0
- package/dist/components/modal.d.ts +26 -0
- package/dist/components/modal.js +158 -0
- package/dist/components/styles.d.ts +88 -0
- package/dist/components/styles.js +86 -0
- package/dist/firebase/notifications_listener.d.ts +6 -0
- package/dist/firebase/notifications_listener.js +170 -0
- package/{src/index.ts → dist/index.d.ts} +6 -11
- package/dist/index.js +6 -0
- package/dist/models/inngage_properties.d.ts +11 -0
- package/dist/models/inngage_properties.js +13 -0
- package/dist/models/requests.d.ts +40 -0
- package/{src/models/requests.ts → dist/models/requests.js} +40 -42
- package/dist/services/api_services.d.ts +7 -0
- package/{src/services/api_services.ts → dist/services/api_services.js} +25 -30
- package/dist/services/handler.d.ts +1 -0
- package/dist/services/handler.js +38 -0
- package/dist/services/inngage.d.ts +4 -0
- package/dist/services/inngage.js +22 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +25 -0
- package/package.json +79 -40
- package/.editorconfig +0 -6
- package/src/Inngage.ts +0 -193
- package/src/api/handler.ts +0 -53
- package/src/components/in_app.tsx +0 -192
- package/src/components/modal.tsx +0 -221
- package/src/components/styles.ts +0 -88
- package/src/firebase/notifications_listener.ts +0 -182
- package/src/models/inngage_properties.ts +0 -13
- package/src/services/handler.ts +0 -41
- package/src/services/inngage.ts +0 -23
- package/src/utils.ts +0 -35
- package/tsconfig.json +0 -27
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Animated, Easing, Modal as ReactNativeModal, Platform, StyleSheet, TouchableWithoutFeedback } from "react-native";
|
|
3
|
+
import { Component } from "react";
|
|
4
|
+
const MODAL_ANIM_DURATION = 300;
|
|
5
|
+
const MODAL_BACKDROP_OPACITY = 0.3;
|
|
6
|
+
const CONTENT_ANIMATION_IN = Platform.select({
|
|
7
|
+
ios: {
|
|
8
|
+
opacity: {
|
|
9
|
+
inputRange: [0, 1],
|
|
10
|
+
outputRange: [0, 1],
|
|
11
|
+
},
|
|
12
|
+
scale: {
|
|
13
|
+
inputRange: [0, 0.5, 1],
|
|
14
|
+
outputRange: [1.2, 1.1, 1],
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
android: {
|
|
18
|
+
opacity: {
|
|
19
|
+
inputRange: [0, 0.5, 1],
|
|
20
|
+
outputRange: [0, 1, 1],
|
|
21
|
+
},
|
|
22
|
+
scale: {
|
|
23
|
+
inputRange: [0, 1],
|
|
24
|
+
outputRange: [0.3, 1],
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
default: {
|
|
28
|
+
opacity: {
|
|
29
|
+
inputRange: [0, 0.5, 1],
|
|
30
|
+
outputRange: [0, 1, 1],
|
|
31
|
+
},
|
|
32
|
+
scale: {
|
|
33
|
+
inputRange: [0, 1],
|
|
34
|
+
outputRange: [0.3, 1],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
const CONTENT_ANIMATION_OUT = Platform.select({
|
|
39
|
+
default: {
|
|
40
|
+
opacity: {
|
|
41
|
+
inputRange: [0, 1],
|
|
42
|
+
outputRange: [0, 1],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
export class Modal extends Component {
|
|
47
|
+
constructor() {
|
|
48
|
+
super(...arguments);
|
|
49
|
+
this.state = {
|
|
50
|
+
visible: Boolean(this.props.visible),
|
|
51
|
+
currentAnimation: "none",
|
|
52
|
+
};
|
|
53
|
+
this.animVal = new Animated.Value(0);
|
|
54
|
+
this._isMounted = false;
|
|
55
|
+
this.show = () => {
|
|
56
|
+
this.setState({ visible: true, currentAnimation: "in" }, () => {
|
|
57
|
+
Animated.timing(this.animVal, {
|
|
58
|
+
easing: Easing.inOut(Easing.quad),
|
|
59
|
+
useNativeDriver: Boolean(this.props.useNativeDriver),
|
|
60
|
+
duration: MODAL_ANIM_DURATION,
|
|
61
|
+
toValue: 1,
|
|
62
|
+
}).start(() => {
|
|
63
|
+
this.setState({ currentAnimation: "none" });
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
this.hide = () => {
|
|
68
|
+
this.setState({ currentAnimation: "out" }, () => {
|
|
69
|
+
Animated.timing(this.animVal, {
|
|
70
|
+
easing: Easing.inOut(Easing.quad),
|
|
71
|
+
useNativeDriver: Boolean(this.props.useNativeDriver),
|
|
72
|
+
duration: MODAL_ANIM_DURATION,
|
|
73
|
+
toValue: 0,
|
|
74
|
+
}).start(() => {
|
|
75
|
+
if (this._isMounted) {
|
|
76
|
+
this.setState({ currentAnimation: "none" });
|
|
77
|
+
this.setState({ visible: false }, this.props.onHide);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
componentDidMount() {
|
|
84
|
+
this._isMounted = true;
|
|
85
|
+
if (this.state.visible) {
|
|
86
|
+
this.show();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
componentWillUnmount() {
|
|
90
|
+
this._isMounted = false;
|
|
91
|
+
}
|
|
92
|
+
componentDidUpdate(prevProps) {
|
|
93
|
+
if (this.props.visible && !prevProps.visible) {
|
|
94
|
+
this.show();
|
|
95
|
+
}
|
|
96
|
+
else if (!this.props.visible && prevProps.visible) {
|
|
97
|
+
this.hide();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
render() {
|
|
101
|
+
const { children, onBackdropPress, contentStyle, ...otherProps } = this.props;
|
|
102
|
+
const { currentAnimation, visible } = this.state;
|
|
103
|
+
const backdropAnimatedStyle = {
|
|
104
|
+
opacity: this.animVal.interpolate({
|
|
105
|
+
inputRange: [0, 1],
|
|
106
|
+
outputRange: [0, MODAL_BACKDROP_OPACITY],
|
|
107
|
+
}),
|
|
108
|
+
};
|
|
109
|
+
const contentAnimatedStyle = currentAnimation === "in"
|
|
110
|
+
? {
|
|
111
|
+
opacity: this.animVal.interpolate({
|
|
112
|
+
inputRange: CONTENT_ANIMATION_IN.opacity.inputRange,
|
|
113
|
+
outputRange: CONTENT_ANIMATION_IN.opacity.outputRange,
|
|
114
|
+
extrapolate: "clamp",
|
|
115
|
+
}),
|
|
116
|
+
transform: [
|
|
117
|
+
{
|
|
118
|
+
scale: this.animVal.interpolate({
|
|
119
|
+
inputRange: CONTENT_ANIMATION_IN.scale.inputRange,
|
|
120
|
+
outputRange: CONTENT_ANIMATION_IN.scale.outputRange,
|
|
121
|
+
extrapolate: "clamp",
|
|
122
|
+
}),
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
}
|
|
126
|
+
: {
|
|
127
|
+
opacity: this.animVal.interpolate({
|
|
128
|
+
inputRange: CONTENT_ANIMATION_OUT.opacity.inputRange,
|
|
129
|
+
outputRange: CONTENT_ANIMATION_OUT.opacity.outputRange,
|
|
130
|
+
extrapolate: "clamp",
|
|
131
|
+
}),
|
|
132
|
+
};
|
|
133
|
+
return (_jsxs(ReactNativeModal, { transparent: true, animationType: "none", ...otherProps, visible: visible, children: [_jsx(TouchableWithoutFeedback, { onPress: onBackdropPress, children: _jsx(Animated.View, { style: [styles.backdrop, backdropAnimatedStyle] }) }), visible && (_jsx(Animated.View, { style: [styles.content, contentAnimatedStyle, contentStyle], pointerEvents: "box-none", needsOffscreenAlphaCompositing: ["in", "out"].includes(currentAnimation), children: children }))] }));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
Modal.defaultProps = {
|
|
137
|
+
onBackdropPress: () => null,
|
|
138
|
+
onHide: () => null,
|
|
139
|
+
visible: false,
|
|
140
|
+
useNativeDriver: false,
|
|
141
|
+
};
|
|
142
|
+
const styles = StyleSheet.create({
|
|
143
|
+
backdrop: {
|
|
144
|
+
position: "absolute",
|
|
145
|
+
top: 0,
|
|
146
|
+
bottom: 0,
|
|
147
|
+
left: 0,
|
|
148
|
+
right: 0,
|
|
149
|
+
backgroundColor: "black",
|
|
150
|
+
opacity: 0,
|
|
151
|
+
},
|
|
152
|
+
content: {
|
|
153
|
+
flex: 1,
|
|
154
|
+
alignItems: "center",
|
|
155
|
+
justifyContent: "center",
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
export default Modal;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export declare const buildStyles: (data: any, screen: any) => {
|
|
2
|
+
closeButton: {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
justifyContent: "center";
|
|
6
|
+
alignItems: "center";
|
|
7
|
+
backgroundColor: string;
|
|
8
|
+
borderRadius: number;
|
|
9
|
+
shadowOffset: {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
};
|
|
13
|
+
shadowOpacity: number;
|
|
14
|
+
shadowRadius: number;
|
|
15
|
+
position: "absolute";
|
|
16
|
+
top: number;
|
|
17
|
+
right: number;
|
|
18
|
+
zIndex: number;
|
|
19
|
+
};
|
|
20
|
+
textButton: {
|
|
21
|
+
color: string;
|
|
22
|
+
fontSize: number;
|
|
23
|
+
fontWeight: "bold";
|
|
24
|
+
};
|
|
25
|
+
content: {
|
|
26
|
+
backgroundColor: any;
|
|
27
|
+
flexDirection: "column";
|
|
28
|
+
borderRadius: number;
|
|
29
|
+
paddingBottom: number;
|
|
30
|
+
paddingRight: number;
|
|
31
|
+
paddingLeft: number;
|
|
32
|
+
margin: number;
|
|
33
|
+
overflow: "hidden";
|
|
34
|
+
elevation: number;
|
|
35
|
+
width: any;
|
|
36
|
+
alignItems: "center";
|
|
37
|
+
};
|
|
38
|
+
messageData: {
|
|
39
|
+
marginTop: number;
|
|
40
|
+
alignItems: "center";
|
|
41
|
+
justifyContent: "center";
|
|
42
|
+
};
|
|
43
|
+
footer: {
|
|
44
|
+
flexDirection: "row";
|
|
45
|
+
alignItems: "center";
|
|
46
|
+
justifyContent: "flex-end";
|
|
47
|
+
marginTop: number;
|
|
48
|
+
};
|
|
49
|
+
title: {
|
|
50
|
+
color: any;
|
|
51
|
+
fontWeight: "500";
|
|
52
|
+
fontSize: number;
|
|
53
|
+
};
|
|
54
|
+
body: {
|
|
55
|
+
color: any;
|
|
56
|
+
fontSize: number;
|
|
57
|
+
marginTop: number;
|
|
58
|
+
marginBottom: number;
|
|
59
|
+
};
|
|
60
|
+
buttonLeft: {
|
|
61
|
+
margin: number;
|
|
62
|
+
flex: number;
|
|
63
|
+
backgroundColor: any;
|
|
64
|
+
justifyContent: "center";
|
|
65
|
+
alignItems: "center";
|
|
66
|
+
};
|
|
67
|
+
buttonRight: {
|
|
68
|
+
margin: number;
|
|
69
|
+
flex: number;
|
|
70
|
+
backgroundColor: any;
|
|
71
|
+
justifyContent: "center";
|
|
72
|
+
alignItems: "center";
|
|
73
|
+
};
|
|
74
|
+
textButtonLeft: {
|
|
75
|
+
color: any;
|
|
76
|
+
textAlign: "center";
|
|
77
|
+
backgroundColor: string;
|
|
78
|
+
padding: number;
|
|
79
|
+
fontSize: number;
|
|
80
|
+
};
|
|
81
|
+
textButtonRight: {
|
|
82
|
+
color: any;
|
|
83
|
+
textAlign: "center";
|
|
84
|
+
backgroundColor: string;
|
|
85
|
+
padding: number;
|
|
86
|
+
fontSize: number;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
export const buildStyles = (data, screen) => StyleSheet.create({
|
|
3
|
+
closeButton: {
|
|
4
|
+
width: 30,
|
|
5
|
+
height: 30,
|
|
6
|
+
justifyContent: 'center',
|
|
7
|
+
alignItems: 'center',
|
|
8
|
+
backgroundColor: 'transparent',
|
|
9
|
+
borderRadius: 25,
|
|
10
|
+
shadowOffset: { width: 0, height: 2 },
|
|
11
|
+
shadowOpacity: 0.2,
|
|
12
|
+
shadowRadius: 4,
|
|
13
|
+
position: 'absolute',
|
|
14
|
+
top: 10,
|
|
15
|
+
right: 10,
|
|
16
|
+
zIndex: 10,
|
|
17
|
+
},
|
|
18
|
+
textButton: {
|
|
19
|
+
color: '#000',
|
|
20
|
+
fontSize: 16,
|
|
21
|
+
fontWeight: 'bold',
|
|
22
|
+
},
|
|
23
|
+
content: {
|
|
24
|
+
backgroundColor: data?.background_color,
|
|
25
|
+
flexDirection: "column",
|
|
26
|
+
borderRadius: 20,
|
|
27
|
+
paddingBottom: 16,
|
|
28
|
+
paddingRight: 16,
|
|
29
|
+
paddingLeft: 16,
|
|
30
|
+
margin: 16,
|
|
31
|
+
overflow: "hidden",
|
|
32
|
+
elevation: 10,
|
|
33
|
+
width: screen,
|
|
34
|
+
alignItems: "center"
|
|
35
|
+
},
|
|
36
|
+
messageData: {
|
|
37
|
+
marginTop: 12,
|
|
38
|
+
alignItems: "center",
|
|
39
|
+
justifyContent: "center",
|
|
40
|
+
},
|
|
41
|
+
footer: {
|
|
42
|
+
flexDirection: "row",
|
|
43
|
+
alignItems: "center",
|
|
44
|
+
justifyContent: "flex-end",
|
|
45
|
+
marginTop: 4,
|
|
46
|
+
},
|
|
47
|
+
title: {
|
|
48
|
+
color: data?.title_font_color,
|
|
49
|
+
fontWeight: "500",
|
|
50
|
+
fontSize: 18,
|
|
51
|
+
},
|
|
52
|
+
body: {
|
|
53
|
+
color: data?.body_font_color,
|
|
54
|
+
fontSize: 16,
|
|
55
|
+
marginTop: 10,
|
|
56
|
+
marginBottom: 10,
|
|
57
|
+
},
|
|
58
|
+
buttonLeft: {
|
|
59
|
+
margin: 2,
|
|
60
|
+
flex: 1,
|
|
61
|
+
backgroundColor: data?.btn_left_bg_color,
|
|
62
|
+
justifyContent: "center",
|
|
63
|
+
alignItems: "center",
|
|
64
|
+
},
|
|
65
|
+
buttonRight: {
|
|
66
|
+
margin: 2,
|
|
67
|
+
flex: 1,
|
|
68
|
+
backgroundColor: data?.btn_right_bg_color,
|
|
69
|
+
justifyContent: "center",
|
|
70
|
+
alignItems: "center",
|
|
71
|
+
},
|
|
72
|
+
textButtonLeft: {
|
|
73
|
+
color: data?.btn_left_txt_color,
|
|
74
|
+
textAlign: "center",
|
|
75
|
+
backgroundColor: "transparent",
|
|
76
|
+
padding: 8,
|
|
77
|
+
fontSize: 14,
|
|
78
|
+
},
|
|
79
|
+
textButtonRight: {
|
|
80
|
+
color: data?.btn_right_txt_color,
|
|
81
|
+
textAlign: "center",
|
|
82
|
+
backgroundColor: "transparent",
|
|
83
|
+
padding: 8,
|
|
84
|
+
fontSize: 14,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const messagingHeadlessTask: () => void;
|
|
2
|
+
export declare const useInAppHandler: () => {
|
|
3
|
+
showInApp: boolean;
|
|
4
|
+
setShowInApp: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
5
|
+
};
|
|
6
|
+
export declare const InngageNotificationMessage: (firebaseListenCallback?: (data: Record<string, string>) => void) => void;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { AppState, Linking, Platform } from 'react-native';
|
|
3
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
4
|
+
import { getApp } from '@react-native-firebase/app';
|
|
5
|
+
import { getMessaging, setBackgroundMessageHandler, onMessage, onNotificationOpenedApp, getInitialNotification, } from '@react-native-firebase/messaging';
|
|
6
|
+
import InAppBrowser from 'react-native-inappbrowser-reborn';
|
|
7
|
+
import { InngageProperties } from '../models/inngage_properties';
|
|
8
|
+
import * as ApiService from '../services/api_services';
|
|
9
|
+
import notifee, { EventType } from '@notifee/react-native';
|
|
10
|
+
const ANDROID_CHANNEL_ID = 'inngage_default';
|
|
11
|
+
async function ensureAndroidChannel() {
|
|
12
|
+
if (!notifee || Platform.OS !== 'android')
|
|
13
|
+
return;
|
|
14
|
+
await notifee.createChannel({ id: ANDROID_CHANNEL_ID, name: 'Inngage' });
|
|
15
|
+
}
|
|
16
|
+
const toStringValue = (v) => typeof v === 'string' ? v : JSON.stringify(v ?? '');
|
|
17
|
+
const app = getApp();
|
|
18
|
+
const messagingInstance = getMessaging(app);
|
|
19
|
+
export const messagingHeadlessTask = () => {
|
|
20
|
+
return setBackgroundMessageHandler(messagingInstance, async (remoteMessage) => {
|
|
21
|
+
if (InngageProperties.getDebugMode()) {
|
|
22
|
+
console.log('INNGAGE BACKGROUND AND CLOSED DATA: ', remoteMessage);
|
|
23
|
+
}
|
|
24
|
+
const additional = remoteMessage?.data?.additional_data;
|
|
25
|
+
if (additional != null) {
|
|
26
|
+
await AsyncStorage.setItem('inapp', toStringValue(additional));
|
|
27
|
+
}
|
|
28
|
+
return Promise.resolve();
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
export const useInAppHandler = () => {
|
|
32
|
+
const [showInApp, setShowInApp] = useState(false);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const checkInAppData = async () => {
|
|
35
|
+
const inAppData = await AsyncStorage.getItem('inapp');
|
|
36
|
+
if (inAppData)
|
|
37
|
+
setShowInApp(true);
|
|
38
|
+
};
|
|
39
|
+
checkInAppData();
|
|
40
|
+
const subscription = AppState.addEventListener('change', (next) => {
|
|
41
|
+
if (next === 'active')
|
|
42
|
+
checkInAppData();
|
|
43
|
+
});
|
|
44
|
+
return () => subscription.remove();
|
|
45
|
+
}, []);
|
|
46
|
+
return { showInApp, setShowInApp };
|
|
47
|
+
};
|
|
48
|
+
export const InngageNotificationMessage = (firebaseListenCallback) => {
|
|
49
|
+
const [notificationMessage, setNotificationMessage] = useState(null);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
const handleMessage = async (remoteMessage) => {
|
|
52
|
+
const notificationData = remoteMessage.data ?? {};
|
|
53
|
+
if (notificationData.additional_data != null) {
|
|
54
|
+
await AsyncStorage.setItem('inapp', toStringValue(notificationData.additional_data));
|
|
55
|
+
}
|
|
56
|
+
if (notifee) {
|
|
57
|
+
const title = remoteMessage.notification?.title ?? notificationData.title ?? '';
|
|
58
|
+
const body = remoteMessage.notification?.body ?? notificationData.body ?? '';
|
|
59
|
+
await notifee.displayNotification({
|
|
60
|
+
title,
|
|
61
|
+
body,
|
|
62
|
+
android: Platform.OS === 'android' ? { channelId: ANDROID_CHANNEL_ID } : undefined,
|
|
63
|
+
ios: Platform.OS === 'ios'
|
|
64
|
+
? { foregroundPresentationOptions: { banner: true, list: true, sound: true } }
|
|
65
|
+
: undefined,
|
|
66
|
+
});
|
|
67
|
+
return notifee.onForegroundEvent(({ type, detail }) => {
|
|
68
|
+
switch (type) {
|
|
69
|
+
case EventType.DISMISSED:
|
|
70
|
+
if (InngageProperties.getDebugMode()) {
|
|
71
|
+
console.log('User dismissed notification', detail.notification);
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
case EventType.PRESS:
|
|
75
|
+
handleNotification(remoteMessage);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
if (InngageProperties.getDebugMode()) {
|
|
82
|
+
console.log('[SDK] Notifee não instalado; mensagem em foreground: ', remoteMessage);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (InngageProperties.getDebugMode()) {
|
|
86
|
+
console.log('Remote message received in foreground: ', remoteMessage);
|
|
87
|
+
}
|
|
88
|
+
if (firebaseListenCallback && remoteMessage) {
|
|
89
|
+
firebaseListenCallback(notificationData);
|
|
90
|
+
}
|
|
91
|
+
setNotificationMessage(remoteMessage);
|
|
92
|
+
};
|
|
93
|
+
ensureAndroidChannel().catch(() => { });
|
|
94
|
+
const unsubscribe = onMessage(messagingInstance, handleMessage);
|
|
95
|
+
return unsubscribe;
|
|
96
|
+
}, [firebaseListenCallback]);
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
const unsubscribe = onNotificationOpenedApp(messagingInstance, (remoteMessage) => {
|
|
99
|
+
if (!remoteMessage)
|
|
100
|
+
return;
|
|
101
|
+
firebaseListenCallback?.(remoteMessage.data ?? {});
|
|
102
|
+
handleNotification(remoteMessage);
|
|
103
|
+
});
|
|
104
|
+
return unsubscribe;
|
|
105
|
+
}, [firebaseListenCallback]);
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
let mounted = true;
|
|
108
|
+
getInitialNotification(messagingInstance)
|
|
109
|
+
.then(async (value) => {
|
|
110
|
+
if (!mounted || !value)
|
|
111
|
+
return;
|
|
112
|
+
await handleUniqueRemoteMessage(value);
|
|
113
|
+
})
|
|
114
|
+
.catch((e) => console.error(e));
|
|
115
|
+
return () => {
|
|
116
|
+
mounted = false;
|
|
117
|
+
};
|
|
118
|
+
}, []);
|
|
119
|
+
const handleUniqueRemoteMessage = async (remoteMessage) => {
|
|
120
|
+
try {
|
|
121
|
+
const lastId = await AsyncStorage.getItem('LAST_REMOTE_MESSAGE_ID');
|
|
122
|
+
const newId = remoteMessage?.messageId;
|
|
123
|
+
if (newId && lastId !== newId) {
|
|
124
|
+
await AsyncStorage.setItem('LAST_REMOTE_MESSAGE_ID', newId);
|
|
125
|
+
handleNotification(remoteMessage);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
console.error(e);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
async function handleNotification(remoteMessage) {
|
|
133
|
+
const data = remoteMessage?.data ?? {};
|
|
134
|
+
const notId = data?.notId;
|
|
135
|
+
const request = {
|
|
136
|
+
notificationRequest: {
|
|
137
|
+
app_token: InngageProperties.appToken,
|
|
138
|
+
id: notId,
|
|
139
|
+
notId: notId
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
const url = data?.url;
|
|
143
|
+
const type = data?.type;
|
|
144
|
+
if (url) {
|
|
145
|
+
if (type === 'inapp') {
|
|
146
|
+
try {
|
|
147
|
+
if (await InAppBrowser.isAvailable()) {
|
|
148
|
+
await InAppBrowser.open(url, {
|
|
149
|
+
dismissButtonStyle: 'close',
|
|
150
|
+
preferredBarTintColor: '#453AA4',
|
|
151
|
+
preferredControlTintColor: 'white',
|
|
152
|
+
enableDefaultShare: true,
|
|
153
|
+
enableBarCollapsing: true,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
Linking.openURL(url);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
console.error(error);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else if (type === 'deep') {
|
|
165
|
+
Linking.openURL(url).catch((err) => console.error('Erro ao abrir o link:', err));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
await ApiService.sendNotification(request);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import { InApp } from './components/in_app';
|
|
2
|
-
import { useInAppHandler, messagingHeadlessTask } from './firebase/notifications_listener'
|
|
3
|
-
import Inngage from './Inngage';
|
|
4
|
-
|
|
5
|
-
export {
|
|
6
|
-
export
|
|
7
|
-
export default Inngage;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { InApp } from './components/in_app';
|
|
2
|
+
import { useInAppHandler, messagingHeadlessTask } from './firebase/notifications_listener';
|
|
3
|
+
import Inngage from './Inngage';
|
|
4
|
+
export { InApp };
|
|
5
|
+
export { useInAppHandler, messagingHeadlessTask };
|
|
6
|
+
export default Inngage;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { InApp } from './components/in_app';
|
|
2
|
+
import { useInAppHandler, messagingHeadlessTask } from './firebase/notifications_listener';
|
|
3
|
+
import Inngage from './Inngage';
|
|
4
|
+
export { InApp };
|
|
5
|
+
export { useInAppHandler, messagingHeadlessTask };
|
|
6
|
+
export default Inngage;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class InngageProperties {
|
|
2
|
+
static identifier: string;
|
|
3
|
+
static appToken: string;
|
|
4
|
+
static phoneNumber: string;
|
|
5
|
+
static email: string;
|
|
6
|
+
static customFields: any;
|
|
7
|
+
static blockDeepLink: boolean;
|
|
8
|
+
static debugMode: boolean;
|
|
9
|
+
static firebaseToken: string;
|
|
10
|
+
static getDebugMode(): boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export class InngageProperties {
|
|
2
|
+
static getDebugMode() {
|
|
3
|
+
return InngageProperties.debugMode;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
InngageProperties.identifier = '';
|
|
7
|
+
InngageProperties.appToken = '';
|
|
8
|
+
InngageProperties.phoneNumber = '';
|
|
9
|
+
InngageProperties.email = '';
|
|
10
|
+
InngageProperties.customFields = {};
|
|
11
|
+
InngageProperties.blockDeepLink = false;
|
|
12
|
+
InngageProperties.debugMode = false;
|
|
13
|
+
InngageProperties.firebaseToken = '';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare const SUBSCRIBE_REQUEST: {
|
|
2
|
+
registerSubscriberRequest: {
|
|
3
|
+
appToken: string;
|
|
4
|
+
identifier: string;
|
|
5
|
+
registration: string;
|
|
6
|
+
platform: string;
|
|
7
|
+
sdk: string;
|
|
8
|
+
deviceModel: string;
|
|
9
|
+
deviceManufacturer: string;
|
|
10
|
+
osLocale: string;
|
|
11
|
+
osLanguage: string;
|
|
12
|
+
osVersion: string;
|
|
13
|
+
appVersion: string;
|
|
14
|
+
appInstalledIn: string;
|
|
15
|
+
appUpdatedIn: string;
|
|
16
|
+
uuid: string;
|
|
17
|
+
phoneNumber: string;
|
|
18
|
+
email: string;
|
|
19
|
+
customFields: {};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export declare const EVENT_REQUEST: {
|
|
23
|
+
newEventRequest: {
|
|
24
|
+
appToken: string;
|
|
25
|
+
identifier: string;
|
|
26
|
+
registration: string;
|
|
27
|
+
eventName: string;
|
|
28
|
+
conversionEvent: boolean;
|
|
29
|
+
conversionValue: number;
|
|
30
|
+
conversionNotId: string;
|
|
31
|
+
eventValues: {};
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export declare const USER_DATA_REQUEST: {
|
|
35
|
+
fieldsRequest: {
|
|
36
|
+
appToken: string;
|
|
37
|
+
identifier: string;
|
|
38
|
+
customField: {};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -1,42 +1,40 @@
|
|
|
1
|
-
export const SUBSCRIBE_REQUEST = {
|
|
2
|
-
registerSubscriberRequest: {
|
|
3
|
-
appToken: '',
|
|
4
|
-
identifier: '',
|
|
5
|
-
registration: '',
|
|
6
|
-
platform: '',
|
|
7
|
-
sdk: '',
|
|
8
|
-
deviceModel: '',
|
|
9
|
-
deviceManufacturer: '',
|
|
10
|
-
osLocale: '',
|
|
11
|
-
osLanguage: '',
|
|
12
|
-
osVersion: '',
|
|
13
|
-
appVersion: '',
|
|
14
|
-
appInstalledIn: '',
|
|
15
|
-
appUpdatedIn: '',
|
|
16
|
-
uuid: '',
|
|
17
|
-
phoneNumber: '',
|
|
18
|
-
email: '',
|
|
19
|
-
customFields: {},
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
},
|
|
42
|
-
};
|
|
1
|
+
export const SUBSCRIBE_REQUEST = {
|
|
2
|
+
registerSubscriberRequest: {
|
|
3
|
+
appToken: '',
|
|
4
|
+
identifier: '',
|
|
5
|
+
registration: '',
|
|
6
|
+
platform: '',
|
|
7
|
+
sdk: '',
|
|
8
|
+
deviceModel: '',
|
|
9
|
+
deviceManufacturer: '',
|
|
10
|
+
osLocale: '',
|
|
11
|
+
osLanguage: '',
|
|
12
|
+
osVersion: '',
|
|
13
|
+
appVersion: '',
|
|
14
|
+
appInstalledIn: '',
|
|
15
|
+
appUpdatedIn: '',
|
|
16
|
+
uuid: '',
|
|
17
|
+
phoneNumber: '',
|
|
18
|
+
email: '',
|
|
19
|
+
customFields: {},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export const EVENT_REQUEST = {
|
|
23
|
+
newEventRequest: {
|
|
24
|
+
appToken: '',
|
|
25
|
+
identifier: '',
|
|
26
|
+
registration: '',
|
|
27
|
+
eventName: '',
|
|
28
|
+
conversionEvent: false,
|
|
29
|
+
conversionValue: 0,
|
|
30
|
+
conversionNotId: '',
|
|
31
|
+
eventValues: {},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
export const USER_DATA_REQUEST = {
|
|
35
|
+
fieldsRequest: {
|
|
36
|
+
appToken: '',
|
|
37
|
+
identifier: '',
|
|
38
|
+
customField: {},
|
|
39
|
+
},
|
|
40
|
+
};
|