@inngageregistry/inngage-react 2.3.3 → 3.0.2
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/.editorconfig +6 -6
- package/package.json +27 -5
- package/src/Inngage.ts +193 -0
- package/src/components/Inapp.tsx +318 -0
- package/src/components/styles.ts +97 -0
- package/src/index.d.ts +1 -0
- package/src/index.ts +8 -0
- package/{ListenToNotifications.js → src/notificationsListener.ts} +64 -65
- package/src/services/handler.ts +42 -0
- package/src/services/inngage.ts +17 -0
- package/src/utils.ts +51 -0
- package/tsconfig.json +24 -0
- package/index.js +0 -555
- package/inngageApi.js +0 -5
- package/utils.js +0 -84
package/.editorconfig
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
[*]
|
|
2
|
-
end_of_line = lf
|
|
3
|
-
insert_final_newline = true
|
|
4
|
-
charset = utf-8
|
|
5
|
-
indent_style = space
|
|
6
|
-
indent_size = 2
|
|
1
|
+
[*]
|
|
2
|
+
end_of_line = lf
|
|
3
|
+
insert_final_newline = true
|
|
4
|
+
charset = utf-8
|
|
5
|
+
indent_style = space
|
|
6
|
+
indent_size = 2
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inngageregistry/inngage-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "Inngage react integration",
|
|
5
|
-
"main": "index.
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"types": "src/index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
+
"build": "npx tsc"
|
|
8
10
|
},
|
|
9
|
-
"author": "
|
|
11
|
+
"author": "Inngage Developer",
|
|
10
12
|
"license": "ISC",
|
|
11
13
|
"repository": {
|
|
12
14
|
"type": "git",
|
|
@@ -16,5 +18,25 @@
|
|
|
16
18
|
"url": "https://github.com/inngage/inngage-react/issues"
|
|
17
19
|
},
|
|
18
20
|
"homepage": "https://github.com/inngage/inngage-react#readme",
|
|
19
|
-
"dependencies": {
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@react-native-async-storage/async-storage": "^1.16.1",
|
|
23
|
+
"@react-native-community/push-notification-ios": "^1.10.1",
|
|
24
|
+
"@react-native-firebase/app": "^14.11.0",
|
|
25
|
+
"@react-native-firebase/messaging": "^14.11.0",
|
|
26
|
+
"react-native-advertising-id": "^1.0.11",
|
|
27
|
+
"react-native-device-info": "^8.4.9",
|
|
28
|
+
"react-native-inappbrowser-reborn": "^3.6.3",
|
|
29
|
+
"react-native-localize": "^2.2.2",
|
|
30
|
+
"react-native-push-notification": "^8.1.1",
|
|
31
|
+
"react-native-snap-carousel": "^3.9.1"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/jest": "^27.4.0",
|
|
35
|
+
"@types/react": "^17.0.38",
|
|
36
|
+
"@types/react-native": "^0.66.15",
|
|
37
|
+
"@types/react-native-push-notification": "^8.1.0",
|
|
38
|
+
"@types/react-native-snap-carousel": "^3.8.5",
|
|
39
|
+
"@types/react-test-renderer": "^17.0.1",
|
|
40
|
+
"typescript": "^4.5.5"
|
|
41
|
+
}
|
|
20
42
|
}
|
package/src/Inngage.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Platform,
|
|
3
|
+
LogBox,
|
|
4
|
+
AppRegistry,
|
|
5
|
+
} from "react-native";
|
|
6
|
+
|
|
7
|
+
import { firebase } from '@react-native-firebase/messaging';
|
|
8
|
+
import DeviceInfo from "react-native-device-info";
|
|
9
|
+
import * as RNLocalize from "react-native-localize";
|
|
10
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
11
|
+
|
|
12
|
+
import { formatDate, subscriptionRequestAdapter } from "./utils";
|
|
13
|
+
import notificationsListener, { notificationsListenerProps } from "./notificationsListener";
|
|
14
|
+
import { subscriptionApi, eventsApi } from "./services/inngage";
|
|
15
|
+
import RNAdvertisingId from 'react-native-advertising-id';
|
|
16
|
+
|
|
17
|
+
// --- handle background message ------/
|
|
18
|
+
const backgroundNotificationHandler = async remoteMessage => {
|
|
19
|
+
var messageArray: any = [];
|
|
20
|
+
console.log("Remote message:", JSON.stringify(remoteMessage));
|
|
21
|
+
|
|
22
|
+
console.log('Called backgroundNotificationHandler');
|
|
23
|
+
|
|
24
|
+
const currentMessages = await AsyncStorage.getItem('messages');
|
|
25
|
+
if (currentMessages !== null) {
|
|
26
|
+
messageArray = JSON.parse(currentMessages);
|
|
27
|
+
}
|
|
28
|
+
messageArray.push(remoteMessage);
|
|
29
|
+
|
|
30
|
+
await AsyncStorage.setItem('messages', JSON.stringify(messageArray));
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// --- Get Firebase Access ------/
|
|
34
|
+
const getFirebaseAccess = () => {
|
|
35
|
+
let firebaseToken = 'W7SAl94Jk6l3w95W9wCgmv3zZ99V5FReNUytdgJUFUvpvZoqXf72'
|
|
36
|
+
return new Promise(async (resolve) => {
|
|
37
|
+
DeviceInfo.isEmulator().then(isEmulator => {
|
|
38
|
+
if (isEmulator && Platform.OS === "ios") {
|
|
39
|
+
return resolve(firebaseToken)
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
try {
|
|
43
|
+
if (!firebase.messaging().isDeviceRegisteredForRemoteMessages)
|
|
44
|
+
await firebase.messaging().registerDeviceForRemoteMessages();
|
|
45
|
+
|
|
46
|
+
const permission = await firebase.messaging().hasPermission();
|
|
47
|
+
if (permission === firebase.messaging.AuthorizationStatus.NOT_DETERMINED) {
|
|
48
|
+
try {
|
|
49
|
+
await firebase.messaging().requestPermission();
|
|
50
|
+
} catch (e) {
|
|
51
|
+
console.error(e)
|
|
52
|
+
return resolve(firebaseToken);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
firebaseToken = await firebase.messaging().getToken();
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error(error)
|
|
59
|
+
return resolve(firebaseToken)
|
|
60
|
+
}
|
|
61
|
+
return resolve(firebaseToken)
|
|
62
|
+
} catch (err) {
|
|
63
|
+
console.error(err)
|
|
64
|
+
return resolve(firebaseToken)
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
interface SubscriptionProps {
|
|
70
|
+
appToken: string,
|
|
71
|
+
enableAlert: boolean,
|
|
72
|
+
authKey: string,
|
|
73
|
+
dev?: boolean,
|
|
74
|
+
friendlyIdentifier?: string,
|
|
75
|
+
customFields?: any,
|
|
76
|
+
customData?: any,
|
|
77
|
+
phoneNumber?: string
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface SendEventProps {
|
|
81
|
+
newEventRequest: {
|
|
82
|
+
app_token: string,
|
|
83
|
+
identifier: string,
|
|
84
|
+
event_name: string,
|
|
85
|
+
conversion_event: boolean,
|
|
86
|
+
conversion_value: number,
|
|
87
|
+
conversion_notid: string,
|
|
88
|
+
event_values: {
|
|
89
|
+
nome_promo: string,
|
|
90
|
+
categoria: string,
|
|
91
|
+
foto_promo: string,
|
|
92
|
+
redirect_link: string
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
authKey: string
|
|
96
|
+
}
|
|
97
|
+
const Inngage = {
|
|
98
|
+
// ------------ Register Notification Listener ------------//
|
|
99
|
+
RegisterNotificationListener: async (props: notificationsListenerProps) => {
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
LogBox.ignoreLogs(['registerHeadlessTask'])
|
|
103
|
+
} catch (e) { }
|
|
104
|
+
try {
|
|
105
|
+
console.ignoredYellowBox = ['registerHeadlessTask'];
|
|
106
|
+
} catch (e) { }
|
|
107
|
+
try {
|
|
108
|
+
AppRegistry.registerHeadlessTask('ReactNativeFirebaseMessagingHeadlessTask', () => backgroundNotificationHandler)
|
|
109
|
+
notificationsListener({ ...props });
|
|
110
|
+
} catch (e) {
|
|
111
|
+
console.error(e);
|
|
112
|
+
return { subscribed: false };
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
Subscribe: async ({
|
|
116
|
+
appToken,
|
|
117
|
+
dev,
|
|
118
|
+
friendlyIdentifier,
|
|
119
|
+
customFields,
|
|
120
|
+
customData,
|
|
121
|
+
phoneNumber,
|
|
122
|
+
authKey
|
|
123
|
+
}: SubscriptionProps) => {
|
|
124
|
+
try {
|
|
125
|
+
const respToken = await getFirebaseAccess()
|
|
126
|
+
|
|
127
|
+
const locales = RNLocalize.getLocales();
|
|
128
|
+
|
|
129
|
+
const os_language = locales && locales.length ? locales[0].languageCode : ''
|
|
130
|
+
const device_manufacturer = await DeviceInfo.getManufacturer();
|
|
131
|
+
const installTime = await DeviceInfo.getFirstInstallTime();
|
|
132
|
+
const lastUpdateTime = await DeviceInfo.getLastUpdateTime();
|
|
133
|
+
const app_installed_in = formatDate(installTime);
|
|
134
|
+
const app_updated_in = formatDate(lastUpdateTime);
|
|
135
|
+
const androidId = DeviceInfo.getAndroidId();
|
|
136
|
+
var advertiserId = "Unknown"
|
|
137
|
+
var idFa = "Unknown"
|
|
138
|
+
try{
|
|
139
|
+
const rnAdvertisingId = await RNAdvertisingId.getAdvertisingId();
|
|
140
|
+
advertiserId = rnAdvertisingId.advertisingId;
|
|
141
|
+
idFa = rnAdvertisingId.advertisingId;
|
|
142
|
+
}catch(e){
|
|
143
|
+
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
const rawRequest = {
|
|
148
|
+
registerSubscriberRequest: {
|
|
149
|
+
app_token: appToken,
|
|
150
|
+
identifier: friendlyIdentifier,
|
|
151
|
+
registration: respToken,
|
|
152
|
+
phone_Number: phoneNumber,
|
|
153
|
+
platform: DeviceInfo.getSystemName(),
|
|
154
|
+
sdk: DeviceInfo.getBuildNumber(),
|
|
155
|
+
device_model: DeviceInfo.getModel(),
|
|
156
|
+
device_manufacturer,
|
|
157
|
+
os_locale: RNLocalize.getCountry(),
|
|
158
|
+
os_language,
|
|
159
|
+
os_version: DeviceInfo.getReadableVersion(),
|
|
160
|
+
app_version: DeviceInfo.getBuildNumber(),
|
|
161
|
+
app_installed_in,
|
|
162
|
+
app_updated_in,
|
|
163
|
+
uuid: DeviceInfo.getUniqueId(),
|
|
164
|
+
advertiser_id:advertiserId,
|
|
165
|
+
android_id:androidId,
|
|
166
|
+
idfa:idFa,
|
|
167
|
+
authKey,
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const request = subscriptionRequestAdapter(rawRequest, customData, customFields)
|
|
172
|
+
const subscribe = await subscriptionApi(request, dev);
|
|
173
|
+
console.log(await subscribe.json())
|
|
174
|
+
return subscribe;
|
|
175
|
+
} catch (e) {
|
|
176
|
+
console.error(e);
|
|
177
|
+
return { subscribed: false };
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
SendEvent: async (props: SendEventProps) => {
|
|
181
|
+
const { authKey, newEventRequest } = props
|
|
182
|
+
const rawRequest = {
|
|
183
|
+
registerSubscriberRequest: {
|
|
184
|
+
authKey
|
|
185
|
+
},
|
|
186
|
+
newEventRequest
|
|
187
|
+
}
|
|
188
|
+
const subscribe = await eventsApi(rawRequest);
|
|
189
|
+
return subscribe
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export default Inngage;
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import React, { useState, useEffect, useRef } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Modal,
|
|
4
|
+
View,
|
|
5
|
+
Text,
|
|
6
|
+
TouchableHighlight,
|
|
7
|
+
TouchableOpacity,
|
|
8
|
+
Image,
|
|
9
|
+
ScrollView,
|
|
10
|
+
ImageBackground,
|
|
11
|
+
Linking,
|
|
12
|
+
Dimensions,
|
|
13
|
+
} from "react-native";
|
|
14
|
+
import DeviceInfo from "react-native-device-info";
|
|
15
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
16
|
+
import Carousel, { Pagination } from 'react-native-snap-carousel';
|
|
17
|
+
|
|
18
|
+
import { showAlertLink, isEmpty } from "../utils";
|
|
19
|
+
import { linkInApp } from "../notificationsListener";
|
|
20
|
+
import { styleInapp, styleItem } from './styles';
|
|
21
|
+
|
|
22
|
+
const SLIDER_WIDTH = Dimensions.get('window').width;
|
|
23
|
+
const SLIDER_HEIGHT = Dimensions.get('window').height;
|
|
24
|
+
const ITEM_WIDTH = Math.round(SLIDER_WIDTH * 0.8);
|
|
25
|
+
const ITEM_HEIGHT = Math.round(SLIDER_HEIGHT * 0.8);
|
|
26
|
+
|
|
27
|
+
export interface InappProps {
|
|
28
|
+
mediaStyle?: any;
|
|
29
|
+
titleStyle?: any;
|
|
30
|
+
bodyStyle?: any;
|
|
31
|
+
buttonLeftStyle?: any;
|
|
32
|
+
buttonRightStyle?: any;
|
|
33
|
+
buttonTitleLeftStyle?: any;
|
|
34
|
+
buttonTitleRightStyle?: any;
|
|
35
|
+
styleContainer?: any;
|
|
36
|
+
onClose?: 'clear';
|
|
37
|
+
}
|
|
38
|
+
export const Inapp = (props: InappProps) => {
|
|
39
|
+
const [data, setData] = useState<any>([])
|
|
40
|
+
const [indIm, setIndImg] = useState(0)
|
|
41
|
+
const [visible, setVisible] = useState(true)
|
|
42
|
+
const [bgImage, setbgImage] = useState<any>(undefined) // TODO, need a placeholder
|
|
43
|
+
|
|
44
|
+
const CarouselRef = useRef<Carousel<any>>(null);
|
|
45
|
+
const ScrollRef1 = useRef<ScrollView>(null);
|
|
46
|
+
const ScrollRef2 = useRef<ScrollView>(null);
|
|
47
|
+
const ScrollRef3 = useRef<ScrollView>(null);
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
interface _renderItemProps {
|
|
51
|
+
item: any;
|
|
52
|
+
index: number;
|
|
53
|
+
}
|
|
54
|
+
const _renderItem = ({ item, index }: _renderItemProps) => {
|
|
55
|
+
let msg = JSON.parse(item.data.additional_data)
|
|
56
|
+
let arrayImgs: any = []
|
|
57
|
+
let indImg = 0
|
|
58
|
+
|
|
59
|
+
const checkBG = () => {
|
|
60
|
+
if (msg.background_img != '') {
|
|
61
|
+
return null
|
|
62
|
+
} else {
|
|
63
|
+
return msg.background_color
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const itemStyles = styleItem({msg, checkBG})
|
|
68
|
+
|
|
69
|
+
const chooseRef = () => {
|
|
70
|
+
if (index == 0) {
|
|
71
|
+
return ScrollRef1
|
|
72
|
+
}
|
|
73
|
+
if (index == 1) {
|
|
74
|
+
return ScrollRef2
|
|
75
|
+
}
|
|
76
|
+
if (index == 2) {
|
|
77
|
+
return ScrollRef3
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
const pagination = ref => {
|
|
83
|
+
return (
|
|
84
|
+
<Pagination
|
|
85
|
+
dotsLength={arrayImgs.length}
|
|
86
|
+
activeDotIndex={indIm}
|
|
87
|
+
containerStyle={{ height: 2, padding: 0, margin: 0 }}
|
|
88
|
+
renderDots={(activeIndex, total, context) => {
|
|
89
|
+
let dots: any = []
|
|
90
|
+
var size = 0
|
|
91
|
+
for (let i = 0; i < total; i++) {
|
|
92
|
+
if (activeIndex == i) {
|
|
93
|
+
size = 13
|
|
94
|
+
} else {
|
|
95
|
+
size = 8
|
|
96
|
+
}
|
|
97
|
+
dots.push(
|
|
98
|
+
<TouchableOpacity
|
|
99
|
+
onPress={() => {
|
|
100
|
+
ref.current.scrollTo({ x: i * 220, y: 0, animated: true })
|
|
101
|
+
if (i * 220 === 0) {
|
|
102
|
+
setIndImg(0)
|
|
103
|
+
} else if (i * 220 === 220) {
|
|
104
|
+
setIndImg(1)
|
|
105
|
+
} else if (i * 220 === 440) {
|
|
106
|
+
setIndImg(2)
|
|
107
|
+
}
|
|
108
|
+
}}
|
|
109
|
+
key={i.toString()}
|
|
110
|
+
style={[itemStyles.dot, { width: size, height: size }]}
|
|
111
|
+
/>
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
return (
|
|
115
|
+
dots
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const handleButton = (title: string, body: string, url: string, type: string) => {
|
|
124
|
+
if (type === '' || url === '') {
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
console.log(title, body, url, type)
|
|
128
|
+
const openLinkByType = (type, url) => (type === 'deep' ? Linking.openURL(url) : linkInApp(url))
|
|
129
|
+
|
|
130
|
+
return Linking.canOpenURL(url).then((supported) => {
|
|
131
|
+
if (supported) {
|
|
132
|
+
showAlertLink(
|
|
133
|
+
title,
|
|
134
|
+
body,
|
|
135
|
+
`${DeviceInfo.getApplicationName()}`,
|
|
136
|
+
`Acessar ${url} ?`,
|
|
137
|
+
).then(() => { supported && openLinkByType(type, url) })
|
|
138
|
+
}
|
|
139
|
+
}).catch(console.error)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const imgCarosel = () => {
|
|
143
|
+
if (msg.rich_content.carousel == true) {
|
|
144
|
+
if (msg.rich_content.img1 != '') {
|
|
145
|
+
arrayImgs.push({ url: msg.rich_content.img1 })
|
|
146
|
+
}
|
|
147
|
+
if (msg.rich_content.img2 != '') {
|
|
148
|
+
arrayImgs.push({ url: msg.rich_content.img2 })
|
|
149
|
+
}
|
|
150
|
+
if (msg.rich_content.img3 != '') {
|
|
151
|
+
arrayImgs.push({ url: msg.rich_content.img3 })
|
|
152
|
+
}
|
|
153
|
+
let arrayElements = arrayImgs.map((item, index) => (
|
|
154
|
+
<Image key={index.toString()} style={[props.mediaStyle, { width: 200, height: 200, marginRight: 10 }]} source={{ uri: item.url }} />
|
|
155
|
+
));
|
|
156
|
+
return arrayElements
|
|
157
|
+
} else if (arrayImgs.length <= 0) {
|
|
158
|
+
return (
|
|
159
|
+
<Image style={[props.mediaStyle, { width: 200, height: 200 }]} source={{ uri: item.data.picture }} />
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
return (
|
|
164
|
+
<Image style={[props.mediaStyle, { width: 200, height: 200 }]} source={{ uri: item.data.picture }} />
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return (
|
|
169
|
+
<View style={[itemStyles.body]}>
|
|
170
|
+
<Text style={[itemStyles.title, props.titleStyle]}>{msg.title}</Text>
|
|
171
|
+
<ScrollView
|
|
172
|
+
ref={chooseRef()}
|
|
173
|
+
horizontal
|
|
174
|
+
snapToInterval={220}
|
|
175
|
+
decelerationRate="fast"
|
|
176
|
+
showsHorizontalScrollIndicator={false}
|
|
177
|
+
style={{ width: 200, height: 240 }}
|
|
178
|
+
contentContainerStyle={{ alignItems: 'center', justifyContent: 'center' }}
|
|
179
|
+
onMomentumScrollEnd={(e) => {
|
|
180
|
+
if (Math.round(e.nativeEvent.contentOffset.x) === 0
|
|
181
|
+
) {
|
|
182
|
+
indImg = 0
|
|
183
|
+
setIndImg(indImg)
|
|
184
|
+
}
|
|
185
|
+
if (Math.round(e.nativeEvent.contentOffset.x) === 220
|
|
186
|
+
) {
|
|
187
|
+
indImg = 1
|
|
188
|
+
setIndImg(indImg)
|
|
189
|
+
}
|
|
190
|
+
if (Math.round(e.nativeEvent.contentOffset.x) === 430
|
|
191
|
+
) {
|
|
192
|
+
indImg = 2
|
|
193
|
+
setIndImg(indImg)
|
|
194
|
+
}
|
|
195
|
+
}}
|
|
196
|
+
>
|
|
197
|
+
{imgCarosel()}
|
|
198
|
+
</ScrollView>
|
|
199
|
+
{
|
|
200
|
+
msg.rich_content.carousel == true ?
|
|
201
|
+
pagination(chooseRef()) : null
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
<Text style={[itemStyles.bodyText, props.bodyStyle]}>{msg.body}</Text>
|
|
205
|
+
<View style={{ flexDirection: "row", marginBottom: 0, justifyContent: 'center' }}>
|
|
206
|
+
<TouchableOpacity onPress={() => handleButton(msg.title, msg.body, msg.btn_left_action_link, msg.btn_left_action_type)} style={[itemStyles.btn_left, props.buttonLeftStyle]}>
|
|
207
|
+
<View>
|
|
208
|
+
<Text style={[itemStyles.btn_left_title, props.buttonTitleLeftStyle]}>{msg.btn_left_txt}</Text>
|
|
209
|
+
</View>
|
|
210
|
+
</TouchableOpacity>
|
|
211
|
+
<TouchableOpacity onPress={() => handleButton(msg.title, msg.body, msg.btn_right_action_link, msg.btn_right_action_type)} style={[itemStyles.btn_right, props.buttonRightStyle]}>
|
|
212
|
+
<View>
|
|
213
|
+
<Text style={[itemStyles.btn_right_title, props.buttonTitleRightStyle]}>{msg.btn_right_txt}</Text>
|
|
214
|
+
</View>
|
|
215
|
+
</TouchableOpacity>
|
|
216
|
+
</View>
|
|
217
|
+
</View>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
useEffect(() => {
|
|
222
|
+
onLoad();
|
|
223
|
+
}, [])
|
|
224
|
+
|
|
225
|
+
const onLoad = async () => {
|
|
226
|
+
let temp: any = []
|
|
227
|
+
const messages = JSON.parse(await AsyncStorage.getItem('inngage') ?? '[]')
|
|
228
|
+
|
|
229
|
+
console.log("Messages saved on AsyncStorage: ", JSON.stringify(messages))
|
|
230
|
+
|
|
231
|
+
if (messages !== null) {
|
|
232
|
+
messages.forEach((el) => {
|
|
233
|
+
if (!isEmpty(el)) {
|
|
234
|
+
temp.push(el)
|
|
235
|
+
}
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
let msg: any = {}
|
|
239
|
+
if (temp.length > 0 && temp[0]?.data?.additional_data) {
|
|
240
|
+
msg = JSON.parse(temp[0].data.additional_data)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (msg.background_img != '') {
|
|
244
|
+
setbgImage({ uri: msg.background_img })
|
|
245
|
+
} else {
|
|
246
|
+
setbgImage(undefined)
|
|
247
|
+
}
|
|
248
|
+
setData(temp)
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const handleClose = async () => {
|
|
253
|
+
if (props.onClose) {
|
|
254
|
+
if (props.onClose.toLowerCase() === 'clear') {
|
|
255
|
+
await AsyncStorage.removeItem('inngage');
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
setVisible(false)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const handleBg = index => {
|
|
262
|
+
let msg = JSON.parse(data[index].data.additional_data)
|
|
263
|
+
if (msg.background_img != '') {
|
|
264
|
+
setbgImage({ uri: msg.background_img })
|
|
265
|
+
} else {
|
|
266
|
+
setbgImage(undefined)
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (data.length > 0) {
|
|
271
|
+
return (
|
|
272
|
+
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
|
|
273
|
+
<Modal
|
|
274
|
+
animationType='slide'
|
|
275
|
+
visible={visible}
|
|
276
|
+
transparent={true}
|
|
277
|
+
style={{ justifyContent: 'center', alignItems: 'center', backgroundColor: 'blue' }}
|
|
278
|
+
><View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
|
|
279
|
+
<View style={[styles.styleContainer, props.styleContainer]}>
|
|
280
|
+
<ImageBackground style={{ width: '100%', alignItems: 'center', justifyContent: 'center' }} resizeMode='cover' imageStyle={{ borderRadius: 10, alignSelf: 'stretch', height: 480 }} source={bgImage}>
|
|
281
|
+
<TouchableHighlight
|
|
282
|
+
onPress={() => handleClose()}
|
|
283
|
+
underlayColor='#cccccc'
|
|
284
|
+
style={styles.closeButton}
|
|
285
|
+
>
|
|
286
|
+
<Text style={{ fontWeight: 'bold', color: '#ffffff' }}>
|
|
287
|
+
X
|
|
288
|
+
</Text>
|
|
289
|
+
</TouchableHighlight>
|
|
290
|
+
<Carousel
|
|
291
|
+
vertical
|
|
292
|
+
ref={CarouselRef}
|
|
293
|
+
layout={'default'}
|
|
294
|
+
layoutCardOffset={10}
|
|
295
|
+
data={data}
|
|
296
|
+
inactiveSlideOpacity={0}
|
|
297
|
+
containerCustomStyle={styles.carouselContainer}
|
|
298
|
+
contentContainerCustomStyle={{ justifyContent: 'center' }}
|
|
299
|
+
inactiveSlideShift={0}
|
|
300
|
+
onSnapToItem={(index) => {
|
|
301
|
+
handleBg(index)
|
|
302
|
+
}}
|
|
303
|
+
renderItem={({ item, index }) => _renderItem({ item, index })}
|
|
304
|
+
sliderHeight={500}
|
|
305
|
+
itemHeight={500}
|
|
306
|
+
/>
|
|
307
|
+
</ImageBackground>
|
|
308
|
+
</View>
|
|
309
|
+
</View>
|
|
310
|
+
</Modal>
|
|
311
|
+
</View>
|
|
312
|
+
);
|
|
313
|
+
} else {
|
|
314
|
+
return null
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const styles = styleInapp({SLIDER_WIDTH})
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
interface styleInappProps {
|
|
5
|
+
SLIDER_WIDTH: number;
|
|
6
|
+
}
|
|
7
|
+
export const styleInapp = ({SLIDER_WIDTH}: styleInappProps) => StyleSheet.create({
|
|
8
|
+
carouselContainer: {
|
|
9
|
+
width: "100%",
|
|
10
|
+
marginTop: 10,
|
|
11
|
+
},
|
|
12
|
+
styleContainer: {
|
|
13
|
+
backgroundColor: 'white',
|
|
14
|
+
elevation: 10,
|
|
15
|
+
borderRadius: 10,
|
|
16
|
+
width: SLIDER_WIDTH * 0.8,
|
|
17
|
+
height: 480,
|
|
18
|
+
},
|
|
19
|
+
counter: {
|
|
20
|
+
alignSelf: 'center',
|
|
21
|
+
marginVertical: 10
|
|
22
|
+
},
|
|
23
|
+
closeButton: {
|
|
24
|
+
position: 'absolute',
|
|
25
|
+
alignSelf: 'flex-end',
|
|
26
|
+
right: 20,
|
|
27
|
+
top: 20,
|
|
28
|
+
width: 30,
|
|
29
|
+
height: 30,
|
|
30
|
+
borderRadius: 20,
|
|
31
|
+
backgroundColor: '#00000020',
|
|
32
|
+
justifyContent: 'center',
|
|
33
|
+
alignItems: 'center',
|
|
34
|
+
zIndex: 90,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
interface styleItemProps {
|
|
39
|
+
msg: any,
|
|
40
|
+
checkBG: Function,
|
|
41
|
+
}
|
|
42
|
+
export const styleItem = ({msg, checkBG}: styleItemProps) => StyleSheet.create({
|
|
43
|
+
btn_left: {
|
|
44
|
+
backgroundColor: msg.btn_left_bg_color || "#FFFFFF",
|
|
45
|
+
height: 40,
|
|
46
|
+
width: 100,
|
|
47
|
+
alignItems: 'center',
|
|
48
|
+
justifyContent: 'center',
|
|
49
|
+
marginRight: 20,
|
|
50
|
+
marginLeft: 10,
|
|
51
|
+
flex: 1
|
|
52
|
+
},
|
|
53
|
+
btn_right: {
|
|
54
|
+
backgroundColor: msg.btn_right_bg_color || "#FFFFFF",
|
|
55
|
+
height: 40,
|
|
56
|
+
width: 100,
|
|
57
|
+
alignItems: 'center',
|
|
58
|
+
justifyContent: 'center',
|
|
59
|
+
marginRight: 10,
|
|
60
|
+
flex: 1
|
|
61
|
+
},
|
|
62
|
+
btn_left_title: {
|
|
63
|
+
color: msg.btn_left_txt_color || "#000000"
|
|
64
|
+
},
|
|
65
|
+
btn_right_title: {
|
|
66
|
+
color: msg.btn_right_txt_color || "#000000"
|
|
67
|
+
},
|
|
68
|
+
body: {
|
|
69
|
+
backgroundColor: checkBG(),
|
|
70
|
+
width: '100%',
|
|
71
|
+
height: 450,
|
|
72
|
+
alignSelf: 'center',
|
|
73
|
+
alignItems: 'center',
|
|
74
|
+
justifyContent: 'center',
|
|
75
|
+
},
|
|
76
|
+
bodyText: {
|
|
77
|
+
color: msg.body_font_color || "#000000",
|
|
78
|
+
textAlign: 'justify',
|
|
79
|
+
marginBottom: 10,
|
|
80
|
+
fontSize: 15,
|
|
81
|
+
marginHorizontal: 10
|
|
82
|
+
},
|
|
83
|
+
title: {
|
|
84
|
+
color: msg.title_font_color || "#000000",
|
|
85
|
+
fontWeight: "bold",
|
|
86
|
+
fontSize: 18,
|
|
87
|
+
marginTop: 40
|
|
88
|
+
},
|
|
89
|
+
dot: {
|
|
90
|
+
backgroundColor: msg.dot_color || "#FFFFFF",
|
|
91
|
+
borderRadius: 100,
|
|
92
|
+
width: 8,
|
|
93
|
+
height: 8,
|
|
94
|
+
marginLeft: 5,
|
|
95
|
+
elevation: 5,
|
|
96
|
+
}
|
|
97
|
+
});
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// not implemented
|