Skip to content

Commit 0273fab

Browse files
authored
Hand off presentation properly in VirtualDisplayController.resize() (flutter#17897)
1 parent 12012f1 commit 0273fab

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import android.view.View;
1717
import android.view.ViewTreeObserver;
1818
import androidx.annotation.NonNull;
19+
import androidx.annotation.VisibleForTesting;
1920
import io.flutter.view.TextureRegistry;
2021

2122
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
@@ -62,7 +63,7 @@ public static VirtualDisplayController create(
6263
private final TextureRegistry.SurfaceTextureEntry textureEntry;
6364
private final OnFocusChangeListener focusChangeListener;
6465
private VirtualDisplay virtualDisplay;
65-
private SingleViewPresentation presentation;
66+
@VisibleForTesting SingleViewPresentation presentation;
6667
private Surface surface;
6768

6869
private VirtualDisplayController(
@@ -145,15 +146,21 @@ public void run() {
145146
public void onViewDetachedFromWindow(View v) {}
146147
});
147148

148-
presentation =
149+
// Create a new SingleViewPresentation and show() it before we cancel() the existing
150+
// presentation. Calling show() and cancel() in this order fixes
151+
// https://github.com/flutter/flutter/issues/26345 and maintains seamless transition
152+
// of the contents of the presentation.
153+
SingleViewPresentation newPresentation =
149154
new SingleViewPresentation(
150155
context,
151156
virtualDisplay.getDisplay(),
152157
accessibilityEventsDelegate,
153158
presentationState,
154159
focusChangeListener,
155160
isFocused);
156-
presentation.show();
161+
newPresentation.show();
162+
presentation.cancel();
163+
presentation = newPresentation;
157164
}
158165

159166
public void dispose() {

shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,26 @@ public void itNotifiesVirtualDisplayControllersOfViewAttachmentAndDetachment() {
5757
verify(fakeVdController2, times(1)).onFlutterViewAttached(eq(fakeFlutterView));
5858
verify(fakeVdController2, times(1)).onFlutterViewDetached();
5959
}
60+
61+
@Test
62+
public void itCancelsOldPresentationOnResize() {
63+
// Setup test structure.
64+
// Create a fake View that represents the View that renders a Flutter UI.
65+
View fakeFlutterView = new View(RuntimeEnvironment.systemContext);
66+
67+
// Create fake VirtualDisplayControllers. This requires internal knowledge of
68+
// PlatformViewsController. We know that all PlatformViewsController does is
69+
// forward view attachment/detachment calls to it's VirtualDisplayControllers.
70+
//
71+
// TODO(mattcarroll): once PlatformViewsController is refactored into testable
72+
// pieces, remove this test and avoid verifying private behavior.
73+
VirtualDisplayController fakeVdController1 = mock(VirtualDisplayController.class);
74+
75+
SingleViewPresentation presentation = fakeVdController1.presentation;
76+
77+
fakeVdController1.resize(10, 10, null);
78+
79+
assertEquals(fakeVdController1.presentation != presentation, true);
80+
assertEquals(presentation.isShowing(), false);
81+
}
6082
}

0 commit comments

Comments
 (0)