Add null Activity check in PlayServicesLocationManager.getCurrentLocationData #220
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR addresses issue #217 in which app is crashing probably because activity returned by
mReactContext.getCurrentActivity()
is null.As suggested in my comment #217 (comment) I added a null check in PlayServicesLocationManager.getCurrentLocationData.
If currentActivity is returned as null, we invoke the
error
callback with a new PositionError (ACTIVITY_NULL
), and then justreturn
to end the method execution.Questions
I added the new
ACTIVITY_NULL
error to the PositionError class. But this is not a position error, more some underlying Android/React Native error (I don't know 😅). Adding this to PositionError is quick and easy, but to be precise and clean it would make sense to put it in another class, eg.UnexpectedError
or something like that..Also this breaks the so called "feature parity with iOS", and makes the
GeolocationError
TypeScript type inaccurate.Any thoughts on that?
At first I tried to call the error callback with
emitError
, but the error was not reaching the JS. So I changed toerror.invoke
, and then the error was reaching the JS. I see that you made changes to how the error callback is called in the last two commit (741a353, 362bf80), and I am wondering if these changes are maybe a mistake?Unrelated: I tried to run the e2e tests, but noticed the script does not exist in package.json. Maybe CONTRIBUTING.md should be updated?
Test Plan
I added the changes in my app with a patch and then hardcoded
to make sure that the null check was working and that the error was reaching the JS, which it did.
Then, I changed it back to what it's supposed to be
and made sure the location data was reaching the JS, which it did.