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] Add ability to animate camera with duration #7648

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jokerttu
Copy link
Contributor

@jokerttu jokerttu commented Sep 14, 2024

Adds ability to configure camera animation duration on Android and iOS.

Resolves #39810
Resolves #44284

Pre-launch Checklist

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

@jokerttu jokerttu force-pushed the feature/animate-camera-duration branch from fbf20bc to 68e52df Compare September 14, 2024 12:57
@jokerttu jokerttu changed the title [google_maps_flutter] add ability to animate camera with duration Sep 14, 2024
@jokerttu jokerttu force-pushed the feature/animate-camera-duration branch from 68e52df to 2c8caf1 Compare September 15, 2024 09:03
@jokerttu jokerttu force-pushed the feature/animate-camera-duration branch from 2c8caf1 to 2256a07 Compare November 7, 2024 16:28
@jokerttu jokerttu force-pushed the feature/animate-camera-duration branch from 2256a07 to c39c721 Compare November 7, 2024 16:41
@jokerttu
Copy link
Contributor Author

jokerttu commented Nov 7, 2024

Web support is not included, as there are still some areas open for discussion.
Test implementation here:
https://github.com/CodemateLtd/packages/compare/feature/animate-camera-duration...CodemateLtd:packages:feature/animate-camera-duration-web?expand=1

@jokerttu jokerttu marked this pull request as ready for review November 7, 2024 16:58
@stuartmorgan stuartmorgan added the federated: all_changes PR that contains changes for all packages for a federated plugin change label Nov 7, 2024
@@ -421,8 +421,20 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform {
CameraUpdate cameraUpdate, {
required int mapId,
}) {
return channel(mapId).invokeMethod<void>('camera#animate', <String, Object>{
return channel(mapId).invokeMethod<void>('camera#animate',
<String, dynamic>{'cameraUpdate': cameraUpdate.toJson()});
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this changed to dynamic? We only use dynamic when we have an extremely compelling reason to do so as it bypasses a lot of static analysis.

'cameraUpdate': cameraUpdate.toJson(),
'duration': configuration.duration?.inMilliseconds,
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't generally want to send nulls in collections in method channels.

I would recommend just reverting the changes to this file; we don't use the method channel implementation, it's only still here because removing it requires a breaking change. There's no obligation to implement new features for it.

/// platform side.
Future<void> animateCameraWithConfiguration(
CameraUpdate cameraUpdate, {
required CameraUpdateAnimationConfiguration configuration,
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be positional rather than named since it's a core parameter.

required int mapId,
}) {
throw UnimplementedError(
'animateCameraWithConfiguration() has not been implemented.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

And the forwarding should get a unit test in this package.

@@ -24,6 +24,7 @@ export 'package:google_maps_flutter_platform_interface/google_maps_flutter_platf
CameraPositionCallback,
CameraTargetBounds,
CameraUpdate,
CameraUpdateAnimationConfiguration,
Copy link
Contributor

Choose a reason for hiding this comment

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

We generally don't want to expose these parameter objects at the app-facing package API level; they solve a problem (adding optional parameter being a breaking change for subclasses) that doesn't exist at this level, and add complexity for all clients (vs. just ourselves in implementation packages). The client-facing API should expose the duration directly, and that should be packed into the configuration object as an internal implementation detail.

@@ -103,6 +103,13 @@ class PlatformCameraUpdateZoomTo {
final double zoom;
}

/// Pigeon representation of a CameraUpdateAnimationConfiguration.
class PlatformCameraUpdateAnimationConfiguration {
Copy link
Contributor

Choose a reason for hiding this comment

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

Pigeon interfaces are internal APIs, and can be changed at will, so there is no need to use parameter objects in general; the method can just take a durationMilliseconds parameter directly (same on iOS).

// Assert that the camera zoom is updated after the animation completes
XCTAssertEqual(controller.mapView.camera.zoom, 10.0,
"Camera zoom should be updated to 10.0 after animation.");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually running animations is pretty slow for unit tests; could we just dependency inject a simple wrapper around CATransaction and ensure that's being called as expected, rather than testing the animation itself (which is largely testing the underlying SDK rather than the plugin code)?

@@ -51,6 +51,13 @@ class PlatformCameraUpdate {
final Object json;
}

/// Pigeon representation of a CameraUpdateAnimationConfiguration.
class PlatformCameraUpdateAnimationConfiguration {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same note here as on Android.

required CameraUpdateAnimationConfiguration configuration,
required int mapId,
}) {
return animateCamera(cameraUpdate, mapId: mapId);
Copy link
Contributor

Choose a reason for hiding this comment

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

This will need a TODO referencing an issue, as with the test disabling.

null);
} else {
googleMap.animateCamera(Convert.cameraUpdateFromPigeon(cameraUpdate, density));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be a native unit test validating the branching here (via a mock map).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
federated: all_changes PR that contains changes for all packages for a federated plugin change p: google_maps_flutter platform-android platform-ios platform-web
2 participants