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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.FlyyStories = exports.FlyyWidget = exports.FlyyCheckinView = exports.default = void 0;
6
+ exports.FlyyStories = exports.FlyyWidget = exports.FlyyFloatingWidget = exports.FlyyCheckinView = exports.default = void 0;
7
7
 
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
 
@@ -11,6 +11,10 @@ var _reactNative = require("react-native");
11
11
 
12
12
  var _flyy_checkin_view = _interopRequireDefault(require("./flyy_checkin_view"));
13
13
 
14
+ var _asyncStorage = _interopRequireDefault(require("@react-native-async-storage/async-storage"));
15
+
16
+ var _reactNativeDraggable = _interopRequireDefault(require("react-native-draggable"));
17
+
14
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
19
 
16
20
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -43,214 +47,249 @@ exports.FlyyCheckinView = FlyyCheckinView;
43
47
  const windowHeight = _reactNative.Dimensions.get('window').height;
44
48
 
45
49
  const windowWidth = _reactNative.Dimensions.get('window').width; // ****** Flyy Floating Widget ******
46
- // export const FlyyFloatingWidget = ({
47
- // props = {
48
- // backgroundColor: "#654EA3",
49
- // buttonHeight: 55,
50
- // buttonWidth: 55,
51
- // buttonCornerRadius: 40,
52
- // buttonIcon: require('./assets/images/rewardwidget.png'),
53
- // onPress: () => { },
54
- // x: windowWidth - 75,
55
- // y: windowHeight - 100,
56
- // minX: 5,
57
- // minY: 5,
58
- // maxX: windowWidth - 5,
59
- // maxY: windowHeight - 5,
60
- // show: true,
61
- // stick: false,
62
- // startDate: 0,
63
- // endDate: 0
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 - 100);
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
- // useEffect(()=>{
79
- // fetchData();
80
- // },[]);
81
- // const fetchData = async() => {
82
- // const sdkInfo = await Flyy.getUserData();
83
- // const appData = await Flyy.getAppData();
84
- // const resp = await fetch(`https://${sdkInfo["environment"] == 0 ? "ghc-stage" : "ghc"}.theflyy.com/api/v8/flyy_app_info`, {
85
- // headers: {
86
- // "X-Key": sdkInfo["partner_id"],
87
- // "Content-Type": "application/json",
88
- // "X-App-Data": appData
89
- // }
90
- // });
91
- // data = await resp.json();
92
- // if(!data.success){
93
- // if (Platform.OS === 'android') {
94
- // ToastAndroid.show(data.message, ToastAndroid.SHORT);
95
- // } else {
96
- // // Toast.showWithGravity(data.message, Toast.SHORT, Toast.BOTTOM);
97
- // }
98
- // return;
99
- // }
100
- // const widgetConfig = data.info.floating_widget_configuration;
101
- // if (widgetConfig.icon_url != null && widgetConfig.icon_url != '') {
102
- // setIconUrl({ uri: widgetConfig.icon_url })
103
- // } else {
104
- // setIconUrl(props.buttonIcon)
105
- // }
106
- // if (widgetConfig.color != null && widgetConfig.color != '') {
107
- // setBackgroundColor(widgetConfig.color)
108
- // } else {
109
- // setBackgroundColor(props.backgroundColor)
110
- // }
111
- // if (widgetConfig.size != null && widgetConfig.color != 0) {
112
- // setButtonSize(parseInt(data.info.floating_widget_configuration.size))
113
- // } else {
114
- // setButtonSize(props.buttonHeight)
115
- // }
116
- // //FloatingButton Position
117
- // if (widgetConfig.position == "bottom_left") {
118
- // setButtonXPosition(10)
119
- // } else if (widgetConfig.position == "bottom_right") {
120
- // setButtonXPosition(windowWidth - 75)
121
- // } else if (widgetConfig.position == "upper_left") {
122
- // setButtonXPosition(10)
123
- // if (Platform.OS === 'android'){
124
- // setButtonYPosition(10)
125
- // }else{
126
- // setButtonYPosition(50)
127
- // }
128
- // } else if (widgetConfig.position == "upper_right") {
129
- // setButtonXPosition(windowWidth - 75)
130
- // if (Platform.OS === 'android'){
131
- // setButtonYPosition(10)
132
- // }else{
133
- // setButtonYPosition(50)
134
- // }
135
- // }
136
- // //Set DeepLink
137
- // if (widgetConfig.deeplink != null && widgetConfig.deeplink != "") {
138
- // setDeeplink(widgetConfig.deeplink)
139
- // }
140
- // //Set Visibility of FloatingButton
141
- // var currentDate = new Date();
142
- // const getDate = await AsyncStorage.getItem(flyyConfigDate);
143
- // const userId = await AsyncStorage.getItem(flyyConfigUserId);
144
- // var date = new Date(parseInt(getDate));
145
- // const diffTime = Math.abs(getDate - currentDate);
146
- // const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))-1;
147
- // if(diffDays != 0 || userId == null || userId != sdkInfo[flyyConfigUserId]){
148
- // var data = await Flyy.getAppOccurence(1);
149
- // await AsyncStorage.setItem(
150
- // flyyConfigUserId,
151
- // sdkInfo[flyyConfigUserId]
152
- // );
153
- // }
154
- // const occurrenceCount = await Flyy.getAppOccurence(0);
155
- // if (widgetConfig.show_to_user && occurrenceCount <= parseInt(widgetConfig.num_times)) {
156
- // // var numberOfDaysToAdd = widgetConfig.num_days+1;
157
- // // var result = currentDate.setDate(currentDate.getDate() + numberOfDaysToAdd);
158
- // if(getDate === null || userId == null || userId != sdkInfo[flyyConfigUserId]){
159
- // await AsyncStorage.setItem(
160
- // flyyConfigDate,
161
- // JSON.stringify(currentDate.getTime())
162
- // );
163
- // }
164
- // const getDate2 = await AsyncStorage.getItem(flyyConfigDate);
165
- // var date = new Date(parseInt(getDate2));
166
- // const diffTime = Math.abs(getDate2 - currentDate);
167
- // const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))-1;
168
- // //Show widget on same day
169
- // if(diffDays === 0 || diffDays === -1){
170
- // setShowWidget(true)
171
- // }else{
172
- // //reset occurrence on next day
173
- // await Flyy.getAppOccurence(1);
174
- // if(diffDays >= parseInt(widgetConfig.num_days)+1){
175
- // await AsyncStorage.setItem(
176
- // flyyConfigDate,
177
- // JSON.stringify(currentDate.getTime())
178
- // );
179
- // setShowWidget(true)
180
- // }
181
- // }
182
- // }else{
183
- // setShowWidget(false);
184
- // const getDate2 = await AsyncStorage.getItem(flyyConfigDate);
185
- // var date = new Date(parseInt(getDate2));
186
- // const diffTime = Math.abs(getDate2 - currentDate);
187
- // const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
188
- // if(diffDays != 1){
189
- // var data = await Flyy.getAppOccurence(1);
190
- // }
191
- // }
192
- // }
193
- // // if(props.show){
194
- // // if(props.startDate != null && props.startDate != 0){
195
- // // var now = new Date().getTime();
196
- // // if(now >= props.startDate && now <= props.endDate){
197
- // // props.show = true
198
- // // }else{
199
- // // props.show = false
200
- // // }
201
- // // }
202
- // // }
203
- // // AppState.addEventListener('change', state =>{
204
- // // console.log('AppState updated to', AppState.currentState)
205
- // // oldState = currentState;
206
- // // currentState = state;
207
- // // if(oldState == null){
208
- // // console.log('App is newly start :::')
209
- // // }})
210
- // return (
211
- // // @ts-ignore
212
- // props.show && showWidget? <Draggable x={buttonXPosition}
213
- // y={buttonYPosition}
214
- // minX={props.minX ?? 5}
215
- // minY={props.minY ?? 5}
216
- // maxX={props.maxX ?? windowWidth - 5}
217
- // maxY={props.maxY ?? windowHeight - 5}
218
- // renderSize={56}
219
- // // shouldReverse = {true}
220
- // onDragRelease={props.stick ? () => {
221
- // } : null} isCircle>
222
- // <TouchableOpacity
223
- // onPress={deeplink != null ? async()=>{
224
- // if (Platform.OS === 'android' || !deeplink.startsWith("flyy://")) {
225
- // const supported = await Linking.canOpenURL(deeplink);
226
- // await Linking.openURL(deeplink);
227
- // } else {
228
- // navigateTo(deeplink);
229
- // }
230
- // }:props.onPress}
231
- // style={{
232
- // height: buttonSize,
233
- // width: buttonSize,
234
- // backgroundColor: backgroundColor,
235
- // borderRadius: buttonSize/2,
236
- // justifyContent: 'center',
237
- // alignItems: 'center',
238
- // }}>
239
- // <Image source={iconUrl} style={{ height: buttonSize*55/100, width: buttonSize*55/100 }} />
240
- // <TouchableOpacity
241
- // onPress={()=>{
242
- // props.show = false;
243
- // setShowWidget(false);
244
- // }}
245
- // style = {{height: 20, width: 20, backgroundColor: "transparent",position:'absolute',left:buttonSize-11, bottom: buttonSize*72/100}}>
246
- // <Image source={require('./assets/images/xmark.png')} style={{ height: 18, width: 18, tintColor: "black"}} />
247
- // </TouchableOpacity>
248
- // </TouchableOpacity>
249
- // </Draggable> : <View/>
250
- // );
251
- // }
252
50
 
