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.
package/src/index.tsx CHANGED
@@ -10,10 +10,13 @@ import {
10
10
  AppState,
11
11
  ToastAndroid,
12
12
  Linking,
13
- FlatList
13
+ FlatList,
14
+ Alert
14
15
  } from 'react-native';
15
16
  import FlyyCheckinComponent from './flyy_checkin_view';
16
17
  import { FlyyStoriesWidget } from './flyy_stories';
18
+ import AsyncStorage from '@react-native-async-storage/async-storage';
19
+ import Draggable from 'react-native-draggable';
17
20
 
18
21
  type FlyyType = {
19
22
  getUserId(arg0: (data: any) => void): unknown;
@@ -39,224 +42,225 @@ const windowHeight = Dimensions.get('window').height;
39
42
  const windowWidth = Dimensions.get('window').width;
40
43
 
41
44
  // ****** Flyy Floating Widget ******
42
- // export const FlyyFloatingWidget = ({
43
- // props = {
44
- // backgroundColor: "#654EA3",
45
- // buttonHeight: 55,
46
- // buttonWidth: 55,
47
- // buttonCornerRadius: 40,
48
- // buttonIcon: require('./assets/images/rewardwidget.png'),
49
- // onPress: () => { },
50
- // x: windowWidth - 75,
51
- // y: windowHeight - 100,
52
- // minX: 5,
53
- // minY: 5,
54
- // maxX: windowWidth - 5,
55
- // maxY: windowHeight - 5,
56
- // show: true,
57
- // stick: false,
58
- // startDate: 0,
59
- // endDate: 0
60
- // } }) => {
61
-
62
- // const [showWidget,setShowWidget] = useState(false);
63
- // const [userData,setUserData] = useState({});
64
- // const [iconUrl,setIconUrl] = useState(require('./assets/images/rewardwidget.png'));
65
- // const [backgroundColor,setBackgroundColor] = useState("#654EA3");
66
- // const [buttonSize,setButtonSize] = useState(55);
67
- // const [buttonXPosition,setButtonXPosition] = useState(windowWidth - 75);
68
- // const [buttonYPosition,setButtonYPosition] = useState(windowHeight - 100);
69
- // const [deeplink,setDeeplink] = useState(null);
70
- // const flyyConfigDate = "flyy_config_date";
71
- // const flyyConfigUserId = "user_id";
72
- // var oldState = null;
73
- // var currentState = null;
74
- // var data = null;
75
-
76
- // useEffect(()=>{
77
- // fetchData();
78
- // },[]);
79
-
80
- // const fetchData = async() => {
81
- // const sdkInfo = await Flyy.getUserData();
82
- // const appData = await Flyy.getAppData();
83
- // const resp = await fetch(`https://${sdkInfo["environment"] == 0 ? "ghc-stage" : "ghc"}.theflyy.com/api/v8/flyy_app_info`, {
84
- // headers: {
85
- // "X-Key": sdkInfo["partner_id"],
86
- // "Content-Type": "application/json",
87
- // "X-App-Data": appData
88
- // }
89
- // });
90
- // data = await resp.json();
91
- // if(!data.success){
92
- // if (Platform.OS === 'android') {
93
- // ToastAndroid.show(data.message, ToastAndroid.SHORT);
94
- // } else {
95
- // // Toast.showWithGravity(data.message, Toast.SHORT, Toast.BOTTOM);
96
- // }
97
- // return;
98
- // }
99
- // const widgetConfig = data.info.floating_widget_configuration;
100
-
101
- // if (widgetConfig.icon_url != null && widgetConfig.icon_url != '') {
102
- // setIconUrl({ uri: widgetConfig.icon_url })
103
- // } else {
104
- // setIconUrl(props.buttonIcon)
105
- // }
106
-
107
- // if (widgetConfig.color != null && widgetConfig.color != '') {
108
- // setBackgroundColor(widgetConfig.color)
109
- // } else {
110
- // setBackgroundColor(props.backgroundColor)
111
- // }
112
-
113
- // if (widgetConfig.size != null && widgetConfig.color != 0) {
114
- // setButtonSize(parseInt(data.info.floating_widget_configuration.size))
115
- // } else {
116
- // setButtonSize(props.buttonHeight)
117
- // }
118
-
119
- // //FloatingButton Position
120
- // if (widgetConfig.position == "bottom_left") {
121
- // setButtonXPosition(10)
122
- // } else if (widgetConfig.position == "bottom_right") {
123
- // setButtonXPosition(windowWidth - 75)
124
- // } else if (widgetConfig.position == "upper_left") {
125
- // setButtonXPosition(10)
126
- // if (Platform.OS === 'android'){
127
- // setButtonYPosition(10)
128
- // }else{
129
- // setButtonYPosition(50)
130
- // }
131
- // } else if (widgetConfig.position == "upper_right") {
132
- // setButtonXPosition(windowWidth - 75)
133
- // if (Platform.OS === 'android'){
134
- // setButtonYPosition(10)
135
- // }else{
136
- // setButtonYPosition(50)
137
- // }
138
- // }
139
-
140
- // //Set DeepLink
141
- // if (widgetConfig.deeplink != null && widgetConfig.deeplink != "") {
142
- // setDeeplink(widgetConfig.deeplink)
143
- // }
144
- // //Set Visibility of FloatingButton
145
- // var currentDate = new Date();
146
- // const getDate = await AsyncStorage.getItem(flyyConfigDate);
147
- // const userId = await AsyncStorage.getItem(flyyConfigUserId);
148
- // var date = new Date(parseInt(getDate));
149
- // const diffTime = Math.abs(getDate - currentDate);
150
- // const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))-1;
151
- // if(diffDays != 0 || userId == null || userId != sdkInfo[flyyConfigUserId]){
152
- // var data = await Flyy.getAppOccurence(1);
153
- // await AsyncStorage.setItem(
154
- // flyyConfigUserId,
155
- // sdkInfo[flyyConfigUserId]
156
- // );
157
- // }
158
- // const occurrenceCount = await Flyy.getAppOccurence(0);
159
- // if (widgetConfig.show_to_user && occurrenceCount <= parseInt(widgetConfig.num_times)) {
160
- // // var numberOfDaysToAdd = widgetConfig.num_days+1;
161
- // // var result = currentDate.setDate(currentDate.getDate() + numberOfDaysToAdd);
162
- // if(getDate === null || userId == null || userId != sdkInfo[flyyConfigUserId]){
163
- // await AsyncStorage.setItem(
164
- // flyyConfigDate,
165
- // JSON.stringify(currentDate.getTime())
166
- // );
167
- // }
168
- // const getDate2 = await AsyncStorage.getItem(flyyConfigDate);
169
- // var date = new Date(parseInt(getDate2));
170
- // const diffTime = Math.abs(getDate2 - currentDate);
171
- // const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))-1;
172
- // //Show widget on same day
173
- // if(diffDays === 0 || diffDays === -1){
174
- // setShowWidget(true)
175
- // }else{
176
- // //reset occurrence on next day
177
- // await Flyy.getAppOccurence(1);
178
- // if(diffDays >= parseInt(widgetConfig.num_days)+1){
179
- // await AsyncStorage.setItem(
180
- // flyyConfigDate,
181
- // JSON.stringify(currentDate.getTime())
182
- // );
183
- // setShowWidget(true)
184
- // }
185
- // }
186
- // }else{
187
- // setShowWidget(false);
188
- // const getDate2 = await AsyncStorage.getItem(flyyConfigDate);
189
- // var date = new Date(parseInt(getDate2));
190
- // const diffTime = Math.abs(getDate2 - currentDate);
191
- // const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
192
- // if(diffDays != 1){
193
- // var data = await Flyy.getAppOccurence(1);
194
- // }
195
- // }
196
- // }
197
-
198
- // // if(props.show){
199
- // // if(props.startDate != null && props.startDate != 0){
200
- // // var now = new Date().getTime();
201
- // // if(now >= props.startDate && now <= props.endDate){
202
- // // props.show = true
203
- // // }else{
204
- // // props.show = false
205
- // // }
206
- // // }
207
- // // }
208
-
209
- // // AppState.addEventListener('change', state =>{
210
- // // console.log('AppState updated to', AppState.currentState)
211
- // // oldState = currentState;
212
- // // currentState = state;
213
- // // if(oldState == null){
214
- // // console.log('App is newly start :::')
215
- // // }})
216
-
217
- // return (
218
- // // @ts-ignore
219
- // props.show && showWidget? <Draggable x={buttonXPosition}
220
- // y={buttonYPosition}
221
- // minX={props.minX ?? 5}
222
- // minY={props.minY ?? 5}
223
- // maxX={props.maxX ?? windowWidth - 5}
224
- // maxY={props.maxY ?? windowHeight - 5}
225
- // renderSize={56}
226
- // // shouldReverse = {true}
227
- // onDragRelease={props.stick ? () => {
228
-
229
- // } : null} isCircle>
230
- // <TouchableOpacity
231
- // onPress={deeplink != null ? async()=>{
232
- // if (Platform.OS === 'android' || !deeplink.startsWith("flyy://")) {
233
- // const supported = await Linking.canOpenURL(deeplink);
234
- // await Linking.openURL(deeplink);
235
- // } else {
236
- // navigateTo(deeplink);
237
- // }
238
- // }:props.onPress}
239
- // style={{
240
- // height: buttonSize,
241
- // width: buttonSize,
242
- // backgroundColor: backgroundColor,
243
- // borderRadius: buttonSize/2,
244
- // justifyContent: 'center',
245
- // alignItems: 'center',
246
- // }}>
247
- // <Image source={iconUrl} style={{ height: buttonSize*55/100, width: buttonSize*55/100 }} />
248
- // <TouchableOpacity
249
- // onPress={()=>{
250
- // props.show = false;
251
- // setShowWidget(false);
252
- // }}
253
- // style = {{height: 20, width: 20, backgroundColor: "transparent",position:'absolute',left:buttonSize-11, bottom: buttonSize*72/100}}>
254
- // <Image source={require('./assets/images/xmark.png')} style={{ height: 18, width: 18, tintColor: "black"}} />
255
- // </TouchableOpacity>
256
- // </TouchableOpacity>
257
- // </Draggable> : <View/>
258
- // );
259
- // }
45
+ export const FlyyFloatingWidget = ({
46
+ props = {
47
+ backgroundColor: "#654EA3",
48
+ buttonHeight: 55,
49
+ buttonWidth: 55,
50
+ buttonCornerRadius: 40,
51
+ buttonIcon: require('./assets/images/rewardwidget.png'),
52
+ onPress: () => { },
53
+ x: windowWidth - 75,
54
+ y: windowHeight - 100,
55
+ minX: 5,
56
+ minY: 5,
57
+ maxX: windowWidth - 5,
58
+ maxY: windowHeight - 5,
59
+ show: true,
60
+ stick: false,
61
+ startDate: 0,
62
+ endDate: 0
63
+ } }) => {
64
+
65
+ const [showWidget,setShowWidget] = useState(false);
66
+ const [userData,setUserData] = useState({});
67
+ const [iconUrl,setIconUrl] = useState(require('./assets/images/rewardwidget.png'));
68
+ const [backgroundColor,setBackgroundColor] = useState("#654EA3");
69
+ const [buttonSize,setButtonSize] = useState(55);
70
+ const [buttonXPosition,setButtonXPosition] = useState(windowWidth - 75);
71
+ const [buttonYPosition,setButtonYPosition] = useState(windowHeight - 200);
72
+ const [deeplink,setDeeplink] = useState(null);
73
+ const flyyConfigDate = "flyy_config_date";
74
+ const flyyConfigUserId = "user_id";
75
+ var oldState = null;
76
+ var currentState = null;
77
+ var data = null;
78
+
79
+ useEffect(()=>{
80
+ fetchData();
81
+ },[]);
82
+
83
+ const fetchData = async() => {
84
+ const sdkInfo = await Flyy.getUserData();
85
+ const appData = await Flyy.getAppData();
86
+ const resp = await fetch(`https://${sdkInfo["environment"] == 0 ? "ghc-stage" : "ghc"}.theflyy.com/api/v8/flyy_app_info`, {
87
+ headers: {
88
+ "X-Key": sdkInfo["partner_id"],
89
+ "Content-Type": "application/json",
90
+ "X-App-Data": appData
91
+ }
92
+ });
93
+ data = await resp.json();
94
+ if(!data.success){
95
+ if (Platform.OS === 'android') {
96
+ ToastAndroid.show(data.message, ToastAndroid.SHORT);
97
+ } else {
98
+ // Toast.showWithGravity(data.message, Toast.SHORT, Toast.BOTTOM);
99
+ Alert.alert(data.message);
100
+ }
101
+ return;
102
+ }
103
+ const widgetConfig = data.info.floating_widget_configuration;
104
+
105
+ if (widgetConfig.icon_url != null && widgetConfig.icon_url != '') {
106
+ setIconUrl({ uri: widgetConfig.icon_url })
107
+ } else {
108
+ setIconUrl(props.buttonIcon)
109
+ }
110
+
111
+ if (widgetConfig.color != null && widgetConfig.color != '') {
112
+ setBackgroundColor(widgetConfig.color)
113
+ } else {
114
+ setBackgroundColor(props.backgroundColor)
115
+ }
116
+
117
+ if (widgetConfig.size != null && widgetConfig.color != 0) {
118
+ setButtonSize(parseInt(data.info.floating_widget_configuration.size))
119
+ } else {
120
+ setButtonSize(props.buttonHeight)
121
+ }
122
+
123
+ //FloatingButton Position
124
+ if (widgetConfig.position == "bottom_left") {
125
+ setButtonXPosition(10)
126
+ } else if (widgetConfig.position == "bottom_right") {
127
+ setButtonXPosition(windowWidth - 75)
128
+ } else if (widgetConfig.position == "upper_left") {
129
+ setButtonXPosition(10)
130
+ if (Platform.OS === 'android'){
131
+ setButtonYPosition(10)
132
+ }else{
133
+ setButtonYPosition(50)
134
+ }
135
+ } else if (widgetConfig.position == "upper_right") {
136
+ setButtonXPosition(windowWidth - 75)
137
+ if (Platform.OS === 'android'){
138
+ setButtonYPosition(10)
139
+ }else{
140
+ setButtonYPosition(50)
141
+ }
142
+ }
143
+
144
+ //Set DeepLink
145
+ if (widgetConfig.deeplink != null && widgetConfig.deeplink != "") {
146
+ setDeeplink(widgetConfig.deeplink)
147
+ }
148
+ //Set Visibility of FloatingButton
149
+ var currentDate = new Date();
150
+ const getDate = await AsyncStorage.getItem(flyyConfigDate);
151
+ const userId = await AsyncStorage.getItem(flyyConfigUserId);
152
+ var date = new Date(parseInt(getDate));
153
+ const diffTime = Math.abs(getDate - currentDate);
154
+ const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))-1;
155
+ if(diffDays != 0 || userId == null || userId != sdkInfo[flyyConfigUserId]){
156
+ var data = await Flyy.getAppOccurence(1);
157
+ await AsyncStorage.setItem(
158
+ flyyConfigUserId,
159
+ sdkInfo[flyyConfigUserId]
160
+ );
161
+ }
162
+ const occurrenceCount = await Flyy.getAppOccurence(0);
163
+ if (widgetConfig.show_to_user && occurrenceCount <= parseInt(widgetConfig.num_times)) {
164
+ // var numberOfDaysToAdd = widgetConfig.num_days+1;
165
+ // var result = currentDate.setDate(currentDate.getDate() + numberOfDaysToAdd);
166
+ if(getDate === null || userId == null || userId != sdkInfo[flyyConfigUserId]){
167
+ await AsyncStorage.setItem(
168
+ flyyConfigDate,
169
+ JSON.stringify(currentDate.getTime())
170
+ );
171
+ }
172
+ const getDate2 = await AsyncStorage.getItem(flyyConfigDate);
173
+ var date = new Date(parseInt(getDate2));
174
+ const diffTime = Math.abs(getDate2 - currentDate);
175
+ const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))-1;
176
+ //Show widget on same day
177
+ if(diffDays === 0 || diffDays === -1){
178
+ setShowWidget(true)
179
+ }else{
180
+ //reset occurrence on next day
181
+ await Flyy.getAppOccurence(1);
182
+ if(diffDays >= parseInt(widgetConfig.num_days)+1){
183
+ await AsyncStorage.setItem(
184
+ flyyConfigDate,
185
+ JSON.stringify(currentDate.getTime())
186
+ );
187
+ setShowWidget(true)
188
+ }
189
+ }
190
+ }else{
191
+ setShowWidget(false);
192
+ const getDate2 = await AsyncStorage.getItem(flyyConfigDate);
193
+ var date = new Date(parseInt(getDate2));
194
+ const diffTime = Math.abs(getDate2 - currentDate);
195
+ const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
196
+ if(diffDays != 1){
197
+ var data = await Flyy.getAppOccurence(1);
198
+ }
199
+ }
200
+ }
201
+
202
+ // if(props.show){
203
+ // if(props.startDate != null && props.startDate != 0){
204
+ // var now = new Date().getTime();
205
+ // if(now >= props.startDate && now <= props.endDate){
206
+ // props.show = true
207
+ // }else{
208
+ // props.show = false
209
+ // }
210
+ // }
211
+ // }
212
+
213
+ // AppState.addEventListener('change', state =>{
214
+ // console.log('AppState updated to', AppState.currentState)
215
+ // oldState = currentState;
216
+ // currentState = state;
217
+ // if(oldState == null){
218
+ // console.log('App is newly start :::')
219
+ // }})
220
+
221
+ return (
222
+ // @ts-ignore
223
+ props.show && showWidget? <Draggable x={buttonXPosition}
224
+ y={buttonYPosition}
225
+ minX={props.minX ?? 5}
226
+ minY={props.minY ?? 5}
227
+ maxX={props.maxX ?? windowWidth - 5}
228
+ maxY={props.maxY ?? windowHeight - 5}
229
+ renderSize={56}
230
+ // shouldReverse = {true}
231
+ onDragRelease={props.stick ? () => {
232
+
233
+ } : null} isCircle>
234
+ <TouchableOpacity
235
+ onPress={deeplink != null ? async()=>{
236
+ if (Platform.OS === 'android' || !deeplink.startsWith("flyy://")) {
237
+ const supported = await Linking.canOpenURL(deeplink);
238
+ await Linking.openURL(deeplink);
239
+ } else {
240
+ navigateTo(deeplink);
241
+ }
242
+ }:props.onPress}
243
+ style={{
244
+ height: buttonSize,
245
+ width: buttonSize,
246
+ backgroundColor: backgroundColor,
247
+ borderRadius: buttonSize/2,
248
+ justifyContent: 'center',
249
+ alignItems: 'center',
250
+ }}>
251
+ <Image source={iconUrl} style={{ height: buttonSize*55/100, width: buttonSize*55/100 }} />
252
+ <TouchableOpacity
253
+ onPress={()=>{
254
+ props.show = false;
255
+ setShowWidget(false);
256
+ }}
257
+ style = {{height: 20, width: 20, backgroundColor: "transparent",position:'absolute',left:buttonSize-11, bottom: buttonSize*72/100}}>
258
+ <Image source={require('./assets/images/xmark.png')} style={{ height: 18, width: 18, tintColor: "black"}} />
259
+ </TouchableOpacity>
260
+ </TouchableOpacity>
261
+ </Draggable> : <View/>
262
+ );
263
+ }
260
264
 
261
265
  const navigateTo = (deeplink) => {
262
266
  let components = deeplink.split("/");
@@ -265,7 +269,7 @@ const navigateTo = (deeplink) => {
265
269
  case "flyy_offers":
266
270
  {
267
271
  Flyy.openOffersScreen();
268
- }
272
+ }
269
273
  break;
270
274
  case "challenge_details":
271
275
  {
@@ -345,7 +349,7 @@ const navigateTo = (deeplink) => {
345
349
  {
346
350
  Flyy.openFlyyGamesPage();
347
351
  }
348
- break;
352
+ break;
349
353
  case "flyy_bonanza":
350
354
  {
351
355
  Flyy.openFlyyBonanzaPage();
@@ -358,6 +362,7 @@ const navigateTo = (deeplink) => {
358
362
  break;
359
363
  default:
360
364
  // Toast.showWithGravity("ACTION NOT FOUND", Toast.SHORT, Toast.BOTTOM);
365
+ Alert.alert("ACTION NOT FOUND");
361
366
 
362
367
  }
363
368
  }
@@ -518,7 +523,7 @@ export const FlyyStories = ({
518
523
  },[]);
519
524
 
520
525
  const fetchStoriesData = async() => {
521
- const sdkInfo = await Flyy.getUserData();
526
+ const sdkInfo = await Flyy.getUserData();
522
527
  const appData = await Flyy.getAppData();
523
528
  const resp = await fetch(`https://${sdkInfo["environment"] == 0 ? "ghc-stage" : "ghc"}.theflyy.com/api/storyboard`, {
524
529
  headers: {
@@ -536,7 +541,7 @@ export const FlyyStories = ({
536
541
  case "offers":
537
542
  {
538
543
  Flyy.openOffersScreen();
539
- }
544
+ }
540
545
  break;
541
546
  case "spin_wheel":
542
547
  {
@@ -549,25 +554,25 @@ export const FlyyStories = ({
549
554
  Flyy.openFlyyChallengeDetailPage(0);
550
555
  }
551
556
  break;
552
-
557
+
553
558
  case "quiz_list":
554
559
  {
555
560
  Flyy.openFlyyQuizListPage();
556
561
  }
557
562
  break;
558
-
563
+
559
564
  case "stamp_campaign":
560
565
  {
561
566
  Flyy.openFlyyStampsPage();
562
567
  }
563
568
  break;
564
-
569
+
565
570
  case "campaign_home":
566
571
  {
567
572
  Flyy.openFlyyStampsPage();
568
573
  }
569
574
  break;
570
-
575
+
571
576
  case "bonanza_details":
572
577
  {
573
578
  Flyy.openFlyyBonanzaPage();
@@ -635,7 +640,7 @@ export const FlyyStories = ({
635
640
  break;
636
641
  default:
637
642
  // Toast.showWithGravity("ACTION NOT FOUND", Toast.SHORT, Toast.BOTTOM);
638
-
643
+ Alert.alert("ACTION NOT FOUND");
639
644
  }
640
645
  }
641
646
 
@@ -675,7 +680,7 @@ export const FlyyStories = ({
675
680
  }}
676
681
  numberOfLines={2}
677
682
  >
678
- {data.title}
683
+ {data.title}
679
684
  </Text>
680
685
  </View>
681
686
  <View style={{ height: 10 }} />
@@ -690,5 +695,5 @@ export const FlyyStories = ({
690
695
  renderItem={({ item }) => <StoriesItem data={item} />}
691
696
  keyExtractor={item => item.id}
692
697
  />
693
- </View>);
698
+ </View>);
694
699
  }