flutter-unity-view-widget icon indicating copy to clipboard operation
flutter-unity-view-widget copied to clipboard

[Android] Prepare to revert Flutter 3.0 PlatformView workaround

Open timbotimbo opened this issue 3 years ago • 0 comments

Description

Flutter 3.0 broke the default android platformview (https://github.com/juicycleff/flutter-unity-view-widget/issues/584), rendering the unity widget in the wrong location. According to https://github.com/flutter/flutter/issues/103630#issuecomment-1190733675, this is now fixed in Flutter beta releases.

If the original issue is fixed, we can remove the workaround in this plugin. And if we prepare and test this now, it can be ready to go when theses fixes make it into a new Flutter release.

Current workaround

@juicycleff fixed this in flutter_unity_widget 2022.1.1 by ignoring useAndroidSurfaceView and always using initExpensiveAndroidView.

/* /lib/src/io/device_method.dart */

// commented for 3.0.0 changes in platform view rendition
// if (!useAndroidViewSurface) {
//   return AndroidView(
//     viewType: _viewType,
//     onPlatformViewCreated: onPlatformViewCreated,
//     gestureRecognizers: gestureRecognizers,
//     creationParams: creationParams,
//     creationParamsCodec: const StandardMessageCodec(),
//     hitTestBehavior: PlatformViewHitTestBehavior.opaque,
//     layoutDirection: TextDirection.ltr,
//   );
// }

/* return initExpensiveAndroidView below */

This works for now, but the ExpensiveAndroidView introduces new bugs that did not happen with Flutter 2.x.

Flutter beta

The current Flutter beta releases (starting with 3.3.0-0.0.pre) seem to fix the original issue, meaning we can enable the AndroidView option again.

Setup:

  • Flutter 3.0.5 & 3.3.0-0.0.pre
  • Unity 2021.3.5
  • flutter_unity_widget 2022.1.7+1 (With the above code uncommented)
  • Android 12 (Samsung Galaxy S20FE)

In these videos I open the 'Simple Unity Demo' and 'Native exposed API demo' screens because these show the original issue the best.

Flutter 3.0.5
useAndroidSurfaceView: false
Flutter 3.3.0-0.0.pre
useAndroidSurfaceView: false
Flutter 3.3.0-0.0.pre
useAndroidSurfaceView: true

https://user-images.githubusercontent.com/11444698/181485459-0de78c35-96ab-4909-ac31-0f00d8ce4dad.mp4

https://user-images.githubusercontent.com/11444698/181485472-c9c72de9-cd00-46d6-8f36-88bf23ef9cfb.mp4

https://user-images.githubusercontent.com/11444698/181485489-9a940f7c-6d6f-43b3-b883-d12e975d3e3a.mp4

Result

Flutter 3.3.0-0.0-pre seems to fix the issue, so we should enable AndroidView again when this makes it to a Flutter release version. In this way users get to choose which type of PlatformView to use, and might be able to avoid certain bugs,

It also shows that useAndroidViewSurface: false now respects the margin and rounded borders that are broken with useAndroidViewSurface: true

[UPDATE] Testing

I tried some more devices to check android compatibility with 3.3.0-0.0.pre:

Device Android useAndroidViewSurface: false useAndroidViewSurface: true
Samsung Galaxy S20FE 12 Works Works
Samsung Galaxy S8 9 Works Works
Wileyfox Swift 7.1 Works broken
Samsung Galaxy J5 6 Works broken

timbotimbo avatar Jul 28 '22 11:07 timbotimbo