Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions android/src/main/java/com/eddieowens/RNBoundaryModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
public class RNBoundaryModule extends ReactContextBaseJavaModule implements LifecycleEventListener {

public static final String TAG = "RNBoundary";
public static final String ON_ENTER = "onEnter";
public static final String ON_EXIT = "onExit";
public static final String GEOFENCE_DATA_TO_EMIT = "com.eddieowens.GEOFENCE_DATA_TO_EMIT";

private GeofencingClient mGeofencingClient;
private PendingIntent mBoundaryPendingIntent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,24 @@ protected void onHandleWork(@NonNull Intent intent) {
}
switch (geofencingEvent.getGeofenceTransition()) {
case Geofence.GEOFENCE_TRANSITION_ENTER:
Log.i(TAG, "Enter geofence event detected. Sending event.");
final ArrayList<String> enteredGeofences = new ArrayList<>();
for (Geofence geofence : geofencingEvent.getTriggeringGeofences()) {
enteredGeofences.add(geofence.getRequestId());
Log.i(TAG, "Enter geofence event detected. Sending event.");
sendEvent(this.getApplicationContext(), ON_ENTER, geofence.getRequestId());
}
sendEvent(this.getApplicationContext(), ON_ENTER, enteredGeofences);
break;
case Geofence.GEOFENCE_TRANSITION_EXIT:
Log.i(TAG, "Exit geofence event detected. Sending event.");
final ArrayList<String> exitingGeofences = new ArrayList<>();
for (Geofence geofence : geofencingEvent.getTriggeringGeofences()) {
exitingGeofences.add(geofence.getRequestId());
Log.i(TAG, "Exit geofence event detected. Sending event.");
sendEvent(this.getApplicationContext(), ON_EXIT, geofence.getRequestId());
}
sendEvent(this.getApplicationContext(), ON_EXIT, exitingGeofences);
break;
}
}

private void sendEvent(Context context, String event, ArrayList<String> params) {
final Intent intent = new Intent(RNBoundaryModule.GEOFENCE_DATA_TO_EMIT);
intent.putExtra("event", event);
intent.putExtra("params", params);

private void sendEvent(Context context, String event, String id) {
Bundle bundle = new Bundle();
bundle.putString("event", event);
bundle.putStringArrayList("ids", intent.getStringArrayListExtra("params"));
bundle.putString("id", id);

Intent headlessBoundaryIntent = new Intent(context, BoundaryEventHeadlessTaskService.class);
headlessBoundaryIntent.putExtras(bundle);
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export {
Events
}

const HeadlessBoundaryEventTask = async ({event, ids}) => {
console.log(event, ids);
boundaryEventEmitter.emit(event, ids)
const HeadlessBoundaryEventTask = async ({event, id}) => {
console.log(event, id);
boundaryEventEmitter.emit(event, id)
};

AppRegistry.registerHeadlessTask('OnBoundaryEvent', () => HeadlessBoundaryEventTask);
Expand Down