react-native-flyy 1.4.31 → 1.4.33

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.
@@ -1,7 +1,9 @@
1
1
  // @ts-nocheck
2
2
  import React, { useEffect, useState } from 'react';
3
- import { Image, NativeModules, Text, TouchableOpacity, View, Dimensions, FlatList } from 'react-native';
3
+ import { Image, NativeModules, Text, TouchableOpacity, View, Dimensions, ToastAndroid, Linking, FlatList, Alert } from 'react-native';
4
4
  import FlyyCheckinComponent from './flyy_checkin_view';
5
+ import AsyncStorage from '@react-native-async-storage/async-storage';
6
+ import Draggable from 'react-native-draggable';
5
7
  const {
6
8
  Flyy
7
9
  } = NativeModules;
@@ -21,212 +23,245 @@ export const FlyyCheckinView = props => {
21
23
  };
22
24
  const windowHeight = Dimensions.get('window').height;
23
25
  const windowWidth = Dimensions.get('window').width; // ****** Flyy Floating Widget ******
24
- // export const FlyyFloatingWidget = ({
25
- // props = {
26
- // backgroundColor: "#654EA3",
27
- // buttonHeight: 55,
28
- // buttonWidth: 55,
29
- // buttonCornerRadius: 40,
30
- // buttonIcon: require('./assets/images/rewardwidget.png'),
31
- // onPress: () => { },
32
- // x: windowWidth - 75,
33
- // y: windowHeight - 100,
34
- // minX: 5,
35
- // minY: 5,
36
- // maxX: windowWidth - 5,
37
- // maxY: windowHeight - 5,
38
- // show: true,
39
- // stick: false,
40
- // startDate: 0,
41
- // endDate: 0
42
- // } }) => {
43
- // const [showWidget,setShowWidget] = useState(false);
44
- // const [userData,setUserData] = useState({});
45
- // const [iconUrl,setIconUrl] = useState(require('./assets/images/rewardwidget.png'));
46
- // const [backgroundColor,setBackgroundColor] = useState("#654EA3");
47
- // const [buttonSize,setButtonSize] = useState(55);
48
- // const [buttonXPosition,setButtonXPosition] = useState(windowWidth - 75);
49
- // const [buttonYPosition,setButtonYPosition] = useState(windowHeight - 100);
50
- // const [deeplink,setDeeplink] = useState(null);
51
- // const flyyConfigDate = "flyy_config_date";
52
- // const flyyConfigUserId = "user_id";
53
- // var oldState = null;
54
- // var currentState = null;
55
- // var data = null;
56
- // useEffect(()=>{
57
- // fetchData();
58
- // },[]);
59
- // const fetchData = async() => {
60
- // const sdkInfo = await Flyy.getUserData();
61
- // const appData = await Flyy.getAppData();
62
- // const resp = await fetch(`https://${sdkInfo["environment"] == 0 ? "ghc-stage" : "ghc"}.theflyy.com/api/v8/flyy_app_info`, {
63
- // headers: {
64
- // "X-Key": sdkInfo["partner_id"],
65
- // "Content-Type": "application/json",
66
- // "X-App-Data": appData
67
- // }
68
- // });
69
- // data = await resp.json();
70
- // if(!data.success){
71
- // if (Platform.OS === 'android') {
72
- // ToastAndroid.show(data.message, ToastAndroid.SHORT);
73
- // } else {
74
- // // Toast.showWithGravity(data.message, Toast.SHORT, Toast.BOTTOM);
75
- // }
76
- // return;
77
- // }
78
- // const widgetConfig = data.info.floating_widget_configuration;
79
- // if (widgetConfig.icon_url != null && widgetConfig.icon_url != '') {
80
- // setIconUrl({ uri: widgetConfig.icon_url })
81
- // } else {
82
- // setIconUrl(props.buttonIcon)
83
- // }
84
- // if (widgetConfig.color != null && widgetConfig.color != '') {
85
- // setBackgroundColor(widgetConfig.color)
86
- // } else {
87
- // setBackgroundColor(props.backgroundColor)
88
- // }
89
- // if (widgetConfig.size != null && widgetConfig.color != 0) {
90
- // setButtonSize(parseInt(data.info.floating_widget_configuration.size))
91
- // } else {
92
- // setButtonSize(props.buttonHeight)
93
- // }
94
- // //FloatingButton Position
95
- // if (widgetConfig.position == "bottom_left") {
96
- // setButtonXPosition(10)
97
- // } else if (widgetConfig.position == "bottom_right") {
98
- // setButtonXPosition(windowWidth - 75)
99
- // } else if (widgetConfig.position == "upper_left") {
100
- // setButtonXPosition(10)
101
- // if (Platform.OS === 'android'){
102
- // setButtonYPosition(10)
103
- // }else{
104
- // setButtonYPosition(50)
105
- // }
106
- // } else if (widgetConfig.position == "upper_right") {
107
- // setButtonXPosition(windowWidth - 75)
108
- // if (Platform.OS === 'android'){
109
- // setButtonYPosition(10)
110
- // }else{
111
- // setButtonYPosition(50)
112
- // }
113
- // }
114
- // //Set DeepLink
115
- // if (widgetConfig.deeplink != null && widgetConfig.deeplink != "") {
116
- // setDeeplink(widgetConfig.deeplink)
117
- // }
118
- // //Set Visibility of FloatingButton
119
- // var currentDate = new Date();
120
- // const getDate = await AsyncStorage.getItem(flyyConfigDate);
121
- // const userId = await AsyncStorage.getItem(flyyConfigUserId);
122
- // var date = new Date(parseInt(getDate));
123
- // const diffTime = Math.abs(getDate - currentDate);
124
- // const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))-1;
125
- // if(diffDays != 0 || userId == null || userId != sdkInfo[flyyConfigUserId]){
126
- // var data = await Flyy.getAppOccurence(1);
127
- // await AsyncStorage.setItem(
128
- // flyyConfigUserId,
129
- // sdkInfo[flyyConfigUserId]
130
- // );
131
- // }
132
- // const occurrenceCount = await Flyy.getAppOccurence(0);
133
- // if (widgetConfig.show_to_user && occurrenceCount <= parseInt(widgetConfig.num_times)) {
134
- // // var numberOfDaysToAdd = widgetConfig.num_days+1;
135
- // // var result = currentDate.setDate(currentDate.getDate() + numberOfDaysToAdd);
136
- // if(getDate === null || userId == null || userId != sdkInfo[flyyConfigUserId]){
137
- // await AsyncStorage.setItem(
138
- // flyyConfigDate,
139
- // JSON.stringify(currentDate.getTime())
140
- // );
141
- // }
142
- // const getDate2 = await AsyncStorage.getItem(flyyConfigDate);
143
- // var date = new Date(parseInt(getDate2));
144
- // const diffTime = Math.abs(getDate2 - currentDate);
145
- // const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))-1;
146
- // //Show widget on same day
147
- // if(diffDays === 0 || diffDays === -1){
148
- // setShowWidget(true)
149
- // }else{
150
- // //reset occurrence on next day
151
- // await Flyy.getAppOccurence(1);
152
- // if(diffDays >= parseInt(widgetConfig.num_days)+1){
153
- // await AsyncStorage.setItem(
154
- // flyyConfigDate,
155
- // JSON.stringify(currentDate.getTime())
156
- // );
157
- // setShowWidget(true)
158
- // }
159
- // }
160
- // }else{
161
- // setShowWidget(false);
162
- // const getDate2 = await AsyncStorage.getItem(flyyConfigDate);
163
- // var date = new Date(parseInt(getDate2));
164
- // const diffTime = Math.abs(getDate2 - currentDate);
165
- // const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
166
- // if(diffDays != 1){
167
- // var data = await Flyy.getAppOccurence(1);
168
- // }
169
- // }
170
- // }
171
- // // if(props.show){
172
- // // if(props.startDate != null && props.startDate != 0){
173
- // // var now = new Date().getTime();
174
- // // if(now >= props.startDate && now <= props.endDate){
175
- // // props.show = true
176
- // // }else{
177
- // // props.show = false
178
- // // }
179
- // // }
180
- // // }
181
- // // AppState.addEventListener('change', state =>{
182
- // // console.log('AppState updated to', AppState.currentState)
183
- // // oldState = currentState;
184
- // // currentState = state;
185
- // // if(oldState == null){
186
- // // console.log('App is newly start :::')
187
- // // }})
188
- // return (
189
- // // @ts-ignore
190
- // props.show && showWidget? <Draggable x={buttonXPosition}
191
- // y={buttonYPosition}
192
- // minX={props.minX ?? 5}
193
- // minY={props.minY ?? 5}
194
- // maxX={props.maxX ?? windowWidth - 5}
195
- // maxY={props.maxY ?? windowHeight - 5}
196
- // renderSize={56}
197
- // // shouldReverse = {true}
198
- // onDragRelease={props.stick ? () => {
199
- // } : null} isCircle>
200
- // <TouchableOpacity
201
- // onPress={deeplink != null ? async()=>{
202
- // if (Platform.OS === 'android' || !deeplink.startsWith("flyy://")) {
203
- // const supported = await Linking.canOpenURL(deeplink);
204
- // await Linking.openURL(deeplink);
205
- // } else {
206
- // navigateTo(deeplink);
207
- // }
208
- // }:props.onPress}
209
- // style={{
210
- // height: buttonSize,
211
- // width: buttonSize,
212
- // backgroundColor: backgroundColor,
213
- // borderRadius: buttonSize/2,
214
- // justifyContent: 'center',
215
- // alignItems: 'center',
216
- // }}>
217
- // <Image source={iconUrl} style={{ height: buttonSize*55/100, width: buttonSize*55/100 }} />
218
- // <TouchableOpacity
219
- // onPress={()=>{
220
- // props.show = false;
221
- // setShowWidget(false);
222
- // }}
223
- // style = {{height: 20, width: 20, backgroundColor: "transparent",position:'absolute',left:buttonSize-11, bottom: buttonSize*72/100}}>
224
- // <Image source={require('./assets/images/xmark.png')} style={{ height: 18, width: 18, tintColor: "black"}} />
225
- // </TouchableOpacity>
226
- // </TouchableOpacity>
227
- // </Draggable> : <View/>
228
- // );
229
- // }
26
+
27
+ export const FlyyFloatingWidget = ({
28
+ props = {
29
+ backgroundColor: "#654EA3",
30
+ buttonHeight: 55,
31
+ buttonWidth: 55,
32
+ buttonCornerRadius: 40,
33
+ buttonIcon: require('./assets/images/rewardwidget.png'),
34
+ onPress: () => {},
35
+ x: windowWidth - 75,
36
+ y: windowHeight - 100,
37
+ minX: 5,
38
+ minY: 5,
39
+ maxX: windowWidth - 5,
40
+ maxY: windowHeight - 5,
41
+ show: true,
42
+ stick: false,
43
+ startDate: 0,
44
+ endDate: 0
45
+ }
46
+ }) => {
47
+ var _props$minX, _props$minY, _props$maxX, _props$maxY;
48
+
49
+ const [showWidget, setShowWidget] = useState(false);
50
+ const [userData, setUserData] = useState({});
51
+ const [iconUrl, setIconUrl] = useState(require('./assets/images/rewardwidget.png'));
52
+ const [backgroundColor, setBackgroundColor] = useState("#654EA3");
53
+ const [buttonSize, setButtonSize] = useState(55);
54
+ const [buttonXPosition, setButtonXPosition] = useState(windowWidth - 75);
55
+ const [buttonYPosition, setButtonYPosition] = useState(windowHeight - 200);
56
+ const [deeplink, setDeeplink] = useState(null);
57
+ const flyyConfigDate = "flyy_config_date";
58
+ const flyyConfigUserId = "user_id";
59
+ var oldState = null;
60
+ var currentState = null;
61
+ var data = null;
62
+ useEffect(() => {
63
+ fetchData();
64
+ }, []);
65
+
66
+ const fetchData = async () => {
67
+ const sdkInfo = await Flyy.getUserData();
68
+ const appData = await Flyy.getAppData();
69
+ const resp = await fetch(`https://${sdkInfo["environment"] == 0 ? "ghc-stage" : "ghc"}.theflyy.com/api/v8/flyy_app_info`, {
70
+ headers: {
71
+ "X-Key": sdkInfo["partner_id"],
72
+ "Content-Type": "application/json",
73
+ "X-App-Data": appData
74
+ }
75
+ });
76
+ data = await resp.json();
77
+
78
+ if (!data.success) {
79
+ if (Platform.OS === 'android') {
80
+ ToastAndroid.show(data.message, ToastAndroid.SHORT);
81
+ } else {
82
+ // Toast.showWithGravity(data.message, Toast.SHORT, Toast.BOTTOM);
83
+ Alert.alert(data.message);
84
+ }
85
+
86
+ return;
87
+ }
88
+
89
+ const widgetConfig = data.info.floating_widget_configuration;
90
+
91
+ if (widgetConfig.icon_url != null && widgetConfig.icon_url != '') {
92
+ setIconUrl({
93
+ uri: widgetConfig.icon_url
94
+ });
95
+ } else {
96
+ setIconUrl(props.buttonIcon);
97
+ }
98
+
99
+ if (widgetConfig.color != null && widgetConfig.color != '') {
100
+ setBackgroundColor(widgetConfig.color);
101
+ } else {
102
+ setBackgroundColor(props.backgroundColor);
103
+ }
104
+
105
+ if (widgetConfig.size != null && widgetConfig.color != 0) {
106
+ setButtonSize(parseInt(data.info.floating_widget_configuration.size));
107
+ } else {
108
+ setButtonSize(props.buttonHeight);
109
+ } //FloatingButton Position
110
+
111
+
112
+ if (widgetConfig.position == "bottom_left") {
113
+ setButtonXPosition(10);
114
+ } else if (widgetConfig.position == "bottom_right") {
115
+ setButtonXPosition(windowWidth - 75);
116
+ } else if (widgetConfig.position == "upper_left") {
117
+ setButtonXPosition(10);
118
+
119
+ if (Platform.OS === 'android') {
120
+ setButtonYPosition(10);
121
+ } else {
122
+ setButtonYPosition(50);
123
+ }
124
+ } else if (widgetConfig.position == "upper_right") {
125
+ setButtonXPosition(windowWidth - 75);
126
+
127
+ if (Platform.OS === 'android') {
128
+ setButtonYPosition(10);
129
+ } else {
130
+ setButtonYPosition(50);
131
+ }
132
+ } //Set DeepLink
133
+
134
+
135
+ if (widgetConfig.deeplink != null && widgetConfig.deeplink != "") {
136
+ setDeeplink(widgetConfig.deeplink);
137
+ } //Set Visibility of FloatingButton
138
+
139
+
140
+ var currentDate = new Date();
141
+ const getDate = await AsyncStorage.getItem(flyyConfigDate);
142
+ const userId = await AsyncStorage.getItem(flyyConfigUserId);
143
+ var date = new Date(parseInt(getDate));
144
+ const diffTime = Math.abs(getDate - currentDate);
145
+ const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) - 1;
146
+
147
+ if (diffDays != 0 || userId == null || userId != sdkInfo[flyyConfigUserId]) {
148
+ var data = await Flyy.getAppOccurence(1);
149
+ await AsyncStorage.setItem(flyyConfigUserId, sdkInfo[flyyConfigUserId]);
150
+ }
151
+
152
+ const occurrenceCount = await Flyy.getAppOccurence(0);
153
+
154
+ if (widgetConfig.show_to_user && occurrenceCount <= parseInt(widgetConfig.num_times)) {
155
+ // var numberOfDaysToAdd = widgetConfig.num_days+1;
156
+ // var result = currentDate.setDate(currentDate.getDate() + numberOfDaysToAdd);
157
+ if (getDate === null || userId == null || userId != sdkInfo[flyyConfigUserId]) {
158
+ await AsyncStorage.setItem(flyyConfigDate, JSON.stringify(currentDate.getTime()));
159
+ }
160
+
161
+ const getDate2 = await AsyncStorage.getItem(flyyConfigDate);
162
+ var date = new Date(parseInt(getDate2));
163
+ const diffTime = Math.abs(getDate2 - currentDate);
164
+ const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) - 1; //Show widget on same day
165
+
166
+ if (diffDays === 0 || diffDays === -1) {
167
+ setShowWidget(true);
168
+ } else {
169
+ //reset occurrence on next day
170
+ await Flyy.getAppOccurence(1);
171
+
172
+ if (diffDays >= parseInt(widgetConfig.num_days) + 1) {
173
+ await AsyncStorage.setItem(flyyConfigDate, JSON.stringify(currentDate.getTime()));
174
+ setShowWidget(true);
175
+ }
176
+ }
177
+ } else {
178
+ setShowWidget(false);
179
+ const getDate2 = await AsyncStorage.getItem(flyyConfigDate);
180
+ var date = new Date(parseInt(getDate2));
181
+ const diffTime = Math.abs(getDate2 - currentDate);
182
+ const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
183
+
184
+ if (diffDays != 1) {
185
+ var data = await Flyy.getAppOccurence(1);
186
+ }
187
+ }
188
+ }; // if(props.show){
189
+ // if(props.startDate != null && props.startDate != 0){
190
+ // var now = new Date().getTime();
191
+ // if(now >= props.startDate && now <= props.endDate){
192
+ // props.show = true
193
+ // }else{
194
+ // props.show = false
195
+ // }
196
+ // }
197
+ // }
198
+ // AppState.addEventListener('change', state =>{
199
+ // console.log('AppState updated to', AppState.currentState)
200
+ // oldState = currentState;
201
+ // currentState = state;
202
+ // if(oldState == null){
203
+ // console.log('App is newly start :::')
204
+ // }})
205
+
206
+
207
+ return (// @ts-ignore
208
+ props.show && showWidget ? /*#__PURE__*/React.createElement(Draggable, {
209
+ x: buttonXPosition,
210
+ y: buttonYPosition,
211
+ minX: (_props$minX = props.minX) !== null && _props$minX !== void 0 ? _props$minX : 5,
212
+ minY: (_props$minY = props.minY) !== null && _props$minY !== void 0 ? _props$minY : 5,
213
+ maxX: (_props$maxX = props.maxX) !== null && _props$maxX !== void 0 ? _props$maxX : windowWidth - 5,
214
+ maxY: (_props$maxY = props.maxY) !== null && _props$maxY !== void 0 ? _props$maxY : windowHeight - 5,
215
+ renderSize: 56 // shouldReverse = {true}
216
+ ,
217
+ onDragRelease: props.stick ? () => {} : null,
218
+ isCircle: true
219
+ }, /*#__PURE__*/React.createElement(TouchableOpacity, {
220
+ onPress: deeplink != null ? async () => {
221
+ if (Platform.OS === 'android' || !deeplink.startsWith("flyy://")) {
222
+ const supported = await Linking.canOpenURL(deeplink);
223
+ await Linking.openURL(deeplink);
224
+ } else {
225
+ navigateTo(deeplink);
226
+ }
227
+ } : props.onPress,
228
+ style: {
229
+ height: buttonSize,
230
+ width: buttonSize,
231
+ backgroundColor: backgroundColor,
232
+ borderRadius: buttonSize / 2,
233
+ justifyContent: 'center',
234
+ alignItems: 'center'
235
+ }
236
+ }, /*#__PURE__*/React.createElement(Image, {
237
+ source: iconUrl,
238
+ style: {
239
+ height: buttonSize * 55 / 100,
240
+ width: buttonSize * 55 / 100
241
+ }
242
+ }), /*#__PURE__*/React.createElement(TouchableOpacity, {
243
+ onPress: () => {
244
+ props.show = false;
245
+ setShowWidget(false);
246
+ },
247
+ style: {
248
+ height: 20,
249
+ width: 20,
250
+ backgroundColor: "transparent",
251
+ position: 'absolute',
252
+ left: buttonSize - 11,
253
+ bottom: buttonSize * 72 / 100
254
+ }
255
+ }, /*#__PURE__*/React.createElement(Image, {
256
+ source: require('./assets/images/xmark.png'),
257
+ style: {
258
+ height: 18,
259
+ width: 18,
260
+ tintColor: "black"
261
+ }
262
+ })))) : /*#__PURE__*/React.createElement(View, null)
263
+ );
264
+ };
230
265
 
231
266
  const navigateTo = deeplink => {
232
267
  let components = deeplink.split("/");
@@ -341,8 +376,9 @@ const navigateTo = deeplink => {
341
376
  }
342
377
  break;
343
378
 
344
- default: // Toast.showWithGravity("ACTION NOT FOUND", Toast.SHORT, Toast.BOTTOM);
345
-
379
+ default:
380
+ // Toast.showWithGravity("ACTION NOT FOUND", Toast.SHORT, Toast.BOTTOM);
381
+ Alert.alert("ACTION NOT FOUND");
346
382
  }
347
383
  };
348
384
 
@@ -628,8 +664,9 @@ export const FlyyStories = ({
628
664
  }
629
665
  break;
630
666
 
631
- default: // Toast.showWithGravity("ACTION NOT FOUND", Toast.SHORT, Toast.BOTTOM);
632
-
667
+ default:
668
+ // Toast.showWithGravity("ACTION NOT FOUND", Toast.SHORT, Toast.BOTTOM);
669
+ Alert.alert("ACTION NOT FOUND");
633
670
  }
634
671
  };
635
672