transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.54k stars 424 forks source link

BackgroundGeolocation onGeofence calling multiple times causing performance issue #1999

Open SAPLMobileDev opened 3 weeks ago

SAPLMobileDev commented 3 weeks ago

Your Environment

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
<!--- reproduce this issue; include code to reproduce, if relevant -->
1.
2.
3.
4.

## 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
<!-- include iOS / Android logs
- ios XCode logs,
- use #getLog #emailLog methods (@see docs)
- Android: $ adb logcat -s TSLocationManager
-->
<details><summary>Logs</summary>

``` <!-- Syntax highlighting:  DO NOT REMOVE -->

christocracy commented 3 weeks ago

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: ╚═════════════════════════════════════════════
SAPLMobileDev commented 3 weeks ago

Yes, we checked as you said but event is triggerd 8 times and 12 times

image (2) image (3)

christocracy commented 3 weeks ago

Show me more of your code. Where you’re adding/removing geofences and the specific attributes you’re providing your geofences.

SAPLMobileDev commented 3 weeks ago

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

Plotgeofence.txt

Usegeofence.txt

Geofence.txt