react-native-background-geolocation
react-native-background-geolocation copied to clipboard
BackgroundGeolocation onGeofence calling multiple times causing performance issue
Your Environment
- Plugin version: "react-native-background-geolocation": "^4.15.2"
- Platform: Android
- OS version: 10, 12
- Device manufacturer / model:
- React Native version (
react-native -v): "react-native": "0.73.2" - Plugin config
useEffect(() => {
console.log(`subscribe`);
subscribe(BackgroundGeolocation.onGeofence(setGeofenceEvent));
return () => {
// Important for with live-reload to remove BackgroundGeolocation event subscriptions.
unsubscribe();
clearMarkers();
};
}, []);
useEffect(() => {
if (!geofenceEvent) return;
const updatedGeofenceHitEvents = updateGeofenceHitEvents(geofenceEvent);
if (
updatedGeofenceHitEvents.length !== geofenceHitEvent.length ||
!updatedGeofenceHitEvents.every(
(newItem, index) =>
newItem.ShopId === geofenceHitEvent[index].ShopId &&
newItem.Action === geofenceHitEvent[index].Action,
)
) {
setGeofenceHitEvent(updatedGeofenceHitEvents);
}
}, [geofenceEvent]);
Expected Behavior
Same geofence identifier event should not trigger again.
Actual Behavior
same geofence identifier event getting called multiple times.
Steps to Reproduce
Context
We are first subscribing to the geofence events then we are applying our business logic into that but geofenceHitEvent getting update many times that causes useEffect to re render multiple time and causing performance issue
Debug logs
Logs
Observe the plugin's native logs with $ adb logcat *:S TSLocationManager:V.
Ensure the native geofence event fires just once. If it does, then the problem is within your own Javascript.
04-17 09:37:13.992 19996 14041 I TSLocationManager: [c.t.l.s.GeofencingService a]
04-17 09:37:13.992 19996 14041 I TSLocationManager: ╔═════════════════════════════════════════════
04-17 09:37:13.992 19996 14041 I TSLocationManager: ║ Geofencing Event: ENTER
04-17 09:37:13.992 19996 14041 I TSLocationManager: ╠═════════════════════════════════════════════
04-17 09:37:13.992 19996 14041 I TSLocationManager: ╟─ Home
04-17 09:37:13.992 19996 14041 I TSLocationManager: ╚═════════════════════════════════════════════
Yes, we checked as you said but event is triggerd 8 times and 12 times
Show me more of your code. Where you’re adding/removing geofences and the specific attributes you’re providing your geofences.
this are referance files, usegeofence :- custom hook Goefence:- first screen registration done from here for the library its a separate screen Plotgeofence:- screen where in db operation done and then passed to hook to register geofence
--TS files converted into TXT for upload
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.