Hand off presentation properly in VirtualDisplayController.resize() (flutter/engine#17897)

This commit is contained in:
Gary Qian
2020-04-23 15:32:20 -07:00
committed by GitHub
parent a643d8aa67
commit b181ae8f63
2 changed files with 32 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ import android.view.Surface;
import android.view.View;
import android.view.ViewTreeObserver;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import io.flutter.view.TextureRegistry;
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
@@ -62,7 +63,7 @@ class VirtualDisplayController {
private final TextureRegistry.SurfaceTextureEntry textureEntry;
private final OnFocusChangeListener focusChangeListener;
private VirtualDisplay virtualDisplay;
private SingleViewPresentation presentation;
@VisibleForTesting SingleViewPresentation presentation;
private Surface surface;
private VirtualDisplayController(
@@ -145,7 +146,11 @@ class VirtualDisplayController {
public void onViewDetachedFromWindow(View v) {}
});
presentation =
// Create a new SingleViewPresentation and show() it before we cancel() the existing
// presentation. Calling show() and cancel() in this order fixes
// https://github.com/flutter/flutter/issues/26345 and maintains seamless transition
// of the contents of the presentation.
SingleViewPresentation newPresentation =
new SingleViewPresentation(
context,
virtualDisplay.getDisplay(),
@@ -153,7 +158,9 @@ class VirtualDisplayController {
presentationState,
focusChangeListener,
isFocused);
presentation.show();
newPresentation.show();
presentation.cancel();
presentation = newPresentation;
}
public void dispose() {

View File

@@ -57,4 +57,26 @@ public class PlatformViewsControllerTest {
verify(fakeVdController2, times(1)).onFlutterViewAttached(eq(fakeFlutterView));
verify(fakeVdController2, times(1)).onFlutterViewDetached();
}
@Test
public void itCancelsOldPresentationOnResize() {
// Setup test structure.
// Create a fake View that represents the View that renders a Flutter UI.
View fakeFlutterView = new View(RuntimeEnvironment.systemContext);
// Create fake VirtualDisplayControllers. This requires internal knowledge of
// PlatformViewsController. We know that all PlatformViewsController does is
// forward view attachment/detachment calls to it's VirtualDisplayControllers.
//
// TODO(mattcarroll): once PlatformViewsController is refactored into testable
// pieces, remove this test and avoid verifying private behavior.
VirtualDisplayController fakeVdController1 = mock(VirtualDisplayController.class);
SingleViewPresentation presentation = fakeVdController1.presentation;
fakeVdController1.resize(10, 10, null);
assertEquals(fakeVdController1.presentation != presentation, true);
assertEquals(presentation.isShowing(), false);
}
}