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

[google_maps_flutter_android] Convert PlatformCameraUpdate to pigeon. #7507

Merged
merged 25 commits into from
Sep 12, 2024

Conversation

yaakovschectman
Copy link
Contributor

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

If you need help, consider asking for advice on the #hackers-new channel on Discord.

}
Messages.PlatformNewLatLng newLatLng = update.getNewLatLng();
if (newLatLng != null) {
return CameraUpdateFactory.newLatLng(latLngFromPigeon(newLatLng.getLatLng()));
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.


static PlatformCameraUpdate _platformCameraUpdateFromCameraUpdate(
CameraUpdate update) {
if (update is NewCameraPosition) {
Copy link
Contributor

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.

Messages.PlatformCameraUpdateZoom zoom = (Messages.PlatformCameraUpdateZoom) cameraUpdate;
return (zoom.getOut()) ? CameraUpdateFactory.zoomOut() : CameraUpdateFactory.zoomIn();
}
throw new IllegalArgumentException("PlatformCameraUpdate must have one non-null member.");
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@reidbaker
Copy link
Contributor

Please hold on @stuartmorgan's approval as well.

Copy link
Contributor

@stuartmorgan stuartmorgan left a 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.

Copy link
Contributor

@stuartmorgan stuartmorgan left a 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.)

@yaakovschectman
Copy link
Contributor Author

yaakovschectman commented Sep 6, 2024

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.

@stuartmorgan I do not think we can address the testing in the PR that updates the platform interface. The tests would be in the android package, and no PR can land that refers to changes in the platform interface until the platform interface's package's PR lands. Perhaps I have misunderstood what you mean..
It occurs to me now you are probably suggesting that the unit tests for each case of CameraUpdate would go in the platform_interface package, rendering my above point moot.

yaakovschectman added a commit that referenced this pull request Sep 9, 2024
…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
Copy link
Contributor

@stuartmorgan stuartmorgan 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 the expanded testing and Java cleanup! Mostly looks great, just a few comments.

private static LatLngBounds toLatLngBounds(Object o) {
if (o == null) {
@Nullable
static Point pointFromPigeon(@Nullable Messages.PlatformOffset point, float density) {
Copy link
Contributor

@reidbaker reidbaker Sep 10, 2024

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.

Copy link
Contributor

@stuartmorgan stuartmorgan Sep 10, 2024

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

LGTM

@yaakovschectman yaakovschectman merged commit 11b339e into flutter:main Sep 12, 2024
76 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 13, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 13, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Sep 13, 2024
flutter/packages@91caa7a...330581f

2024-09-12 43759233+kenzieschmoll@users.noreply.github.com Refactor the test benchmark app to make the example easier to follow (flutter/packages#7640)
2024-09-12 matanlurey@users.noreply.github.com Fix an if statement with resumed video players on Android. (flutter/packages#7641)
2024-09-12 engine-flutter-autoroll@skia.org Roll Flutter from 2e221e7 to 303f222 (77 revisions) (flutter/packages#7638)
2024-09-12 109111084+yaakovschectman@users.noreply.github.com [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 flutter-ecosystem@google.com,rmistry@google.com 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants