@@ -79,8 +79,20 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
7979 // it is associated with(e.g if a platform view creates other views in the same virtual display.
8080 private final HashMap <Context , View > contextToPlatformView ;
8181
82+ // The view returned by `PlatformView#getView()`.
83+ //
84+ // This only applies to hybrid composition.
8285 private final SparseArray <View > platformViews ;
83- private final SparseArray <FlutterMutatorView > mutatorViews ;
86+
87+ // The platform view parent that is appended to `FlutterView`.
88+ // If an entry in `platformViews` doesn't have an entry in this array, the platform view isn't
89+ // in the view hierarchy.
90+ //
91+ // This view provides a wrapper that applies scene builder operations to the platform view.
92+ // For example, a transform matrix, or setting opacity on the platform view layer.
93+ //
94+ // This is only applies to hybrid composition.
95+ private final SparseArray <FlutterMutatorView > platformViewParent ;
8496
8597 // Map of unique IDs to views that render overlay layers.
8698 private final SparseArray <FlutterImageView > overlayLayerViews ;
@@ -146,12 +158,17 @@ public void createAndroidViewForPlatformView(
146158 public void disposeAndroidViewForPlatformView (int viewId ) {
147159 // Hybrid view.
148160 final View platformView = platformViews .get (viewId );
161+ final FlutterMutatorView parentView = platformViewParent .get (viewId );
149162 if (platformView != null ) {
150- final FlutterMutatorView mutatorView = mutatorViews . get ( viewId );
151- mutatorView .removeView (platformView );
152- (( FlutterView ) flutterView ). removeView ( mutatorView );
163+ if ( parentView != null ) {
164+ parentView .removeView (platformView );
165+ }
153166 platformViews .remove (viewId );
154- mutatorViews .remove (viewId );
167+ }
168+
169+ if (parentView != null ) {
170+ ((FlutterView ) flutterView ).removeView (parentView );
171+ platformViewParent .remove (viewId );
155172 }
156173 }
157174
@@ -405,7 +422,7 @@ public PlatformViewsController() {
405422 currentFrameUsedPlatformViewIds = new HashSet <>();
406423
407424 platformViews = new SparseArray <>();
408- mutatorViews = new SparseArray <>();
425+ platformViewParent = new SparseArray <>();
409426
410427 motionEventTracker = MotionEventTracker .getInstance ();
411428 }
@@ -681,15 +698,15 @@ void initializePlatformViewIfNeeded(int viewId) {
681698 throw new IllegalStateException (
682699 "Platform view hasn't been initialized from the platform view channel." );
683700 }
684- if (mutatorViews .get (viewId ) != null ) {
701+ if (platformViewParent .get (viewId ) != null ) {
685702 return ;
686703 }
687- final FlutterMutatorView mutatorView =
704+ final FlutterMutatorView parentView =
688705 new FlutterMutatorView (
689706 context , context .getResources ().getDisplayMetrics ().density , androidTouchProcessor );
690- mutatorViews .put (viewId , mutatorView );
691- mutatorView .addView (view );
692- ((FlutterView ) flutterView ).addView (mutatorView );
707+ platformViewParent .put (viewId , parentView );
708+ parentView .addView (view );
709+ ((FlutterView ) flutterView ).addView (parentView );
693710 }
694711
695712 public void attachToFlutterRenderer (FlutterRenderer flutterRenderer ) {
@@ -708,13 +725,14 @@ public void onDisplayPlatformView(
708725 initializeRootImageViewIfNeeded ();
709726 initializePlatformViewIfNeeded (viewId );
710727
711- FlutterMutatorView mutatorView = mutatorViews .get (viewId );
712- mutatorView .readyToDisplay (mutatorsStack , x , y , width , height );
713- mutatorView .setVisibility (View .VISIBLE );
714- mutatorView .bringToFront ();
728+ final FlutterMutatorView parentView = platformViewParent .get (viewId );
729+ parentView .readyToDisplay (mutatorsStack , x , y , width , height );
730+ parentView .setVisibility (View .VISIBLE );
731+ parentView .bringToFront ();
715732
716- FrameLayout .LayoutParams layoutParams = new FrameLayout .LayoutParams (viewWidth , viewHeight );
717- View platformView = platformViews .get (viewId );
733+ final FrameLayout .LayoutParams layoutParams =
734+ new FrameLayout .LayoutParams (viewWidth , viewHeight );
735+ final View platformView = platformViews .get (viewId );
718736 platformView .setLayoutParams (layoutParams );
719737 platformView .bringToFront ();
720738 currentFrameUsedPlatformViewIds .add (viewId );
@@ -723,7 +741,7 @@ public void onDisplayPlatformView(
723741 public void onDisplayOverlaySurface (int id , int x , int y , int width , int height ) {
724742 initializeRootImageViewIfNeeded ();
725743
726- FlutterImageView overlayView = overlayLayerViews .get (id );
744+ final FlutterImageView overlayView = overlayLayerViews .get (id );
727745 if (overlayView .getParent () == null ) {
728746 ((FlutterView ) flutterView ).addView (overlayView );
729747 }
@@ -766,19 +784,19 @@ public void onEndFrame() {
766784 // If one of the surfaces doesn't have an image, the frame may be incomplete and must be
767785 // dropped.
768786 // For example, a toolbar widget painted by Flutter may not be rendered.
769- boolean isFrameRenderedUsingImageReaders =
787+ final boolean isFrameRenderedUsingImageReaders =
770788 flutterViewConvertedToImageView && view .acquireLatestImageViewFrame ();
771789 finishFrame (isFrameRenderedUsingImageReaders );
772790 }
773791
774792 private void finishFrame (boolean isFrameRenderedUsingImageReaders ) {
775793 for (int i = 0 ; i < overlayLayerViews .size (); i ++) {
776- int overlayId = overlayLayerViews .keyAt (i );
777- FlutterImageView overlayView = overlayLayerViews .valueAt (i );
794+ final int overlayId = overlayLayerViews .keyAt (i );
795+ final FlutterImageView overlayView = overlayLayerViews .valueAt (i );
778796
779797 if (currentFrameUsedOverlayLayerIds .contains (overlayId )) {
780798 ((FlutterView ) flutterView ).attachOverlaySurfaceToRender (overlayView );
781- boolean didAcquireOverlaySurfaceImage = overlayView .acquireLatestImage ();
799+ final boolean didAcquireOverlaySurfaceImage = overlayView .acquireLatestImage ();
782800 isFrameRenderedUsingImageReaders &= didAcquireOverlaySurfaceImage ;
783801 } else {
784802 // If the background surface isn't rendered by the image view, then the
@@ -792,22 +810,20 @@ private void finishFrame(boolean isFrameRenderedUsingImageReaders) {
792810 }
793811 }
794812
795- for (int i = 0 ; i < platformViews .size (); i ++) {
796- int viewId = platformViews .keyAt (i );
797- View platformView = platformViews .get (viewId );
798- View mutatorView = mutatorViews .get (viewId );
813+ for (int i = 0 ; i < platformViewParent .size (); i ++) {
814+ final int viewId = platformViewParent .keyAt (i );
815+ final View parentView = platformViewParent .get (viewId );
799816
800817 // Show platform views only if the surfaces have images available in this frame,
801818 // and if the platform view is rendered in this frame.
819+ // The platform view is appended to a mutator view.
802820 //
803821 // Otherwise, hide the platform view, but don't remove it from the view hierarchy yet as
804822 // they are removed when the framework diposes the platform view widget.
805823 if (isFrameRenderedUsingImageReaders && currentFrameUsedPlatformViewIds .contains (viewId )) {
806- platformView .setVisibility (View .VISIBLE );
807- mutatorView .setVisibility (View .VISIBLE );
824+ parentView .setVisibility (View .VISIBLE );
808825 } else {
809- platformView .setVisibility (View .GONE );
810- mutatorView .setVisibility (View .GONE );
826+ parentView .setVisibility (View .GONE );
811827 }
812828 }
813829 }
0 commit comments