Surface will be created again after the front and back switches (flutter/engine#35767)

This commit is contained in:
Nayuta403
2022-09-09 15:28:11 +08:00
committed by GitHub
parent 33a13335bc
commit 603e316036
2 changed files with 36 additions and 0 deletions

View File

@@ -1522,6 +1522,17 @@ public class FlutterView extends FrameLayout
textInputPlugin.autofill(values);
}
@Override
public void setVisibility(int visibility) {
super.setVisibility(visibility);
// For `FlutterSurfaceView`, setting visibility to the current `FlutterView` will not take
// effect since it is not in the view tree. So override this method and set the surfaceView.
// See https://github.com/flutter/flutter/issues/105203
if (renderSurface instanceof FlutterSurfaceView) {
((FlutterSurfaceView) renderSurface).setVisibility(visibility);
}
}
/**
* Listener that is notified when a {@link io.flutter.embedding.engine.FlutterEngine} is attached
* to/detached from a given {@code FlutterView}.

View File

@@ -1061,6 +1061,31 @@ public class FlutterActivityAndFragmentDelegateTest {
assertEquals(View.GONE, delegate.flutterView.getVisibility());
}
@Test
public void flutterSurfaceViewVisibilityChangedWithFlutterView() {
// ---- Test setup ----
// Create the real object that we're testing.
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost);
delegate.onAttach(ctx);
delegate.onCreateView(null, null, null, 0, true);
// --- Execute the behavior under test ---
// For `FlutterSurfaceView`, setting visibility to the current `FlutterView` will not take
// effect since it is not in the view tree. So we need to make sure that when the visibility of
// `FlutterView` changes, the `FlutterSurfaceView` changes at the same time
// See https://github.com/flutter/flutter/issues/105203
assertEquals(FlutterSurfaceView.class, delegate.flutterView.renderSurface.getClass());
FlutterSurfaceView surfaceView = (FlutterSurfaceView) delegate.flutterView.renderSurface;
// Verify that the `FlutterSurfaceView` is gone.
delegate.flutterView.setVisibility(View.GONE);
assertEquals(View.GONE, surfaceView.getVisibility());
// Verify that the `FlutterSurfaceView` is visible.
delegate.flutterView.setVisibility(View.VISIBLE);
assertEquals(View.VISIBLE, surfaceView.getVisibility());
// Verify that the `FlutterSurfaceView` is invisible.
delegate.flutterView.setVisibility(View.INVISIBLE);
assertEquals(View.INVISIBLE, surfaceView.getVisibility());
}
@Test
public void itDoesNotDelayTheFirstDrawWhenRequestedAndWithAProvidedSplashScreen() {
when(mockHost.provideSplashScreen())