eddieowens / react-native-boundary

Native implementation of geofencing/region monitoring

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Event Callbacks not firing: no listeners registered

adammacdonald opened this issue · comments

Boundaries are registered and will trip if I move in and out of a region, but the callbacks never fire and I receive a YellowBox warning stating
"Sending 'onEnter' with no listeners registered"

Im using:
iOS 12.1
Android 8.1
react-native-boundary 1.0.7
react-native 0.57.3

My test implementation is dead simple.

componentWillMount() {
  Boundary.on(Events.ENTER, () => console.log('Entered'));
  Boundary.on(Events.EXIT, () => console.log('Exited'));
}
componentWillUnmount() {
  Boundary.removeAll();
}

Any idea or direction would be appreciated.

Originally posted by @adammacdonald in #20 (comment)

Could it have something to do with the backgroundmodes capability in xcode?

@RWOverdijk – Having the same issue, what backgroundmodecapabillities are you supposed to run?

@RWOverdijk I wouldnt think so. Background Location Updates is already on, and these events still fire when the application is in the foreground however the callbacks are never registered.

@RWOverdijk – Found the issue in my case.
.removeAll is acutally clearing the event listners:
https://github.com/eddieowens/react-native-boundary/blob/master/index.js#L46

My case is that on app-focus i clear the boundaries and add new ones after requesting an API with fresh locations. This means that my global event listners is removed when my intention were to just remove the old boundaries.

in @adammacdonald ´s case I do not know why it do not work, but then again life cycle hooks in react-native can be fishy and after all .removeAll is called on unmount :)

I think it would be better to remove that row completly and simply implement an ".off" function to give users the possibility to remove the event listners manually if needed.

What do you think about that?

@mikaelengstrom you 100% nailed my issue as well. I made the assumption that removeAll simply removed the Boundaries that were defined...not the EventListeners as well.

I have the exact same use case as you.

Going to close this issue as it appears developer error, but maintainers may want to extend documentation or add an addtional method for handling cleanup.

@adammacdonald – Please reopen the issue, since there is no fix in place yet. This thread will serve as a good documentation to what needs to be done and why it was implemented when referenced in a pull request :)

@adammacdonald I'm not sure I understand what you want to happen in this case. You want removeAll to remove the boundaries but keep the event callbacks? If that's the case, why? And if the geofence is still tripping, that is certainly a bug. RNBoundary.removeAll() should remove every geofence.

@eddieowens I’m clearing them before registering new ones. If you have more boundaries than you can register in iOS you need to replace them depending on the users current location.

@eddieowens removeAll() does remove every geofence along with the listeners. I'm thinking there should be more flexibility in the removal. Something that allows you to replace the boundaries without removing the eventListeners because like @mikaelengstrom said...with 20 geofence limits on iOS they need to be updated based on the users location.

@eddieowens – Please review my PR and let me know if there is any room for improvement or if you have any concerns about the implementation: #29