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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add the reason for map camera movement #154

Merged
merged 5 commits into from Jun 23, 2022
Merged

Conversation

barbeau
Copy link
Contributor

@barbeau barbeau commented Jun 22, 2022

As discussed in #49, this PR exposes the reason value passed back in GoogleMap.OnCameraMoveStartedListener(int reason) callback so that developers can tell the reason that the camera started moving (e.g., user gesture, developer animation, API animation):
https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.OnCameraMoveStartedListener#onCameraMoveStarted(int)

For constant values see:
https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.OnCameraMoveStartedListener#constants

The PR also adds demo code to LocationTrackingActivity to print the reason that the camera moves, as well as assertions to test behavior in an existing unit test.


Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open a GitHub issue as a bug/feature request before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #49 馃

Copy link
Member

@arriolac arriolac left a comment

Choose a reason for hiding this comment

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

Change generally LGTM although I think this is a good opportunity to improve the type safety around reason and use an enum instead. A new type can also be created for the initial case. Note that this is a pattern already used in the library for MapType.

@barbeau
Copy link
Contributor Author

barbeau commented Jun 23, 2022

@arriolac Good idea! I converted to an enum in 819179e.

I wasn't sure how to handle the case where a new Maps SDK constant is passed back from the GoogleMap.OnCameraMoveStartedListener that isn't known to the maps-compose library (e.g., if the Maps SDK is updated). I ended up mapping these unknown constants to another CameraMoveStartedReason enum value UNKNOWN(-2), but let me know if you have a better idea of how to handle this.

Copy link
Member

@arriolac arriolac left a comment

Choose a reason for hiding this comment

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

LGTM! Just a small nit about imports.

Re: using -2 for an unknown reason. The other option is to initialize cameraMoveStartedReason as null which would represent NO_MOVEMENT_YET. It's nice to have properties as non-optional though so I think your current approach is better.

import kotlinx.coroutines.cancel
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.*
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Use single name imports here. I have my preferences configured to the following:

image

This should probably be enforced in the linter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good catch - I fixed the imports to not use wildcards and updated my AS settings.

@barbeau barbeau merged commit 202f34f into main Jun 23, 2022
@barbeau barbeau deleted the sean/camera-move-reason branch June 23, 2022 18:13
googlemaps-bot pushed a commit that referenced this pull request Jun 23, 2022
# [2.4.0](v2.3.0...v2.4.0) (2022-06-23)

### Features

* Add the reason for map camera movement ([#154](#154)) ([202f34f](202f34f))
@googlemaps-bot
Copy link
Contributor

馃帀 This PR is included in version 2.4.0 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Source of camera movement - Exposing GoogleMap.OnCameraMoveStartedListener "reason"
4 participants