This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Support Hybrid Composition on Android #4017
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7a46e96
add support for hybrid composition on Android
bparrishMines 6916220
export method channel platform interface
bparrishMines 16eeb01
version bump
bparrishMines 9f44436
add tests
bparrishMines 091a05f
remove duplicate version bump
bparrishMines a6a1c41
formatting and add comment for future test
bparrishMines 2deb78d
cheat to get tests to pass
bparrishMines 85c30ae
comments
bparrishMines 4dbe1bc
Update packages/google_maps_flutter/google_maps_flutter_platform_inte…
bparrishMines 2975535
Update packages/google_maps_flutter/google_maps_flutter_platform_inte…
bparrishMines 8c6ac44
make text direction optional
bparrishMines ce74525
Merge branch 'maps_hybrid' of github.com:bparrishMines/plugins into m…
bparrishMines 35f1ec1
create new build method for text direction
bparrishMines a2b3df6
Merge branch 'master' of github.com:flutter/plugins into maps_hybrid
bparrishMines a2b0483
empty commit
bparrishMines 5ef7a79
Merge branch 'master' of github.com:flutter/plugins into maps_hybrid
bparrishMines File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,98 @@ class MethodChannelGoogleMapsFlutter extends GoogleMapsFlutterPlatform { | |
return channel(mapId).invokeMethod<Uint8List>('map#takeSnapshot'); | ||
} | ||
|
||
/// Set [GoogleMapsFlutterPlatform] to use [AndroidViewSurface] to build the Google Maps widget. | ||
/// | ||
/// 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://flutter.dev/docs/development/platform-integration/platform-views#performance for more | ||
/// information. | ||
/// | ||
/// If set to true, the google map widget should be built with | ||
/// [buildViewWithTextDirection] instead of [buildView]. | ||
/// | ||
/// Defaults to false. | ||
bool useAndroidViewSurface = false; | ||
|
||
/// Returns a widget displaying the map view. | ||
/// | ||
/// This method includes a parameter for platforms that require a text | ||
/// direction. For example, this should be used when using hybrid composition | ||
/// on Android. | ||
Widget buildViewWithTextDirection( | ||
int creationId, | ||
PlatformViewCreatedCallback onPlatformViewCreated, { | ||
required CameraPosition initialCameraPosition, | ||
required TextDirection textDirection, | ||
Set<Marker> markers = const <Marker>{}, | ||
Set<Polygon> polygons = const <Polygon>{}, | ||
Set<Polyline> polylines = const <Polyline>{}, | ||
Set<Circle> circles = const <Circle>{}, | ||
Set<TileOverlay> tileOverlays = const <TileOverlay>{}, | ||
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers, | ||
Map<String, dynamic> mapOptions = const <String, dynamic>{}, | ||
}) { | ||
if (defaultTargetPlatform == TargetPlatform.android && | ||
useAndroidViewSurface) { | ||
final Map<String, dynamic> creationParams = <String, dynamic>{ | ||
'initialCameraPosition': initialCameraPosition.toMap(), | ||
'options': mapOptions, | ||
'markersToAdd': serializeMarkerSet(markers), | ||
'polygonsToAdd': serializePolygonSet(polygons), | ||
'polylinesToAdd': serializePolylineSet(polylines), | ||
'circlesToAdd': serializeCircleSet(circles), | ||
'tileOverlaysToAdd': serializeTileOverlaySet(tileOverlays), | ||
}; | ||
return PlatformViewLink( | ||
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, | ||
creationParams: creationParams, | ||
creationParamsCodec: const StandardMessageCodec(), | ||
bparrishMines marked this conversation as resolved.
Show resolved
Hide resolved
|
||
onFocus: () => params.onFocusChanged(true), | ||
); | ||
controller.addOnPlatformViewCreatedListener( | ||
params.onPlatformViewCreated, | ||
); | ||
controller.addOnPlatformViewCreatedListener( | ||
onPlatformViewCreated, | ||
); | ||
|
||
controller.create(); | ||
return controller; | ||
}, | ||
); | ||
} | ||
return buildView( | ||
creationId, | ||
onPlatformViewCreated, | ||
initialCameraPosition: initialCameraPosition, | ||
markers: markers, | ||
polygons: polygons, | ||
polylines: polylines, | ||
circles: circles, | ||
tileOverlays: tileOverlays, | ||
gestureRecognizers: gestureRecognizers, | ||
mapOptions: mapOptions, | ||
); | ||
} | ||
|
||
@override | ||
Widget buildView( | ||
int creationId, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_flutter
pulls the latest version of the platform interface from pub.