react-native-radar 3.5.5 → 3.5.7

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.
@@ -18,7 +18,7 @@ android {
18
18
  minSdkVersion 16
19
19
  targetSdkVersion 31
20
20
  versionCode 1
21
- versionName '3.5.5'
21
+ versionName '3.5.7'
22
22
  }
23
23
  lintOptions {
24
24
  abortOnError false
@@ -39,6 +39,7 @@ import org.json.JSONException;
39
39
  import org.json.JSONObject;
40
40
 
41
41
  import java.util.EnumSet;
42
+ import java.util.Map;
42
43
 
43
44
  public class RNRadarModule extends ReactContextBaseJavaModule implements PermissionListener {
44
45
 
@@ -78,16 +79,54 @@ public class RNRadarModule extends ReactContextBaseJavaModule implements Permiss
78
79
  Radar.setUserId(userId);
79
80
  }
80
81
 
82
+ @ReactMethod
83
+ public void getUserId(final Promise promise) {
84
+ if (promise == null) {
85
+ return;
86
+ }
87
+
88
+ promise.resolve(Radar.getUserId());
89
+ }
90
+
81
91
  @ReactMethod
82
92
  public void setDescription(String description) {
83
93
  Radar.setDescription(description);
84
94
  }
85
95
 
96
+ @ReactMethod
97
+ public void getDescription(final Promise promise) {
98
+ if (promise == null) {
99
+ return;
100
+ }
101
+
102
+ promise.resolve(Radar.getDescription());
103
+ }
104
+
86
105
  @ReactMethod
87
106
  public void setMetadata(ReadableMap metadataMap) throws JSONException {
88
107
  Radar.setMetadata(RNRadarUtils.jsonForMap(metadataMap));
89
108
  }
90
109
 
110
+ @ReactMethod
111
+ public void getMetadata(final Promise promise) throws JSONException {
112
+ if (promise == null) {
113
+ return;
114
+ }
115
+
116
+ JSONObject metaJson = Radar.getMetadata();
117
+ promise.resolve(RNRadarUtils.mapForJson(metaJson));
118
+ }
119
+
120
+ @ReactMethod
121
+ public void setAnonymousTrackingEnabled(boolean enabled) {
122
+ Radar.setAnonymousTrackingEnabled(enabled);
123
+ }
124
+
125
+ @ReactMethod
126
+ public void setAdIdEnabled(boolean enabled) {
127
+ Radar.setAdIdEnabled(enabled);
128
+ }
129
+
91
130
  @ReactMethod
92
131
  public void getPermissionsStatus(final Promise promise) {
93
132
  if (promise == null) {
@@ -146,8 +185,22 @@ public class RNRadarModule extends ReactContextBaseJavaModule implements Permiss
146
185
  }
147
186
 
148
187
  @ReactMethod
149
- public void getLocation(final Promise promise) {
150
- Radar.getLocation(new Radar.RadarLocationCallback() {
188
+ public void getLocation(String desiredAccuracy, final Promise promise) {
189
+
190
+ RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy accuracyLevel = RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM;
191
+ String accuracy = desiredAccuracy != null ? desiredAccuracy.toLowerCase() : "medium";
192
+
193
+ if (accuracy.equals("low")) {
194
+ accuracyLevel = RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.LOW;
195
+ } else if (accuracy.equals("medium")) {
196
+ accuracyLevel = RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.MEDIUM;
197
+ } else if (accuracy.equals("high")) {
198
+ accuracyLevel = RadarTrackingOptions.RadarTrackingOptionsDesiredAccuracy.HIGH;
199
+ } else {
200
+ promise.reject(Radar.RadarStatus.ERROR_BAD_REQUEST.toString(), Radar.RadarStatus.ERROR_BAD_REQUEST.toString());
201
+ }
202
+
203
+ Radar.getLocation(accuracyLevel, new Radar.RadarLocationCallback() {
151
204
  @Override
152
205
  public void onComplete(@NonNull Radar.RadarStatus status, @Nullable Location location, boolean stopped) {
153
206
  if (promise == null) {
@@ -312,6 +365,29 @@ public class RNRadarModule extends ReactContextBaseJavaModule implements Permiss
312
365
  Radar.stopTracking();
313
366
  }
314
367
 
368
+ @ReactMethod
369
+ public void isTracking(final Promise promise) {
370
+ if (promise == null) {
371
+ return;
372
+ }
373
+
374
+ promise.resolve(Radar.isTracking());
375
+ }
376
+
377
+ @ReactMethod
378
+ public void getTrackingOptions(final Promise promise) {
379
+ if (promise == null) {
380
+ return;
381
+ }
382
+ try {
383
+ RadarTrackingOptions options = Radar.getTrackingOptions();
384
+ promise.resolve(RNRadarUtils.mapForJson(options.toJson()));
385
+ } catch(JSONException e) {
386
+ Log.e(TAG, "JSONException", e);
387
+ promise.reject(Radar.RadarStatus.ERROR_SERVER.toString(), Radar.RadarStatus.ERROR_SERVER.toString());
388
+ }
389
+ }
390
+
315
391
  @ReactMethod
316
392
  public void setForegroundServiceOptions(ReadableMap optionsMap) {
317
393
  try {
@@ -333,6 +409,20 @@ public class RNRadarModule extends ReactContextBaseJavaModule implements Permiss
333
409
  Radar.rejectEvent(eventId);
334
410
  }
335
411
 
412
+ @ReactMethod
413
+ public void getTripOptions(final Promise promise) {
414
+ if (promise == null) {
415
+ return;
416
+ }
417
+ try {
418
+ RadarTripOptions options = Radar.getTripOptions();
419
+ promise.resolve(options != null ? RNRadarUtils.mapForJson(options.toJson()) : null);
420
+ } catch(JSONException e) {
421
+ Log.e(TAG, "JSONException", e);
422
+ promise.reject(Radar.RadarStatus.ERROR_SERVER.toString(), Radar.RadarStatus.ERROR_SERVER.toString());
423
+ }
424
+ }
425
+
336
426
  @ReactMethod
337
427
  public void startTrip(ReadableMap optionsMap, final Promise promise) {
338
428
  try {
@@ -578,6 +668,7 @@ public class RNRadarModule extends ReactContextBaseJavaModule implements Permiss
578
668
  }
579
669
  int radius = optionsMap.hasKey("radius") ? optionsMap.getInt("radius") : 1000;
580
670
  String[] chains = optionsMap.hasKey("chains") ? RNRadarUtils.stringArrayForArray(optionsMap.getArray("chains")) : null;
671
+ Map<String, String> chainMetadata = RNRadarUtils.stringStringMap(optionsMap.getMap("chainMetadata"));
581
672
  String[] categories = optionsMap.hasKey("categories") ? RNRadarUtils.stringArrayForArray(optionsMap.getArray("categories")) : null;
582
673
  String[] groups = optionsMap.hasKey("groups") ? RNRadarUtils.stringArrayForArray(optionsMap.getArray("groups")) : null;
583
674
  int limit = optionsMap.hasKey("limit") ? optionsMap.getInt("limit") : 10;
@@ -607,9 +698,9 @@ public class RNRadarModule extends ReactContextBaseJavaModule implements Permiss
607
698
  };
608
699
 
609
700
  if (near != null) {
610
- Radar.searchPlaces(near, radius, chains, categories, groups, limit, callback);
701
+ Radar.searchPlaces(near, radius, chains, chainMetadata, categories, groups, limit, callback);
611
702
  } else {
612
- Radar.searchPlaces(radius, chains, categories, groups, limit, callback);
703
+ Radar.searchPlaces(radius, chains, chainMetadata, categories, groups, limit, callback);
613
704
  }
614
705
  }
615
706
 
@@ -984,4 +1075,39 @@ public class RNRadarModule extends ReactContextBaseJavaModule implements Permiss
984
1075
  });
985
1076
  }
986
1077
 
1078
+ @ReactMethod
1079
+ public void sendEvent(String customType, ReadableMap metadata, final Promise promise) throws JSONException {
1080
+ if (promise == null) {
1081
+ return;
1082
+ }
1083
+
1084
+ JSONObject metadataObj = RNRadarUtils.jsonForMap(metadata);
1085
+ Radar.sendEvent(customType, metadataObj, new Radar.RadarSendEventCallback() {
1086
+ @Override
1087
+ public void onComplete(@NonNull Radar.RadarStatus status, @Nullable Location location, @Nullable RadarEvent[] events, @Nullable RadarUser user) {
1088
+ try {
1089
+ if (status == Radar.RadarStatus.SUCCESS) {
1090
+ WritableMap map = Arguments.createMap();
1091
+ map.putString("status", status.toString());
1092
+ if (location != null) {
1093
+ map.putMap("location", RNRadarUtils.mapForJson(Radar.jsonForLocation(location)));
1094
+ }
1095
+ if (events != null) {
1096
+ map.putArray("events", RNRadarUtils.arrayForJson(RadarEvent.toJson(events)));
1097
+ }
1098
+ if (user != null) {
1099
+ map.putMap("user", RNRadarUtils.mapForJson(user.toJson()));
1100
+ }
1101
+ promise.resolve(map);
1102
+ } else {
1103
+ promise.reject(status.toString(), status.toString());
1104
+ }
1105
+ } catch (JSONException e) {
1106
+ Log.e(TAG, "JSONException", e);
1107
+ promise.reject(Radar.RadarStatus.ERROR_SERVER.toString(), Radar.RadarStatus.ERROR_SERVER.toString());
1108
+ }
1109
+ }
1110
+ });
1111
+ }
1112
+
987
1113
  }
@@ -3,6 +3,8 @@ package io.radar.react;
3
3
  import com.facebook.react.bridge.ReadableArray;
4
4
  import com.facebook.react.bridge.ReadableMapKeySetIterator;
5
5
  import java.util.Iterator;
6
+ import java.util.Map;
7
+ import java.util.HashMap;
6
8
 
7
9
  import org.json.JSONArray;
8
10
  import org.json.JSONException;
@@ -148,5 +150,18 @@ class RNRadarUtils {
148
150
  }
149
151
  return arr;
150
152
  }
153
+ static Map<String, String> stringStringMap(ReadableMap readableMap) {
154
+ if (readableMap == null) {
155
+ return null;
156
+ }
157
+
158
+ Map<String, String> stringMap = new HashMap<String, String>();
159
+ ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
160
+ while (iterator.hasNextKey()) {
161
+ String key = iterator.nextKey();
162
+ stringMap.put(key, readableMap.getString(key));
163
+ }
164
+ return stringMap;
165
+ }
151
166
 
152
167
  }
package/ios/RNRadar.m CHANGED
@@ -111,14 +111,34 @@ RCT_EXPORT_METHOD(setUserId:(NSString *)userId) {
111
111
  [Radar setUserId:userId];
112
112
  }
113
113
 
114
+ RCT_EXPORT_METHOD(getUserId:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
115
+ resolve([Radar getUserId]);
116
+ }
117
+
114
118
  RCT_EXPORT_METHOD(setDescription:(NSString *)description) {
115
119
  [Radar setDescription:description];
116
120
  }
117
121
 
122
+ RCT_EXPORT_METHOD(getDescription:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
123
+ resolve([Radar getDescription]);
124
+ }
125
+
118
126
  RCT_EXPORT_METHOD(setMetadata:(NSDictionary *)metadataDict) {
119
127
  [Radar setMetadata:metadataDict];
120
128
  }
121
129
 
130
+ RCT_EXPORT_METHOD(getMetadata:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
131
+ resolve([Radar getMetadata]);
132
+ }
133
+
134
+ RCT_EXPORT_METHOD(setAnonymousTrackingEnabled:(BOOL)enabled) {
135
+ [Radar setAnonymousTrackingEnabled:enabled];
136
+ }
137
+
138
+ RCT_EXPORT_METHOD(setAdIdEnabled:(BOOL)enabled) {
139
+ [Radar setAdIdEnabled:enabled];
140
+ }
141
+
122
142
  RCT_REMAP_METHOD(getPermissionsStatus, getPermissionsStatusWithResolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
123
143
  CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
124
144
  NSString *statusStr;
@@ -158,11 +178,29 @@ RCT_EXPORT_METHOD(requestPermissions:(BOOL)background resolve:(RCTPromiseResolve
158
178
  }
159
179
  }
160
180
 
161
- RCT_EXPORT_METHOD(getLocation:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
181
+ RCT_EXPORT_METHOD(getLocation:(NSString *)desiredAccuracy resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
162
182
  __block RCTPromiseResolveBlock resolver = resolve;
163
183
  __block RCTPromiseRejectBlock rejecter = reject;
184
+ RadarTrackingOptionsDesiredAccuracy accuracy = RadarTrackingOptionsDesiredAccuracyMedium;
185
+
186
+ if (desiredAccuracy) {
187
+ NSString *lowerAccuracy = [desiredAccuracy lowercaseString];
188
+ if ([lowerAccuracy isEqualToString:@"high"]) {
189
+ accuracy = RadarTrackingOptionsDesiredAccuracyHigh;
190
+ } else if ([lowerAccuracy isEqualToString:@"medium"]) {
191
+ accuracy = RadarTrackingOptionsDesiredAccuracyMedium;
192
+ } else if ([lowerAccuracy isEqualToString:@"low"]) {
193
+ accuracy = RadarTrackingOptionsDesiredAccuracyLow;
194
+ } else {
195
+ if (reject) {
196
+ reject([Radar stringForStatus:RadarStatusErrorBadRequest], [Radar stringForStatus:RadarStatusErrorBadRequest], nil);
197
+ }
198
+
199
+ return;
200
+ }
201
+ }
164
202
 
165
- [Radar getLocationWithCompletionHandler:^(RadarStatus status, CLLocation * _Nullable location, BOOL stopped) {
203
+ [Radar getLocationWithDesiredAccuracy:accuracy completionHandler:^(RadarStatus status, CLLocation * _Nullable location, BOOL stopped) {
166
204
  if (status == RadarStatusSuccess && resolver) {
167
205
  NSMutableDictionary *dict = [NSMutableDictionary new];
168
206
  [dict setObject:[Radar stringForStatus:status] forKey:@"status"];
@@ -307,6 +345,20 @@ RCT_EXPORT_METHOD(stopTracking) {
307
345
  [Radar stopTracking];
308
346
  }
309
347
 
348
+ RCT_EXPORT_METHOD(isTracking:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
349
+ BOOL res = [Radar isTracking];
350
+ resolve(@(res));
351
+ }
352
+
353
+ RCT_EXPORT_METHOD(getTrackingOptions:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
354
+ if (resolve == nil) {
355
+ return;
356
+ }
357
+
358
+ RadarTrackingOptions* options = [Radar getTrackingOptions];
359
+ resolve([options dictionaryValue]);
360
+ }
361
+
310
362
  RCT_EXPORT_METHOD(setForegroundServiceOptions) {
311
363
  // not implemented
312
364
  }
@@ -319,8 +371,20 @@ RCT_EXPORT_METHOD(rejectEvent:(NSString *)eventId) {
319
371
  [Radar rejectEventId:eventId];
320
372
  }
321
373
 
374
+ RCT_EXPORT_METHOD(getTripOptions:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
375
+ if (resolve == nil) {
376
+ return;
377
+ }
378
+
379
+ RadarTripOptions* options = [Radar getTripOptions];
380
+ resolve([options dictionaryValue]);
381
+ }
382
+
322
383
  RCT_EXPORT_METHOD(startTrip:(NSDictionary *)optionsDict resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
323
384
  RadarTripOptions *options = [RadarTripOptions tripOptionsFromDictionary:optionsDict];
385
+ if (options.scheduledArrivalAt) {
386
+ options.scheduledArrivalAt = [RCTConvert NSDate:options.scheduledArrivalAt];
387
+ }
324
388
 
325
389
  __block RCTPromiseResolveBlock resolver = resolve;
326
390
  __block RCTPromiseRejectBlock rejecter = reject;
@@ -516,6 +580,7 @@ RCT_EXPORT_METHOD(searchPlaces:(NSDictionary *)optionsDict resolve:(RCTPromiseRe
516
580
  radius = 1000;
517
581
  }
518
582
  NSArray *chains = optionsDict[@"chains"];
583
+ NSDictionary *chainMetadata = optionsDict[@"chainMetadata"];
519
584
  NSArray *categories = optionsDict[@"categories"];
520
585
  NSArray *groups = optionsDict[@"groups"];
521
586
  NSNumber *limitNumber = optionsDict[@"limit"];
@@ -548,9 +613,9 @@ RCT_EXPORT_METHOD(searchPlaces:(NSDictionary *)optionsDict resolve:(RCTPromiseRe
548
613
  };
549
614
 
550
615
  if (near) {
551
- [Radar searchPlacesNear:near radius:radius chains:chains categories:categories groups:groups limit:limit completionHandler:completionHandler];
616
+ [Radar searchPlacesNear:near radius:radius chains:chains chainMetadata:chainMetadata categories:categories groups:groups limit:limit completionHandler:completionHandler];
552
617
  } else {
553
- [Radar searchPlacesWithRadius:radius chains:chains categories:categories groups:groups limit:limit completionHandler:completionHandler];
618
+ [Radar searchPlacesWithRadius:radius chains:chains chainMetadata:chainMetadata categories:categories groups:groups limit:limit completionHandler:completionHandler];
554
619
  }
555
620
  }
556
621
 
@@ -889,4 +954,29 @@ RCT_EXPORT_METHOD(getMatrix:(NSDictionary *)optionsDict resolve:(RCTPromiseResol
889
954
  }];
890
955
  }
891
956
 
957
+ RCT_EXPORT_METHOD(sendEvent:(NSString*) customType metadata:(NSDictionary *)metadata resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
958
+ __block RCTPromiseResolveBlock resolver = resolve;
959
+ __block RCTPromiseRejectBlock rejecter = reject;
960
+
961
+ [Radar sendEvent:customType withMetadata:metadata completionHandler:^(RadarStatus status, CLLocation * _Nullable location, NSArray<RadarEvent *> * _Nullable events, RadarUser * _Nullable user) {
962
+ if (status == RadarStatusSuccess && resolver) {
963
+ NSMutableDictionary *dict = [NSMutableDictionary new];
964
+ [dict setObject:[Radar stringForStatus:status] forKey:@"status"];
965
+ if (location) {
966
+ [dict setObject:[Radar dictionaryForLocation:location] forKey:@"location"];
967
+ }
968
+ if (events) {
969
+ [dict setObject:[RadarEvent arrayForEvents:events] forKey:@"events"];
970
+ }
971
+ if (user) {
972
+ [dict setObject:[user dictionaryValue] forKey:@"user"];
973
+ }
974
+ resolver(dict);
975
+ } else if (rejecter) {
976
+ rejecter([Radar stringForStatus:status], [Radar stringForStatus:status], nil);
977
+ }
978
+ resolver = nil;
979
+ rejecter = nil;
980
+ }];
981
+ }
892
982
  @end
package/js/index.js CHANGED
@@ -1,184 +1,9 @@
1
- import { NativeEventEmitter, NativeModules } from 'react-native';
1
+ import { Platform } from 'react-native';
2
2
 
3
- if (!NativeModules.RNRadar) {
4
- throw new Error('NativeModules.RNRadar is undefined');
5
- }
3
+ let module = {};
4
+ if (Platform.OS === 'web')
5
+ module = require('./index.web').default;
6
+ else
7
+ module = require('./index.native').default;
6
8
 
7
- const eventEmitter = new NativeEventEmitter(NativeModules.RNRadar);
8
-
9
- const setLogLevel = (level) => {
10
- NativeModules.RNRadar.setLogLevel(level);
11
- };
12
-
13
- const setUserId = (userId) => {
14
- NativeModules.RNRadar.setUserId(userId);
15
- };
16
-
17
- const setDescription = (description) => {
18
- NativeModules.RNRadar.setDescription(description);
19
- };
20
-
21
- const setMetadata = (metadata) => {
22
- NativeModules.RNRadar.setMetadata(metadata);
23
- };
24
-
25
- const getPermissionsStatus = () => (
26
- NativeModules.RNRadar.getPermissionsStatus()
27
- );
28
-
29
- const requestPermissions = background => (
30
- NativeModules.RNRadar.requestPermissions(background)
31
- );
32
-
33
- const getLocation = () => (
34
- NativeModules.RNRadar.getLocation()
35
- );
36
-
37
- const trackOnce = options => {
38
- let backCompatibleOptions = options;
39
- if (options && options.latitude) {
40
- backCompatibleOptions = {
41
- location: {
42
- ...options
43
- }
44
- }
45
- }
46
- return NativeModules.RNRadar.trackOnce(backCompatibleOptions)
47
- };
48
-
49
- const startTrackingEfficient = () => (
50
- NativeModules.RNRadar.startTrackingEfficient()
51
- );
52
-
53
- const startTrackingResponsive = () => (
54
- NativeModules.RNRadar.startTrackingResponsive()
55
- );
56
-
57
- const startTrackingContinuous = () => (
58
- NativeModules.RNRadar.startTrackingContinuous()
59
- );
60
-
61
- const startTrackingCustom = options => (
62
- NativeModules.RNRadar.startTrackingCustom(options)
63
- );
64
-
65
- const mockTracking = options => (
66
- NativeModules.RNRadar.mockTracking(options)
67
- );
68
-
69
- const stopTracking = () => (
70
- NativeModules.RNRadar.stopTracking()
71
- );
72
-
73
- const setForegroundServiceOptions = options => (
74
- NativeModules.RNRadar.setForegroundServiceOptions(options)
75
- );
76
-
77
- const startTrip = options => (
78
- NativeModules.RNRadar.startTrip(options)
79
- );
80
-
81
- const completeTrip = () => (
82
- NativeModules.RNRadar.completeTrip()
83
- );
84
-
85
- const cancelTrip = () => (
86
- NativeModules.RNRadar.cancelTrip()
87
- );
88
-
89
- const updateTrip = options => (
90
- NativeModules.RNRadar.updateTrip(options)
91
- );
92
-
93
- const acceptEvent = (eventId, verifiedPlaceId) => (
94
- NativeModules.RNRadar.acceptEvent(eventId, verifiedPlaceId)
95
- );
96
-
97
- const rejectEvent = eventId => (
98
- NativeModules.RNRadar.rejectEvent(eventId)
99
- );
100
-
101
- const getContext = location => (
102
- NativeModules.RNRadar.getContext(location)
103
- );
104
-
105
- const searchPlaces = options => (
106
- NativeModules.RNRadar.searchPlaces(options)
107
- );
108
-
109
- const searchGeofences = options => (
110
- NativeModules.RNRadar.searchGeofences(options)
111
- );
112
-
113
- const autocomplete = options => (
114
- NativeModules.RNRadar.autocomplete(options)
115
- );
116
-
117
- const geocode = address => (
118
- NativeModules.RNRadar.geocode(address)
119
- );
120
-
121
- const reverseGeocode = location => (
122
- NativeModules.RNRadar.reverseGeocode(location)
123
- );
124
-
125
- const ipGeocode = () => (
126
- NativeModules.RNRadar.ipGeocode()
127
- );
128
-
129
- const getDistance = options => (
130
- NativeModules.RNRadar.getDistance(options)
131
- );
132
-
133
- const getMatrix = options => (
134
- NativeModules.RNRadar.getMatrix(options)
135
- );
136
-
137
- const on = (event, callback) => (
138
- eventEmitter.addListener(event, callback)
139
- );
140
-
141
- const off = (event, callback) => {
142
- if (callback) {
143
- eventEmitter.removeListener(event, callback);
144
- } else {
145
- eventEmitter.removeAllListeners(event);
146
- }
147
- };
148
-
149
- const Radar = {
150
- setLogLevel,
151
- setUserId,
152
- setDescription,
153
- setMetadata,
154
- getPermissionsStatus,
155
- requestPermissions,
156
- getLocation,
157
- trackOnce,
158
- startTrackingEfficient,
159
- startTrackingResponsive,
160
- startTrackingContinuous,
161
- startTrackingCustom,
162
- mockTracking,
163
- stopTracking,
164
- setForegroundServiceOptions,
165
- acceptEvent,
166
- rejectEvent,
167
- startTrip,
168
- updateTrip,
169
- completeTrip,
170
- cancelTrip,
171
- getContext,
172
- searchPlaces,
173
- searchGeofences,
174
- autocomplete,
175
- geocode,
176
- reverseGeocode,
177
- ipGeocode,
178
- getDistance,
179
- getMatrix,
180
- on,
181
- off,
182
- };
183
-
184
- export default Radar;
9
+ export default module;
@@ -0,0 +1,229 @@
1
+ import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
2
+
3
+ if (!NativeModules.RNRadar && (Platform.OS === 'ios' || Platform.OS === 'android')) {
4
+ throw new Error('NativeModules.RNRadar is undefined');
5
+ }
6
+
7
+ const eventEmitter = new NativeEventEmitter(NativeModules.RNRadar);
8
+
9
+ const setLogLevel = (level) => {
10
+ NativeModules.RNRadar.setLogLevel(level);
11
+ };
12
+
13
+ const setUserId = (userId) => {
14
+ NativeModules.RNRadar.setUserId(userId);
15
+ };
16
+
17
+ const getUserId = () => (
18
+ NativeModules.RNRadar.getUserId()
19
+ );
20
+
21
+ const setDescription = (description) => {
22
+ NativeModules.RNRadar.setDescription(description);
23
+ };
24
+
25
+ const getDescription = () => (
26
+ NativeModules.RNRadar.getDescription()
27
+ );
28
+
29
+ const setMetadata = (metadata) => {
30
+ NativeModules.RNRadar.setMetadata(metadata);
31
+ };
32
+
33
+ const getMetadata = () => (
34
+ NativeModules.RNRadar.getMetadata()
35
+ )
36
+
37
+ const setAnonymousTrackingEnabled = (enabled) => (
38
+ NativeModules.RNRadar.setAnonymousTrackingEnabled(enabled)
39
+ )
40
+
41
+ const setAdIdEnabled = (enabled) => (
42
+ NativeModules.RNRadar.setAdIdEnabled(enabled)
43
+ )
44
+
45
+ const getPermissionsStatus = () => (
46
+ NativeModules.RNRadar.getPermissionsStatus()
47
+ );
48
+
49
+ const requestPermissions = background => (
50
+ NativeModules.RNRadar.requestPermissions(background)
51
+ );
52
+
53
+ const getLocation = desiredAccuracy => (
54
+ NativeModules.RNRadar.getLocation(desiredAccuracy)
55
+ );
56
+
57
+ const trackOnce = options => {
58
+ let backCompatibleOptions = options;
59
+ if (options && options.latitude) {
60
+ backCompatibleOptions = {
61
+ location: {
62
+ ...options
63
+ }
64
+ }
65
+ }
66
+ return NativeModules.RNRadar.trackOnce(backCompatibleOptions)
67
+ };
68
+
69
+ const startTrackingEfficient = () => (
70
+ NativeModules.RNRadar.startTrackingEfficient()
71
+ );
72
+
73
+ const startTrackingResponsive = () => (
74
+ NativeModules.RNRadar.startTrackingResponsive()
75
+ );
76
+
77
+ const startTrackingContinuous = () => (
78
+ NativeModules.RNRadar.startTrackingContinuous()
79
+ );
80
+
81
+ const startTrackingCustom = options => (
82
+ NativeModules.RNRadar.startTrackingCustom(options)
83
+ );
84
+
85
+ const mockTracking = options => (
86
+ NativeModules.RNRadar.mockTracking(options)
87
+ );
88
+
89
+ const stopTracking = () => (
90
+ NativeModules.RNRadar.stopTracking()
91
+ );
92
+
93
+ const getTrackingOptions = () => (
94
+ NativeModules.RNRadar.getTrackingOptions()
95
+ )
96
+
97
+ const isTracking = () => (
98
+ NativeModules.RNRadar.isTracking()
99
+ )
100
+
101
+ const setForegroundServiceOptions = options => (
102
+ NativeModules.RNRadar.setForegroundServiceOptions(options)
103
+ );
104
+
105
+ const getTripOptions = () => (
106
+ NativeModules.RNRadar.getTripOptions()
107
+ )
108
+
109
+ const startTrip = options => (
110
+ NativeModules.RNRadar.startTrip(options)
111
+ );
112
+
113
+ const completeTrip = () => (
114
+ NativeModules.RNRadar.completeTrip()
115
+ );
116
+
117
+ const cancelTrip = () => (
118
+ NativeModules.RNRadar.cancelTrip()
119
+ );
120
+
121
+ const updateTrip = options => (
122
+ NativeModules.RNRadar.updateTrip(options)
123
+ );
124
+
125
+ const acceptEvent = (eventId, verifiedPlaceId) => (
126
+ NativeModules.RNRadar.acceptEvent(eventId, verifiedPlaceId)
127
+ );
128
+
129
+ const rejectEvent = eventId => (
130
+ NativeModules.RNRadar.rejectEvent(eventId)
131
+ );
132
+
133
+ const getContext = location => (
134
+ NativeModules.RNRadar.getContext(location)
135
+ );
136
+
137
+ const searchPlaces = options => (
138
+ NativeModules.RNRadar.searchPlaces(options)
139
+ );
140
+
141
+ const searchGeofences = options => (
142
+ NativeModules.RNRadar.searchGeofences(options)
143
+ );
144
+
145
+ const autocomplete = options => (
146
+ NativeModules.RNRadar.autocomplete(options)
147
+ );
148
+
149
+ const geocode = address => (
150
+ NativeModules.RNRadar.geocode(address)
151
+ );
152
+
153
+ const reverseGeocode = location => (
154
+ NativeModules.RNRadar.reverseGeocode(location)
155
+ );
156
+
157
+ const ipGeocode = () => (
158
+ NativeModules.RNRadar.ipGeocode()
159
+ );
160
+
161
+ const getDistance = options => (
162
+ NativeModules.RNRadar.getDistance(options)
163
+ );
164
+
165
+ const getMatrix = options => (
166
+ NativeModules.RNRadar.getMatrix(options)
167
+ );
168
+
169
+ const sendEvent = (customType, metadata) => (
170
+ NativeModules.RNRadar.sendEvent(customType, metadata)
171
+ )
172
+
173
+ const on = (event, callback) => (
174
+ eventEmitter.addListener(event, callback)
175
+ );
176
+
177
+ const off = (event, callback) => {
178
+ if (callback) {
179
+ eventEmitter.removeListener(event, callback);
180
+ } else {
181
+ eventEmitter.removeAllListeners(event);
182
+ }
183
+ };
184
+
185
+ const Radar = {
186
+ setLogLevel,
187
+ setUserId,
188
+ getUserId,
189
+ setDescription,
190
+ getDescription,
191
+ setMetadata,
192
+ getMetadata,
193
+ setAnonymousTrackingEnabled,
194
+ setAdIdEnabled,
195
+ getPermissionsStatus,
196
+ requestPermissions,
197
+ getLocation,
198
+ trackOnce,
199
+ startTrackingEfficient,
200
+ startTrackingResponsive,
201
+ startTrackingContinuous,
202
+ startTrackingCustom,
203
+ mockTracking,
204
+ stopTracking,
205
+ isTracking,
206
+ getTrackingOptions,
207
+ setForegroundServiceOptions,
208
+ acceptEvent,
209
+ rejectEvent,
210
+ getTripOptions,
211
+ startTrip,
212
+ updateTrip,
213
+ completeTrip,
214
+ cancelTrip,
215
+ getContext,
216
+ searchPlaces,
217
+ searchGeofences,
218
+ autocomplete,
219
+ geocode,
220
+ reverseGeocode,
221
+ ipGeocode,
222
+ getDistance,
223
+ getMatrix,
224
+ sendEvent,
225
+ on,
226
+ off,
227
+ };
228
+
229
+ export default Radar;
@@ -0,0 +1,400 @@
1
+ import RadarJS from 'radar-sdk-js';
2
+
3
+ const initialize = (publishableKey) => {
4
+ RadarJS.initialize(publishableKey);
5
+ }
6
+
7
+ const setLogLevel = (level) => {
8
+ // not implemented
9
+ };
10
+
11
+ const setUserId = (userId) => {
12
+ RadarJS.setUserId(userId);
13
+ };
14
+
15
+ const setDeviceId = (deviceId, installId) => {
16
+ RadarJS.setDeviceId(deviceId, installId);
17
+ }
18
+ const setDeviceType = (deviceType) => {
19
+ RadarJS.setDeviceType(deviceType);
20
+ }
21
+
22
+ const setRequestHeaders = (headers) => {
23
+ RadarJS.setRequestHeaders(headers);
24
+ }
25
+
26
+ const setDescription = (description) => {
27
+ RadarJS.setDescription(description);
28
+ };
29
+
30
+ const setMetadata = (metadata) => {
31
+ RadarJS.setMetadata(metadata);
32
+ };
33
+
34
+ const getPermissionsStatus = () => {
35
+ return new Promise(resolve => {
36
+ const navigator = window.navigator;
37
+
38
+ if (!navigator.permissions) {
39
+ resolve({
40
+ status: 'UNKNOWN'
41
+ });
42
+ } else {
43
+ navigator.permissions.query({ name: 'geolocation' }).then((result) => {
44
+ resolve({
45
+ status: result.state === 'granted' ? 'GRANTED_FOREGROUND' : 'DENIED',
46
+ });
47
+ });
48
+ }
49
+ });
50
+ };
51
+
52
+ const requestPermissions = background => {
53
+ // not implemented
54
+ };
55
+
56
+ const getLocation = () => {
57
+ return new Promise((resolve, reject) => {
58
+ RadarJS.getLocation((err, result) => {
59
+ if (err)
60
+ reject(err);
61
+ else
62
+ resolve(result);
63
+ })
64
+ });
65
+ };
66
+
67
+ const trackOnce = options => {
68
+ return new Promise((resolve, reject) => {
69
+ const callback = (err, { status, location, user, events }) => {
70
+ if (err) {
71
+ reject(err);
72
+ } else {
73
+ resolve({
74
+ status,
75
+ location,
76
+ user,
77
+ events,
78
+ });
79
+ }
80
+ };
81
+
82
+ if (options) {
83
+ RadarJS.trackOnce(options.location ? options.location : options, callback);
84
+ } else {
85
+ RadarJS.trackOnce(callback);
86
+ }
87
+ });
88
+ };
89
+
90
+ const startTrackingEfficient = () => {
91
+ // not implemented
92
+ };
93
+
94
+ const startTrackingResponsive = () => {
95
+ // not implemented
96
+ };
97
+
98
+ const startTrackingContinuous = () => {
99
+ // not implemented
100
+ };
101
+
102
+ const startTrackingCustom = options => {
103
+ // not implemented
104
+ };
105
+
106
+ const mockTracking = options => {
107
+ // not implemented
108
+ };
109
+
110
+ const stopTracking = () => {
111
+ // not implemented
112
+ };
113
+
114
+ const setForegroundServiceOptions = options => {
115
+ // not implemented
116
+ };
117
+
118
+ const startTrip = options => {
119
+ return new Promise((resolve, reject) => {
120
+ const callback = (err, { trip, events, status }) => {
121
+ if (err) {
122
+ reject(err);
123
+ } else {
124
+ resolve({
125
+ trip,
126
+ events,
127
+ status
128
+ });
129
+ }
130
+ };
131
+
132
+ RadarJS.startTrip(options, callback);
133
+ });
134
+ };
135
+
136
+ const completeTrip = () => {
137
+ return new Promise((resolve, reject) => {
138
+ const callback = (err, { trip, events, status }) => {
139
+ if (err) {
140
+ reject(err);
141
+ } else {
142
+ resolve({
143
+ trip,
144
+ events,
145
+ status
146
+ });
147
+ }
148
+ };
149
+
150
+ RadarJS.completeTrip(callback);
151
+ });
152
+ };
153
+
154
+ const cancelTrip = () => {
155
+ return new Promise((resolve, reject) => {
156
+ const callback = (err, { trip, events, status }) => {
157
+ if (err) {
158
+ reject(err);
159
+ } else {
160
+ resolve({
161
+ trip,
162
+ events,
163
+ status
164
+ });
165
+ }
166
+ };
167
+
168
+ RadarJS.cancelTrip(callback);
169
+ });
170
+ };
171
+
172
+ const updateTrip = (tripOptions) => {
173
+ return new Promise((resolve, reject) => {
174
+ const callback = (err, { trip, events, status }) => {
175
+ if (err) {
176
+ reject(err);
177
+ } else {
178
+ resolve({
179
+ trip,
180
+ events,
181
+ status
182
+ });
183
+ }
184
+ };
185
+
186
+ RadarJS.updateTrip(tripOptions.options, tripOptions.status, callback);
187
+ });
188
+ };
189
+
190
+ const acceptEvent = (eventId, verifiedPlaceId) => {
191
+ // not implemented
192
+ };
193
+
194
+ const rejectEvent = eventId => {
195
+ // not implemented
196
+ };
197
+
198
+ const getContext = options => {
199
+ return new Promise((resolve, reject) => {
200
+ const callback = (err, { status, location, context }) => {
201
+ if (err) {
202
+ reject(err);
203
+ } else {
204
+ resolve({
205
+ status,
206
+ location,
207
+ context,
208
+ });
209
+ }
210
+ };
211
+
212
+ if (options) {
213
+ RadarJS.getContext(options, callback);
214
+ } else {
215
+ RadarJS.getContext(callback);
216
+ }
217
+ });
218
+ };
219
+
220
+ const searchPlaces = options => {
221
+ return new Promise((resolve, reject) => {
222
+ RadarJS.searchPlaces(options, (err, { status, location, places }) => {
223
+ if (err) {
224
+ reject(err);
225
+ } else {
226
+ resolve({
227
+ status,
228
+ location,
229
+ places,
230
+ });
231
+ }
232
+ });
233
+ });
234
+ };
235
+
236
+ const searchGeofences = options => {
237
+ return new Promise((resolve, reject) => {
238
+ RadarJS.searchGeofences(options, (err, { status, location, geofences }) => {
239
+ if (err) {
240
+ reject(err);
241
+ } else {
242
+ resolve({
243
+ status,
244
+ location,
245
+ geofences,
246
+ });
247
+ }
248
+ });
249
+ });
250
+ };
251
+
252
+ const autocomplete = options => {
253
+ return new Promise((resolve, reject) => {
254
+ RadarJS.autocomplete(options, (err, { status, addresses }) => {
255
+ if (err) {
256
+ reject(err);
257
+ } else {
258
+ resolve({
259
+ status,
260
+ addresses,
261
+ });
262
+ }
263
+ });
264
+ });
265
+ };
266
+
267
+ const geocode = options => {
268
+ return new Promise((resolve, reject) => {
269
+ let newOptions = options;
270
+ if (typeof options === 'string')
271
+ newOptions = {
272
+ query: options
273
+ };
274
+
275
+ RadarJS.geocode(newOptions, (err, { status, addresses }) => {
276
+ if (err) {
277
+ reject(err);
278
+ } else {
279
+ resolve({
280
+ status,
281
+ addresses,
282
+ });
283
+ }
284
+ });
285
+ });
286
+ };
287
+
288
+ const reverseGeocode = options => {
289
+ return new Promise((resolve, reject) => {
290
+ const callback = (err, { status, addresses }) => {
291
+ if (err) {
292
+ reject(err);
293
+ } else {
294
+ resolve({
295
+ status,
296
+ addresses,
297
+ });
298
+ }
299
+ };
300
+
301
+ if (options) {
302
+ RadarJS.reverseGeocode(options, callback);
303
+ } else {
304
+ RadarJS.reverseGeocode(callback);
305
+ }
306
+ });
307
+ };
308
+
309
+ const ipGeocode = () => {
310
+ return new Promise((resolve, reject) => {
311
+ RadarJS.ipGeocode((err, { status, address }) => {
312
+ if (err) {
313
+ reject(err);
314
+ } else {
315
+ resolve({
316
+ status,
317
+ address,
318
+ });
319
+ }
320
+ });
321
+ });
322
+ };
323
+
324
+ const getDistance = options => {
325
+ return new Promise((resolve, reject) => {
326
+ RadarJS.getDistance(options, (err, { status, routes }) => {
327
+ if (err) {
328
+ reject(err);
329
+ } else {
330
+ resolve({
331
+ status,
332
+ routes,
333
+ });
334
+ }
335
+ });
336
+ });
337
+ };
338
+
339
+ const getMatrix = options => {
340
+ return new Promise((resolve, reject) => {
341
+ RadarJS.getMatrix(options, (err, { origins, destinations, matrix, status }) => {
342
+ if (err) {
343
+ reject(err);
344
+ } else {
345
+ resolve({
346
+ origins,
347
+ destinations,
348
+ matrix,
349
+ status,
350
+ });
351
+ }
352
+ });
353
+ });
354
+ };
355
+
356
+ const on = (event, callback) => {
357
+ // not implemented
358
+ };
359
+
360
+ const off = (event, callback) => {
361
+ // not implemented
362
+ };
363
+
364
+ const Radar = {
365
+ initialize,
366
+ setLogLevel,
367
+ setUserId,
368
+ setDescription,
369
+ setMetadata,
370
+ getPermissionsStatus,
371
+ requestPermissions,
372
+ getLocation,
373
+ trackOnce,
374
+ startTrackingEfficient,
375
+ startTrackingResponsive,
376
+ startTrackingContinuous,
377
+ startTrackingCustom,
378
+ mockTracking,
379
+ stopTracking,
380
+ setForegroundServiceOptions,
381
+ acceptEvent,
382
+ rejectEvent,
383
+ startTrip,
384
+ updateTrip,
385
+ completeTrip,
386
+ cancelTrip,
387
+ getContext,
388
+ searchPlaces,
389
+ searchGeofences,
390
+ autocomplete,
391
+ geocode,
392
+ reverseGeocode,
393
+ ipGeocode,
394
+ getDistance,
395
+ getMatrix,
396
+ on,
397
+ off,
398
+ };
399
+
400
+ export default Radar;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "React Native module for Radar, the leading geofencing and location tracking platform",
4
4
  "homepage": "https://radar.com",
5
5
  "license": "Apache-2.0",
6
- "version": "3.5.5",
6
+ "version": "3.5.7",
7
7
  "main": "js/index.js",
8
8
  "files": [
9
9
  "android",
@@ -48,7 +48,8 @@
48
48
  "metro-react-native-babel-preset": "^0.51.1",
49
49
  "npm-run-all": "^4.1.5",
50
50
  "react": "16.8.6",
51
- "react-native": "0.60.0"
51
+ "react-native": "0.60.0",
52
+ "radar-sdk-js": "^3.3.0"
52
53
  },
53
54
  "bugs": {
54
55
  "url": "https://github.com/radarlabs/react-native-radar/issues"