Skip to content

Commit

Permalink
1.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
nickpatrick committed Nov 21, 2017
1 parent fc51663 commit 8304e75
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 12 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,17 @@ Radar.stopTracking();

You only need to call these methods once, as these settings will be persisted across app sessions.

To listen for events and errors, you can add event listeners:
To listen for events, location updates, and errors, you can add event listeners:

```js
Radar.on('events', (result) => {
// do something with result.events, result.user
});

Radar.on('location', (result) => {
// do something with result.location, result.user
});

Radar.on('error', (err) => {
// do something with err
});
Expand All @@ -162,6 +166,8 @@ You can also remove event listeners:
```js
Radar.off('events');

Radar.off('location');

Radar.off('error');
```

Expand Down
43 changes: 34 additions & 9 deletions android/src/main/java/com/onradar/react/RNRadarReceiver.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.onradar.react;

import android.content.Context;
import android.location.Location;
import android.support.annotation.NonNull;

import com.facebook.react.ReactApplication;
Expand Down Expand Up @@ -45,22 +46,46 @@ public void onReactContextInitialized(ReactContext reactContext) {

@Override
public void onEventsReceived(@NonNull Context context, @NonNull RadarEvent[] events, @NonNull RadarUser user) {
ReactApplication reactApplication = ((ReactApplication)context.getApplicationContext());
mReactNativeHost = reactApplication.getReactNativeHost();
try {
ReactApplication reactApplication = ((ReactApplication)context.getApplicationContext());
mReactNativeHost = reactApplication.getReactNativeHost();

WritableMap map = Arguments.createMap();
map.putArray("events", RNRadarUtils.arrayForEvents(events));
map.putMap("user", RNRadarUtils.mapForUser(user));
WritableMap map = Arguments.createMap();
map.putArray("events", RNRadarUtils.arrayForEvents(events));
map.putMap("user", RNRadarUtils.mapForUser(user));

sendEvent("events", map);
sendEvent("events", map);
} catch (Exception e) {

}
}

@Override
public void onLocationUpdated(@NonNull Context context, @NonNull Location location, @NonNull RadarUser user) {
try {
ReactApplication reactApplication = ((ReactApplication)context.getApplicationContext());
mReactNativeHost = reactApplication.getReactNativeHost();

WritableMap map = Arguments.createMap();
map.putMap("location", RNRadarUtils.mapForLocation(location));
map.putMap("user", RNRadarUtils.mapForUser(user));

sendEvent("location", map);
} catch (Exception e) {

}
}

@Override
public void onError(@NonNull Context context, @NonNull Radar.RadarStatus status) {
ReactApplication reactApplication = ((ReactApplication)context.getApplicationContext());
mReactNativeHost = reactApplication.getReactNativeHost();
try {
ReactApplication reactApplication = ((ReactApplication)context.getApplicationContext());
mReactNativeHost = reactApplication.getReactNativeHost();

sendEvent("error", RNRadarUtils.stringForStatus(status));
sendEvent("error", RNRadarUtils.stringForStatus(status));
} catch (Exception e) {

}
}

}
8 changes: 7 additions & 1 deletion ios/RNRadar.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ - (instancetype)init {
}

- (NSArray<NSString *> *)supportedEvents {
return @[@"events", @"error"];
return @[@"events", @"location", @"error"];
}

- (void)startObserving {
Expand All @@ -38,6 +38,12 @@ - (void)didReceiveEvents:(NSArray<RadarEvent *> *)events user:(RadarUser *)user
}
}

- (void)didUpdateLocation:(CLLocation *)location user:(RadarUser *)user {
if (hasListeners) {
[self sendEventWithName:@"location" body:@{@"location": [RNRadarUtils dictionaryForLocation:location], @"user": [RNRadarUtils dictionaryForUser:user]}];
}
}

- (void)didFailWithStatus:(RadarStatus)status {
if (hasListeners) {
[self sendEventWithName:@"error" body:[RNRadarUtils stringForStatus:status]];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "React Native module for Radar, the location platform for mobile apps",
"homepage": "https://www.onradar.com",
"license": "Apache-2.0",
"version": "1.0.10",
"version": "1.0.11",
"main": "js/index.js",
"dependencies": {},
"peerDependencies": {
Expand Down

0 comments on commit 8304e75

Please sign in to comment.