-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Support Hybrid Composition on Android #4017
Changes from 7 commits
7a46e96
6916220
16eeb01
9f44436
091a05f
a6a1c41
2deb78d
85c30ae
4dbe1bc
2975535
8c6ac44
ce74525
35f1ec1
a2b3df6
a2b0483
5ef7a79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import 'dart:typed_data'; | |
| import 'package:flutter/foundation.dart'; | ||
| import 'package:flutter/gestures.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter/rendering.dart'; | ||
| import 'package:flutter/services.dart'; | ||
| import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; | ||
| import 'package:stream_transform/stream_transform.dart'; | ||
|
|
@@ -441,6 +442,17 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { | |
| return channel(mapId).invokeMethod<Uint8List>('map#takeSnapshot'); | ||
| } | ||
|
|
||
| /// Set [GoogleMapsFlutterPlatform] to uses [AndroidViewSurface] to build the Google Maps widget. | ||
bparrishMines marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// | ||
| /// This implementation uses hybrid composition to render the Google Maps | ||
| /// Widget on Android. This comes at the cost of some performance on Android | ||
| /// versions below 10. See | ||
| /// https://github.com/flutter/flutter/wiki/Hybrid-Composition for more | ||
bparrishMines marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// information. | ||
| /// | ||
| /// Defaults to false. | ||
| bool useAndroidViewSurface = false; | ||
|
|
||
| @override | ||
| Widget buildView( | ||
| int creationId, | ||
|
|
@@ -463,7 +475,43 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { | |
| 'circlesToAdd': serializeCircleSet(circles), | ||
| 'tileOverlaysToAdd': serializeTileOverlaySet(tileOverlays), | ||
| }; | ||
| if (defaultTargetPlatform == TargetPlatform.android) { | ||
| if (defaultTargetPlatform == TargetPlatform.android && | ||
| useAndroidViewSurface) { | ||
| return PlatformViewLink( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this snippet of creating the platform view looks good to me, i'll still defer to @blasten to confirm. |
||
| viewType: 'plugins.flutter.io/google_maps', | ||
| surfaceFactory: ( | ||
| BuildContext context, | ||
| PlatformViewController controller, | ||
| ) { | ||
| return AndroidViewSurface( | ||
| controller: controller as AndroidViewController, | ||
| gestureRecognizers: gestureRecognizers ?? | ||
| const <Factory<OneSequenceGestureRecognizer>>{}, | ||
| hitTestBehavior: PlatformViewHitTestBehavior.opaque, | ||
| ); | ||
| }, | ||
| onCreatePlatformView: (PlatformViewCreationParams params) { | ||
| final SurfaceAndroidViewController controller = | ||
| PlatformViewsService.initSurfaceAndroidView( | ||
| id: params.id, | ||
| viewType: 'plugins.flutter.io/google_maps', | ||
| layoutDirection: TextDirection.rtl, | ||
|
||
| creationParams: creationParams, | ||
| creationParamsCodec: const StandardMessageCodec(), | ||
bparrishMines marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ); | ||
| controller.addOnPlatformViewCreatedListener( | ||
| params.onPlatformViewCreated, | ||
| ); | ||
| controller.addOnPlatformViewCreatedListener( | ||
| onPlatformViewCreated, | ||
| ); | ||
|
|
||
| controller.create(); | ||
| return controller; | ||
| }, | ||
| ); | ||
| } else if (defaultTargetPlatform == TargetPlatform.android && | ||
| !useAndroidViewSurface) { | ||
bparrishMines marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return AndroidView( | ||
| viewType: 'plugins.flutter.io/google_maps', | ||
| onPlatformViewCreated: onPlatformViewCreated, | ||
|
|
||
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.
Why is it required in this order?
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.
The tests for the widget are in
google_maps_flutter, but the changes to the code are ingoogle_maps_flutter_platform_interface. However,google_maps_flutterpulls the latest version of the platform interface from pub.