Change visibility of FlutterView when onStop/onStart (flutter/engine#30897)

This commit is contained in:
ColdPaleLight
2022-01-21 05:05:15 +08:00
committed by GitHub
parent c225edfb0a
commit 5efc2ba8d0
2 changed files with 39 additions and 1 deletions

View File

@@ -74,7 +74,7 @@ import java.util.Arrays;
// to this FlutterActivityAndFragmentDelegate.
@NonNull private Host host;
@Nullable private FlutterEngine flutterEngine;
@Nullable private FlutterView flutterView;
@VisibleForTesting @Nullable FlutterView flutterView;
@Nullable private PlatformPlugin platformPlugin;
@VisibleForTesting @Nullable OnPreDrawListener activePreDrawListener;
private boolean isFlutterEngineFromHost;
@@ -388,6 +388,12 @@ import java.util.Arrays;
Log.v(TAG, "onStart()");
ensureAlive();
doInitialFlutterViewRun();
// This is a workaround for a bug on some OnePlus phones. The visibility of the application
// window is still true after locking the screen on some OnePlus phones, and shows a black
// screen when unlocked. We can work around this by changing the visibility of FlutterView in
// onStart and onStop.
// See https://github.com/flutter/flutter/issues/93276
flutterView.setVisibility(View.VISIBLE);
}
/**
@@ -574,6 +580,12 @@ import java.util.Arrays;
Log.v(TAG, "onStop()");
ensureAlive();
flutterEngine.getLifecycleChannel().appIsPaused();
// This is a workaround for a bug on some OnePlus phones. The visibility of the application
// window is still true after locking the screen on some OnePlus phones, and shows a black
// screen when unlocked. We can work around this by changing the visibility of FlutterView in
// onStart and onStop.
// See https://github.com/flutter/flutter/issues/93276
flutterView.setVisibility(View.GONE);
}
/**

View File

@@ -21,6 +21,7 @@ import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.lifecycle.Lifecycle;
import io.flutter.FlutterInjector;
@@ -484,6 +485,7 @@ public class FlutterActivityAndFragmentDelegateTest {
// --- Execute the behavior under test ---
// The FlutterEngine is set up in onAttach().
delegate.onAttach(RuntimeEnvironment.application);
delegate.onCreateView(null, null, null, 0, true);
// Emulate app start.
delegate.onStart();
@@ -511,6 +513,7 @@ public class FlutterActivityAndFragmentDelegateTest {
// --- Execute the behavior under test ---
// The FlutterEngine is set up in onAttach().
delegate.onAttach(RuntimeEnvironment.application);
delegate.onCreateView(null, null, null, 0, true);
// Emulate app start.
delegate.onStart();
@@ -538,6 +541,7 @@ public class FlutterActivityAndFragmentDelegateTest {
// --- Execute the behavior under test ---
// The FlutterEngine is set up in onAttach().
delegate.onAttach(RuntimeEnvironment.application);
delegate.onCreateView(null, null, null, 0, true);
// Emulate app start.
delegate.onStart();
@@ -565,6 +569,7 @@ public class FlutterActivityAndFragmentDelegateTest {
// --- Execute the behavior under test ---
// The FlutterEngine is set up in onAttach().
delegate.onAttach(RuntimeEnvironment.application);
delegate.onCreateView(null, null, null, 0, true);
// Emulate app start.
delegate.onStart();
@@ -590,6 +595,7 @@ public class FlutterActivityAndFragmentDelegateTest {
// --- Execute the behavior under test ---
// The FlutterEngine is set up in onAttach().
delegate.onAttach(RuntimeEnvironment.application);
delegate.onCreateView(null, null, null, 0, true);
// Emulate app start.
delegate.onStart();
@@ -978,6 +984,26 @@ public class FlutterActivityAndFragmentDelegateTest {
});
}
@Test
public void itChangesFlutterViewVisibilityWhenOnStartAndOnStop() {
// ---- Test setup ----
// Create the real object that we're testing.
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost);
// --- Execute the behavior under test ---
delegate.onAttach(RuntimeEnvironment.application);
delegate.onCreateView(null, null, null, 0, true);
delegate.onStart();
// Verify that the flutterView is visible.
assertEquals(View.VISIBLE, delegate.flutterView.getVisibility());
delegate.onStop();
// Verify that the flutterView is not visible.
assertEquals(View.GONE, delegate.flutterView.getVisibility());
delegate.onStart();
// Verify that the flutterView is visible.
assertEquals(View.VISIBLE, delegate.flutterView.getVisibility());
}
@Test
public void itDoesNotDelayTheFirstDrawWhenRequestedAndWithAProvidedSplashScreen() {
when(mockHost.provideSplashScreen())