react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

BackgroundGeolocation onGeofence calling multiple times causing performance issue

Open SAPLMobileDev opened this issue 1 year ago • 5 comments

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

SAPLMobileDev avatar Apr 17 '24 09:04 SAPLMobileDev

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: ╚═════════════════════════════════════════════

christocracy avatar Apr 17 '24 13:04 christocracy

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

image (2) image (3)

SAPLMobileDev avatar Apr 18 '24 09:04 SAPLMobileDev

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

christocracy avatar Apr 18 '24 12:04 christocracy

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

SAPLMobileDev avatar Apr 18 '24 18:04 SAPLMobileDev

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar May 19 '24 01:05 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jun 02 '24 01:06 github-actions[bot]