Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BackgroundGeolocation onGeofence calling multiple times causing performance issue #1999

Closed
SAPLMobileDev opened this issue Apr 17, 2024 · 6 comments
Labels

Comments

@SAPLMobileDev
Copy link

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

@christocracy
Copy link
Member

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
Copy link
Author

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

image (2)
image (3)

@christocracy
Copy link
Member

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

@SAPLMobileDev
Copy link
Author

SAPLMobileDev commented Apr 18, 2024

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

Copy link

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

@github-actions github-actions bot added the stale label May 19, 2024
Copy link

github-actions bot commented Jun 2, 2024

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

@github-actions github-actions bot closed this as completed Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants