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

Issue 915: Stop/start Location manager based on listeners registered. #999

Merged
merged 16 commits into from
Oct 2, 2020

Conversation

soumyashisPR
Copy link
Contributor

@soumyashisPR soumyashisPR commented Aug 23, 2020

Issue: react-native-mapbox-gl https://github.com/react-native-mapbox-gl/maps/issues/915
This issue was caused by UserLocation component as it was stopping the locationManager, which can be shared by other UserLocation instances.

Fix:
'UserLocation' should only add/remove its listener on 'locationManager' service and never start or stop it. It the responsibility of the locationManager to start or stop itself depending on the number of listeners registered.

  1. Removed code to start/stop locationManager from UserLocation component.
  2. Added code to start/stop the LocationManager within LocationManager component itself, based on number of listeners registered at the moment.

EDIT ferdicus:
resolves #915

@soumyashisPR
Copy link
Contributor Author

@mfazekas Would you be able to have a look at the PR?
Thanks.

Copy link
Contributor

@mfazekas mfazekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks, nice work.
It would be great if you could summarise the issues fixed with the changes.

There are also some rename, which is not backward compatible. If the new names are better i'm all for it, but we must keep old versions working and showing a deprecation alert.

docs/UserLocation.md Show resolved Hide resolved
javascript/components/UserLocation.js Show resolved Hide resolved
if (!this._listeners.includes(listener)) {
this._listeners.push(listener);

if (this._lastKnownLocation) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this removed?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change reverted.
Reason for removing this, I was trying to keep addListener() and the method call listener() independent, but didn't work out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mfazekas Please let me know if any more changes are required with this PR.
Thanks.

Copy link
Member

@ferdicus ferdicus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this, just added some comments.

Besides fixing failing tests it would be great if you would kindly add additional tests covering your changes.

🙇

__tests__/components/UserLocation.test.js Outdated Show resolved Hide resolved
javascript/components/UserLocation.js Outdated Show resolved Hide resolved
@ferdicus
Copy link
Member

@soumyashisPR, did you find the time to check the review comments?

Thanks 🙇

@soumyashisPR
Copy link
Contributor Author

Hey @ferdicus , have addressed the review comments. Let me know if there are further changes required.
Currently stuck with some failing unit tests and unable to figure out the issue there.
Would be great if I could get some help / guidance.
Thanks

if (running) {
locationManager.start();

const location = await locationManager.getLastKnownLocation();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this the last time around, I think you can remove getLastKnownLocation then from locationManager as it's not being used anymore?

Copy link
Contributor Author

@soumyashisPR soumyashisPR Sep 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this is actually being used in setLocationManager
if (running) { locationManager.addListener(this._onLocationUpdate); const location = await locationManager.getLastKnownLocation(); this._onLocationUpdate(location); } else { locationManager.removeListener(this._onLocationUpdate); }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean... yeah, now it does after you reverted it again :)

@ferdicus
Copy link
Member

Hey @ferdicus , have addressed the review comments. Let me know if there are further changes required.
Currently stuck with some failing unit tests and unable to figure out the issue there.
Would be great if I could get some help / guidance.
Thanks

Thanks @soumyashisPR, can you please address all comments. 🙇

Also, what seems to be the issue with the unit tests?
Could you be more specific?

Thanks again

@systemlevel
Copy link
Contributor

systemlevel commented Sep 22, 2020

Is this PR going to create an issue for us who don't want the Location Manager running at all?

For example, we are unmounting the <UserLocation /> when we don't want the location manager to run at all when the app is in the background, inactive, or active.

@soumyashisPR
Copy link
Contributor Author

soumyashisPR commented Sep 22, 2020

Is this PR going to create an issue for us who don't want the Location Manager running at all?

For example, we are unmounting the <UserLocation /> when we don't want the location manager to run at all when the app is in the background, inactive, or active.

Hey @systemlevel, according to the PR, unmounting <UserLocation /> will stop it from listening to the locationManager, it won't stop the location manager, unless it was the only <UserLocation />listening to the location manager, in which case locationManger would stop.
Same applies for when <UserLocation /> is mounted, it will start listening to locationManager, and location manager is started if not already started.

@soumyashisPR
Copy link
Contributor Author

Hey @ferdicus , have addressed the review comments. Let me know if there are further changes required.
Currently stuck with some failing unit tests and unable to figure out the issue there.
Would be great if I could get some help / guidance.
Thanks

Thanks @soumyashisPR, can you please address all comments. 🙇

Also, what seems to be the issue with the unit tests?
Could you be more specific?

Thanks again

Nevermind, the issue with unit tests is fixed.

Thanks.

@@ -80,7 +81,7 @@ describe('LocationManager', () => {
expect(locationManager._listeners).toStrictEqual([myListener]);
});

test('does not readd same listener', () => {
test('does not read same listener', () => {
Copy link
Contributor

@mfazekas mfazekas Oct 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 're-add' make more sense here

Suggested change
test('does not read same listener', () => {
test('does not readd same listener', () => {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Member

@ferdicus ferdicus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @soumyashisPR for this PR and sorry it took a while :)

Lets get this out the door 🚪

@ferdicus ferdicus merged commit 9404ec4 into rnmapbox:master Oct 2, 2020
mzu pushed a commit to mzu/maps that referenced this pull request Nov 2, 2020
…rnmapbox#999)

* Fixed doc descriptions for Camera

* Fixed documentation for Camera

* Maps: location manager start/stop listening fix

* Remove commented lines

* Reaname boolean fields for UserLocation

* fix unit tests

* Fix unit  test cases for location manager

* Fix userlocation test

* Add modified docs

* PR review comment addressed

* PR review comment addressed

* PR review commit - reverted renames

* Fix unit test

* typo fix for read to re-add
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UserLocation stops update when an other UserLocation is unmounted
4 participants