-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add and default to Hybrid composition on Android (#916)
* Add and default to Hybrid composition on Android * ran flutter format * added example for handling hybrid composition * fixed issue with android:exported * fixed typo Co-authored-by: Felix Horvat <felix.horvat@ocell.aero>
- Loading branch information
Showing
7 changed files
with
90 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ part of mapbox_gl_platform_interface; | |
|
||
class MethodChannelMapboxGl extends MapboxGlPlatform { | ||
late MethodChannel _channel; | ||
static bool useHybridComposition = true; | ||
|
||
Future<dynamic> _handleMethodCall(MethodCall call) async { | ||
switch (call.method) { | ||
|
@@ -138,13 +139,50 @@ class MethodChannelMapboxGl extends MapboxGlPlatform { | |
OnPlatformViewCreatedCallback onPlatformViewCreated, | ||
Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers) { | ||
if (defaultTargetPlatform == TargetPlatform.android) { | ||
return AndroidView( | ||
viewType: 'plugins.flutter.io/mapbox_gl', | ||
onPlatformViewCreated: onPlatformViewCreated, | ||
gestureRecognizers: gestureRecognizers, | ||
creationParams: creationParams, | ||
creationParamsCodec: const StandardMessageCodec(), | ||
); | ||
if (useHybridComposition) { | ||
return PlatformViewLink( | ||
viewType: 'plugins.flutter.io/mapbox_gl', | ||
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/mapbox_gl', | ||
layoutDirection: TextDirection.ltr, | ||
creationParams: creationParams, | ||
creationParamsCodec: const StandardMessageCodec(), | ||
onFocus: () => params.onFocusChanged(true), | ||
); | ||
controller.addOnPlatformViewCreatedListener( | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
AAverin
Contributor
|
||
params.onPlatformViewCreated, | ||
); | ||
controller.addOnPlatformViewCreatedListener( | ||
onPlatformViewCreated, | ||
); | ||
|
||
controller.create(); | ||
return controller; | ||
}, | ||
); | ||
} else { | ||
return AndroidView( | ||
viewType: 'plugins.flutter.io/mapbox_gl', | ||
onPlatformViewCreated: onPlatformViewCreated, | ||
gestureRecognizers: gestureRecognizers, | ||
creationParams: creationParams, | ||
creationParamsCodec: const StandardMessageCodec(), | ||
); | ||
} | ||
} else if (defaultTargetPlatform == TargetPlatform.iOS) { | ||
return UiKitView( | ||
viewType: 'plugins.flutter.io/mapbox_gl', | ||
|
Any particluar reason why we have two callbacks for
onPlatformViewCreated
here?@felix-ht @yoavrofe
Could it be the reason onStyleLoaded is now triggered twice with Flutter 3 fixes?