-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[google_maps_flutter_android] Convert PlatformCameraUpdate
to pigeon.
#7507
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
[google_maps_flutter_android] Convert PlatformCameraUpdate
to pigeon.
#7507
Conversation
} | ||
Messages.PlatformNewLatLng newLatLng = update.getNewLatLng(); | ||
if (newLatLng != null) { | ||
return CameraUpdateFactory.newLatLng(latLngFromPigeon(newLatLng.getLatLng())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may not be following the types here but is it possible to make this CameraUpdateFactory.newLatLng(latLngFromPigeon(newLatLng); It seems, based on names alone that we should not need so many unboxing/reboxing of lat long data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newLatLng
is an instance of PlatformNewLatLng
, which represents the camera move update to the new position. latLngFromPigeon
accepts a PlatformLatLng
, which is just a boxed pair of numeric coordinates, not a PlatformNewLatLng
. I intend to add a CameraUpdate
prefix to the relevant classes, including PlatformNewLatLng
, as per Stuart's comment, which I believe will make this more clear.
throw new IllegalArgumentException("Cannot interpret " + o + " as CameraUpdate"); | ||
static CameraUpdate cameraUpdateFromPigeon(Messages.PlatformCameraUpdate update, float density) { | ||
Messages.PlatformNewCameraPosition newCameraPosition = update.getNewCameraPosition(); | ||
if (newCameraPosition != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see how this code is a conversion from what was here before but I think the if statement make it harder to read what should happen. Before the toCameraUpdate method either updated the camera position, the lat/lng or the bounds. Now that is much harder to understand.
Try restructuring this method to make it easier for a human reader and/or adding java doc comments.
|
||
static PlatformCameraUpdate _platformCameraUpdateFromCameraUpdate( | ||
CameraUpdate update) { | ||
if (update is NewCameraPosition) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might have discussed this with @stuartmorgan if so feel free to resolve but can cameraUpdate include an enum of the type of update instead of these long object type checks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was discussed a bit for the Pigeon classes (where I don't think the enum probably helps us), but not for the Dart code.
I think for Dart, where we will be creating a new permanent public API surface, it would be better to add a type enum, and to make all of these classes private, so that we're not locking ourselves into a specific class structure forever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these classes were private, would that not then make their members inaccessible in this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦🏻
Sorry, I was thinking about mirroring the Java SDK's approach, but there they only need to consume the properties internally to the SDK.
packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart
Outdated
Show resolved
Hide resolved
packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart
Outdated
Show resolved
Hide resolved
|
||
static PlatformCameraUpdate _platformCameraUpdateFromCameraUpdate( | ||
CameraUpdate update) { | ||
if (update is NewCameraPosition) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was discussed a bit for the Pigeon classes (where I don't think the enum probably helps us), but not for the Dart code.
I think for Dart, where we will be creating a new permanent public API surface, it would be better to add a type enum, and to make all of these classes private, so that we're not locking ourselves into a specific class structure forever.
packages/google_maps_flutter/google_maps_flutter_android/pigeons/messages.dart
Outdated
Show resolved
Hide resolved
Messages.PlatformCameraUpdateZoom zoom = (Messages.PlatformCameraUpdateZoom) cameraUpdate; | ||
return (zoom.getOut()) ? CameraUpdateFactory.zoomOut() : CameraUpdateFactory.zoomIn(); | ||
} | ||
throw new IllegalArgumentException("PlatformCameraUpdate must have one non-null member."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message does not make sense to me since the throw is not related to a value being null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It made sense before, but now I need to update it.
...google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java
Show resolved
Hide resolved
Please hold on @stuartmorgan's approval as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments, but nothing structural at this point. Feel free to split google_maps_flutter_platform_interface
out into its own PR and just addressing the testing in that PR.
packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart
Outdated
Show resolved
Hide resolved
...ges/google_maps_flutter/google_maps_flutter_android/lib/src/google_maps_flutter_android.dart
Show resolved
Hide resolved
packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/camera.dart
Outdated
Show resolved
Hide resolved
...google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java
Show resolved
Hide resolved
...google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java
Show resolved
Hide resolved
...google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java
Show resolved
Hide resolved
packages/google_maps_flutter/google_maps_flutter/example/pubspec.yaml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I forgot to switch from Comment to Request Changes to reflect the comments.)
@stuartmorgan |
…rived classes to use structured data (#7596) Platform interface part of #7507 flutter/flutter#152928 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] page, which explains my responsibilities. - [x] I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use `dart format`.) - [ ] I signed the [CLA]. - [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]` - [x] I [linked to at least one issue that this PR fixes] in the description above. - [x] I updated `pubspec.yaml` with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes]. - [x] I updated `CHANGELOG.md` to add a description of the change, [following repository CHANGELOG style], or this PR is [exempt from CHANGELOG changes]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md [Tree Hygiene]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md [relevant style guides]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md [linked to at least one issue that this PR fixes]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview [pub versioning philosophy]: https://dart.dev/tools/pub/versioning [exempt from version changes]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#version [following repository CHANGELOG style]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog-style [exempt from CHANGELOG changes]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog [test-exempt]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests
# Conflicts: # packages/google_maps_flutter/google_maps_flutter_android/android/src/main/java/io/flutter/plugins/googlemaps/Messages.java # packages/google_maps_flutter/google_maps_flutter_android/lib/src/messages.g.dart
931ac13
to
0ee9e29
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the expanded testing and Java cleanup! Mostly looks great, just a few comments.
packages/google_maps_flutter/google_maps_flutter_android/pigeons/messages.dart
Show resolved
Hide resolved
packages/google_maps_flutter/google_maps_flutter_android/pigeons/messages.dart
Show resolved
Hide resolved
...s/google_maps_flutter/google_maps_flutter_android/test/google_maps_flutter_android_test.dart
Outdated
Show resolved
Hide resolved
...s/google_maps_flutter/google_maps_flutter_android/test/google_maps_flutter_android_test.dart
Outdated
Show resolved
Hide resolved
private static LatLngBounds toLatLngBounds(Object o) { | ||
if (o == null) { | ||
@Nullable | ||
static Point pointFromPigeon(@Nullable Messages.PlatformOffset point, float density) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stuartmorgan is it a normal pattern to have "from" methods in pigeon conversion? As I am reading this pr I find that I very much do not care that the conversions are coming from pidgeon and instead care what the object is being converted into.
FWIW I think the answer is yes because i see a bunch of from methods but I did want to call out my confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe I established that naming convention in this file. The problem is that during this transition there have been a bunch of cases where there are two different version of all the methods: one that converts method channel primitives, for the unconverted code, and one that converts Pigeon objects, but both to the same object. E.g., the toPoint
method that's finally able to be removed in this PR.
In that context, the fact that the source object is Pigeon is very important. Especially because the old methods take Object
which means you can accidentally pass a Pigeon object to them (which will then crash).
I would have no objection to mass renaming these when the conversion is done and the old versions don't exist any more. Or we could mass rename the remaining old methods now to something that clearly identifies them, and then mass rename the Pigeon versions to use the generic names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense and makes me glad I asked the question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stuartmorgan Do you have any remaining concerns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
flutter/packages@91caa7a...330581f 2024-09-12 [email protected] Refactor the test benchmark app to make the example easier to follow (flutter/packages#7640) 2024-09-12 [email protected] Fix an if statement with resumed video players on Android. (flutter/packages#7641) 2024-09-12 [email protected] Roll Flutter from 2e221e7 to 303f222 (77 revisions) (flutter/packages#7638) 2024-09-12 [email protected] [google_maps_flutter_android] Convert `PlatformCameraUpdate` to pigeon. (flutter/packages#7507) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Because this also converts the platform interface Camera type, this will need to be a federated change, unless we come up with a better idea of how to convert that class.
flutter/flutter#152928
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or this PR is exempt from CHANGELOG changes.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.