Skip to content

Conversation

@stuartmorgan-g
Copy link
Collaborator

For both Android and iOS, convert the platform view creation parameters to a typed structure using Pigeon, via the ability to set a custom codec for the parameter, instead of a JSON dictionary, as well as converting the map configuration structure used in both those params and updateMapConfiguration.

This change removes the last high-level use of non-Pigeon code in the plugin. The remaining uses of JSON are now internal to individual maps objects, which means that it should now be the case that all future changes to this plugin use Pigeon structures rather than JSON. (The individual objects don't change often, if at all, and it would be reasonable if someone does want to add a new parameter to one of those objects to require converting that specific object, as that would not require sweeping changes or knowledge of how to do a more holistic Pigeon conversion.)

Part of flutter/flutter#117907

Pre-launch Checklist

@stuartmorgan-g
Copy link
Collaborator Author

I put both platforms together this time since the scope is smaller than the previous PRs, and the structure of the change is the same between the two, but you can each just review your platform's half.

@stuartmorgan-g stuartmorgan-g added triage-ios Should be looked at in iOS triage triage-android Should be looked at in Android triage labels Jul 24, 2024
this.googleMap = googleMap;
}

void addJsonCircles(List<Object> circlesToAdd) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On both platforms, the pure removal of the addJson* methods is because I added the Pigeon version in previous PRs, so this is removing temporarily-quasi-duplicated code.


private void updateInitialMarkers() {
markersController.addJsonMarkers(initialMarkers);
if (initialMarkers != null) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These new null checks are because addJson* was internally no-oping for nil, but the typed versions don't do that because I think it's cleaner to forbid calling add* than to silently no-op internally.


@Before
public void setUp() {
MockitoAnnotations.openMocks(this);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Opportunistic cleanup; there were warnings about the fact that we weren't cleaning this up, and when I went to fix that I noticed that there were no mockito-annotated ivars in this test class.

}

@Test
public void interpretMapConfiguration_handlesNulls() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

New tests because that entire method was untested before, which didn't seem great.

Map<String, Object?> options) {
// All of these hard-coded values and structures come from
// google_maps_flutter_platform_interface/lib/src/types/utils/map_configuration_serialization.dart
// to support this legacy API that relied on cross-package magic strings.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(This applies to Android and iOS.)

This method is gross in that it uses magic strings from another package, but the good news is that it is only in the codepath for a platform interface API that we don't use in recent versions of the app-facing package. At some point we could just decide to do a breaking change to the implementation packages and remove this, without needing to do a breaking change to the app-facing or platform interface packages. I didn't want to do that in this PR though as it requires some extra steps.

(And while this looks like new gross code, it isn't conceptually: it's just moving from native to Dart, and moving from every codepath to a codepath that will in practice almost never be used.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for adding a link to where the magic strings come from

(zoomPrefsJson as List<Object?>).cast<double?>();
return PlatformZoomRange(min: minMaxZoom[0], max: minMaxZoom[1]);
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(This applies to Android and iOS.)

The reason there's a bunch of added conversion code without any corresponding removal of JSON versions is that the JSON serialization code is in google_maps_flutter_platform_interface. That's ugly technical debt, because having the serialization and deserialization in different packages is a bad idea, and means the entire JSON surface is effective part of the public API surface of the platform interface package, and we therefore can't do anything to that code other than add things to dictionaries.

So it looks like it's adding complexity, but is actually reducing technical debt by moving the serialization into the same package as the deserialization where it belongs. (There's actually a TODO about this at the top of the file.)

this.onMapCreated,
this.gestureRecognizers = const <Factory<OneSequenceGestureRecognizer>>{},
this.compassEnabled = true,
this.mapToolbarEnabled = true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These changes to the iOS example are opportunistic cleanup; these have always been Android-only, and just got copypasta'd here when I federated the implementations out of the original shared implementation.

@stuartmorgan-g
Copy link
Collaborator Author

I'm not sure what's going on with that Android test; there's not much info in FTL output, and I haven't been able to repro locally. I'll keep investigating that in parallel with review.

@stuartmorgan-g
Copy link
Collaborator Author

there's not much info in FTL output

Turns out there was, it was just buried in all the other log output.

It found a real bug where I missed a change I needed to make in Convert.java (which the compiler didn't flag because it's code casts Object to other things; the usual problem of dealing with pre-Pigeon code) and I had missed that branch when adding unit tests. Pushed a fix and a unit test that exercised that specific section of code.

Copy link
Contributor

@reidbaker reidbaker left a comment

Choose a reason for hiding this comment

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

Android LGTM

Map<String, Object?> options) {
// All of these hard-coded values and structures come from
// google_maps_flutter_platform_interface/lib/src/types/utils/map_configuration_serialization.dart
// to support this legacy API that relied on cross-package magic strings.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for adding a link to where the magic strings come from

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 8, 2024
@auto-submit auto-submit bot merged commit bb797b9 into flutter:main Aug 8, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 8, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Aug 8, 2024
flutter/packages@5cc0a01...bb797b9

2024-08-08 [email protected] [google_maps_flutter] Converts map configuration and platform view creation params to Pigeon (flutter/packages#7207)
2024-08-08 [email protected] [flutter_markdown] Fix table column alignment (flutter/packages#7327)
2024-08-08 [email protected] [interactive_media_ads] Fix names of unit tests (flutter/packages#7336)
2024-08-07 [email protected] [url_launcher] Convert Linux to Pigeon (flutter/packages#7215)
2024-08-07 [email protected] Roll Flutter from 0a7f8af to d595e98 (4 revisions) (flutter/packages#7334)

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
DBowen33 pushed a commit to DBowen33/flutter that referenced this pull request Aug 16, 2024
flutter/packages@5cc0a01...bb797b9

2024-08-08 [email protected] [google_maps_flutter] Converts map configuration and platform view creation params to Pigeon (flutter/packages#7207)
2024-08-08 [email protected] [flutter_markdown] Fix table column alignment (flutter/packages#7327)
2024-08-08 [email protected] [interactive_media_ads] Fix names of unit tests (flutter/packages#7336)
2024-08-07 [email protected] [url_launcher] Convert Linux to Pigeon (flutter/packages#7215)
2024-08-07 [email protected] Roll Flutter from 0a7f8af to d595e98 (4 revisions) (flutter/packages#7334)

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
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
flutter/packages@5cc0a01...bb797b9

2024-08-08 [email protected] [google_maps_flutter] Converts map configuration and platform view creation params to Pigeon (flutter/packages#7207)
2024-08-08 [email protected] [flutter_markdown] Fix table column alignment (flutter/packages#7327)
2024-08-08 [email protected] [interactive_media_ads] Fix names of unit tests (flutter/packages#7336)
2024-08-07 [email protected] [url_launcher] Convert Linux to Pigeon (flutter/packages#7215)
2024-08-07 [email protected] Roll Flutter from 0a7f8af to d595e98 (4 revisions) (flutter/packages#7334)

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: google_maps_flutter platform-android platform-ios triage-android Should be looked at in Android triage triage-ios Should be looked at in iOS triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants