react-native-flyy 1.4.33 → 1.4.35

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
@@ -15,7 +15,7 @@ import {
15
15
  } from 'react-native';
16
16
  import FlyyCheckinComponent from './flyy_checkin_view';
17
17
  import { FlyyStoriesWidget } from './flyy_stories';
18
- import AsyncStorage from '@react-native-async-storage/async-storage';
18
+ // import AsyncStorage from '@react-native-async-storage/async-storage';
19
19
  import Draggable from 'react-native-draggable';
20
20
 
21
21
  type FlyyType = {
@@ -42,225 +42,225 @@ const windowHeight = Dimensions.get('window').height;
42
42
  const windowWidth = Dimensions.get('window').width;
43
43
 
44
44
  // ****** Flyy Floating Widget ******
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
- }
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
+ // }
264
264
 
265
265
  const navigateTo = (deeplink) => {
266
266
  let components = deeplink.split("/");