253
51
 
52
+ const FlyyFloatingWidget = ({
53
+ props = {
54
+ backgroundColor: "#654EA3",
55
+ buttonHeight: 55,
56
+ buttonWidth: 55,
57
+ buttonCornerRadius: 40,
58
+ buttonIcon: require('./assets/images/rewardwidget.png'),
59
+ onPress: () => {},
60
+ x: windowWidth - 75,
61
+ y: windowHeight - 100,
62
+ minX: 5,
63
+ minY: 5,
64
+ maxX: windowWidth - 5,
65
+ maxY: windowHeight - 5,
66
+ show: true,
67
+ stick: false,
68
+ startDate: 0,
69
+ endDate: 0
70
+ }
71
+ }) => {
72
+ var _props$minX, _props$minY, _props$maxX, _props$maxY;
73
+
74
+ const [showWidget, setShowWidget] = (0, _react.useState)(false);
75
+ const [userData, setUserData] = (0, _react.useState)({});
76
+ const [iconUrl, setIconUrl] = (0, _react.useState)(require('./assets/images/rewardwidget.png'));
77
+ const [backgroundColor, setBackgroundColor] = (0, _react.useState)("#654EA3");
78
+ const [buttonSize, setButtonSize] = (0, _react.useState)(55);
79
+ const [buttonXPosition, setButtonXPosition] = (0, _react.useState)(windowWidth - 75);
80
+ const [buttonYPosition, setButtonYPosition] = (0, _react.useState)(windowHeight - 200);
81
+ const [deeplink, setDeeplink] = (0, _react.useState)(null);
82
+ const flyyConfigDate = "flyy_config_date";
83
+ const flyyConfigUserId = "user_id";
84
+ var oldState = null;
85
+ var currentState = null;
86
+ var data = null;
87
+ (0, _react.useEffect)(() => {
88
+ fetchData();
89
+ }, []);
90
+
91
+ const fetchData = async () => {
92
+ const sdkInfo = await Flyy.getUserData();
93
+ const appData = await Flyy.getAppData();
94
+ const resp = await fetch(`https://${sdkInfo["environment"] == 0 ? "ghc-stage" : "ghc"}.theflyy.com/api/v8/flyy_app_info`, {
95
+ headers: {
96
+ "X-Key": sdkInfo["partner_id"],
97
+ "Content-Type": "application/json",
98
+ "X-App-Data": appData
99
+ }
100
+ });
101
+ data = await resp.json();
102
+
103
+ if (!data.success) {
104
+ if (Platform.OS === 'android') {
105
+ _reactNative.ToastAndroid.show(data.message, _reactNative.ToastAndroid.SHORT);
106
+ } else {
107
+ // Toast.showWithGravity(data.message, Toast.SHORT, Toast.BOTTOM);
108
+ _reactNative.Alert.alert(data.message);
109
+ }
110
+
111
+ return;
112
+ }
113
+
114
+ const widgetConfig = data.info.floating_widget_configuration;
115
+
116
+ if (widgetConfig.icon_url != null && widgetConfig.icon_url != '') {
117
+ setIconUrl({
118
+ uri: widgetConfig.icon_url
119
+ });
120
+ } else {
121
+ setIconUrl(props.buttonIcon);
122
+ }
123
+
124
+ if (widgetConfig.color != null && widgetConfig.color != '') {
125
+ setBackgroundColor(widgetConfig.color);
126
+ } else {
127
+ setBackgroundColor(props.backgroundColor);
128
+ }
129
+
130
+ if (widgetConfig.size != null && widgetConfig.color != 0) {
131
+ setButtonSize(parseInt(data.info.floating_widget_configuration.size));
132
+ } else {
133
+ setButtonSize(props.buttonHeight);
134
+ } //FloatingButton Position
135
+
136
+
137
+ if (widgetConfig.position == "bottom_left") {
138
+ setButtonXPosition(10);
139
+ } else if (widgetConfig.position == "bottom_right") {
140
+ setButtonXPosition(windowWidth - 75);
141
+ } else if (widgetConfig.position == "upper_left") {
142
+ setButtonXPosition(10);
143
+
144
+ if (Platform.OS === 'android') {
145
+ setButtonYPosition(10);
146
+ } else {
147
+ setButtonYPosition(50);
148
+ }
149
+ } else if (widgetConfig.position == "upper_right") {
150
+ setButtonXPosition(windowWidth - 75);
151
+
152
+ if (Platform.OS === 'android') {
153
+ setButtonYPosition(10);
154
+ } else {
155
+ setButtonYPosition(50);
156
+ }
157
+ } //Set DeepLink
158
+
159
+
160
+ if (widgetConfig.deeplink != null && widgetConfig.deeplink != "") {
161
+ setDeeplink(widgetConfig.deeplink);
162
+ } //Set Visibility of FloatingButton
163
+
164
+
165
+ var currentDate = new Date();
166
+ const getDate = await _asyncStorage.default.getItem(flyyConfigDate);
167
+ const userId = await _asyncStorage.default.getItem(flyyConfigUserId);
168
+ var date = new Date(parseInt(getDate));
169
+ const diffTime = Math.abs(getDate - currentDate);
170
+ const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) - 1;
171
+
172
+ if (diffDays != 0 || userId == null || userId != sdkInfo[flyyConfigUserId]) {
173
+ var data = await Flyy.getAppOccurence(1);
174
+ await _asyncStorage.default.setItem(flyyConfigUserId, sdkInfo[flyyConfigUserId]);
175
+ }
176
+
177
+ const occurrenceCount = await Flyy.getAppOccurence(0);
178
+
179
+ if (widgetConfig.show_to_user && occurrenceCount <= parseInt(widgetConfig.num_times)) {
180
+ // var numberOfDaysToAdd = widgetConfig.num_days+1;
181
+ // var result = currentDate.setDate(currentDate.getDate() + numberOfDaysToAdd);
182
+ if (getDate === null || userId == null || userId != sdkInfo[flyyConfigUserId]) {
183
+ await _asyncStorage.default.setItem(flyyConfigDate, JSON.stringify(currentDate.getTime()));
184
+ }
185
+
186
+ const getDate2 = await _asyncStorage.default.getItem(flyyConfigDate);
187
+ var date = new Date(parseInt(getDate2));
188
+ const diffTime = Math.abs(getDate2 - currentDate);
189
+ const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) - 1; //Show widget on same day
190
+
191
+ if (diffDays === 0 || diffDays === -1) {
192
+ setShowWidget(true);
193
+ } else {
194
+ //reset occurrence on next day
195
+ await Flyy.getAppOccurence(1);
196
+
197
+ if (diffDays >= parseInt(widgetConfig.num_days) + 1) {
198
+ await _asyncStorage.default.setItem(flyyConfigDate, JSON.stringify(currentDate.getTime()));
199
+ setShowWidget(true);
200
+ }
201
+ }
202
+ } else {
203
+ setShowWidget(false);
204
+ const getDate2 = await _asyncStorage.default.getItem(flyyConfigDate);
205
+ var date = new Date(parseInt(getDate2));
206
+ const diffTime = Math.abs(getDate2 - currentDate);
207
+ const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
208
+
209
+ if (diffDays != 1) {
210
+ var data = await Flyy.getAppOccurence(1);
211
+ }
212
+ }
213
+ }; // if(props.show){
214
+ // if(props.startDate != null && props.startDate != 0){
215
+ // var now = new Date().getTime();
216
+ // if(now >= props.startDate && now <= props.endDate){
217
+ // props.show = true
218
+ // }else{
219
+ // props.show = false
220
+ // }
221
+ // }
222
+ // }
223
+ // AppState.addEventListener('change', state =>{
224
+ // console.log('AppState updated to', AppState.currentState)
225
+ // oldState = currentState;
226
+ // currentState = state;
227
+ // if(oldState == null){
228
+ // console.log('App is newly start :::')
229
+ // }})
230
+
231
+
232
+ return (// @ts-ignore
233
+ props.show && showWidget ? /*#__PURE__*/_react.default.createElement(_reactNativeDraggable.default, {
234
+ x: buttonXPosition,
235
+ y: buttonYPosition,
236
+ minX: (_props$minX = props.minX) !== null && _props$minX !== void 0 ? _props$minX : 5,
237
+ minY: (_props$minY = props.minY) !== null && _props$minY !== void 0 ? _props$minY : 5,
238
+ maxX: (_props$maxX = props.maxX) !== null && _props$maxX !== void 0 ? _props$maxX : windowWidth - 5,
239
+ maxY: (_props$maxY = props.maxY) !== null && _props$maxY !== void 0 ? _props$maxY : windowHeight - 5,
240
+ renderSize: 56 // shouldReverse = {true}
241
+ ,
242
+ onDragRelease: props.stick ? () => {} : null,
243
+ isCircle: true
244
+ }, /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
245
+ onPress: deeplink != null ? async () => {
246
+ if (Platform.OS === 'android' || !deeplink.startsWith("flyy://")) {
247
+ const supported = await _reactNative.Linking.canOpenURL(deeplink);
248
+ await _reactNative.Linking.openURL(deeplink);
249
+ } else {
250
+ navigateTo(deeplink);
251
+ }
252
+ } : props.onPress,
253
+ style: {
254
+ height: buttonSize,
255
+ width: buttonSize,
256
+ backgroundColor: backgroundColor,
257
+ borderRadius: buttonSize / 2,
258
+ justifyContent: 'center',
259
+ alignItems: 'center'
260
+ }
261
+ }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
262
+ source: iconUrl,
263
+ style: {
264
+ height: buttonSize * 55 / 100,
265
+ width: buttonSize * 55 / 100
266
+ }
267
+ }), /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
268
+ onPress: () => {
269
+ props.show = false;
270
+ setShowWidget(false);
271
+ },
272
+ style: {
273
+ height: 20,
274
+ width: 20,
275
+ backgroundColor: "transparent",
276
+ position: 'absolute',
277
+ left: buttonSize - 11,
278
+ bottom: buttonSize * 72 / 100
279
+ }
280
+ }, /*#__PURE__*/_react.default.createElement(_reactNative.Image, {
281
+ source: require('./assets/images/xmark.png'),
282
+ style: {
283
+ height: 18,
284
+ width: 18,
285
+ tintColor: "black"
286
+ }
287
+ })))) : /*#__PURE__*/_react.default.createElement(_reactNative.View, null)
288
+ );
289
+ };
290
+
291
+ exports.FlyyFloatingWidget = FlyyFloatingWidget;
292
+
254
293
  const navigateTo = deeplink => {
255
294
  let components = deeplink.split("/");
256
295
  let screenCode = components[components.length - 1];
@@ -364,7 +403,9 @@ const navigateTo = deeplink => {
364
403
  }
365
404
  break;
366
405
 
367
- default: // Toast.showWithGravity("ACTION NOT FOUND", Toast.SHORT, Toast.BOTTOM);
406
+ default:
407
+ // Toast.showWithGravity("ACTION NOT FOUND", Toast.SHORT, Toast.BOTTOM);
408
+ _reactNative.Alert.alert("ACTION NOT FOUND");
368
409
 
369
410
  }
370
411
  };
@@ -654,7 +695,9 @@ const FlyyStories = ({
654
695
  }
655
696
  break;
656
697
 
657
- default: // Toast.showWithGravity("ACTION NOT FOUND", Toast.SHORT, Toast.BOTTOM);
698
+ default:
699
+ // Toast.showWithGravity("ACTION NOT FOUND", Toast.SHORT, Toast.BOTTOM);
700
+ _reactNative.Alert.alert("ACTION NOT FOUND");
658
701
 
659
702
  }
660
703
  };