From 94376125a0fe90629130918fb4edab9b5d0bc1cc Mon Sep 17 00:00:00 2001 From: ColdPaleLight Date: Tue, 12 Jul 2022 15:05:05 +0800 Subject: [PATCH] Set the 'visibility' of 'FlutterView' to the previous one in 'FragmentActivityAndFragment.onStart' (flutter/engine#34601) --- .../FlutterActivityAndFragmentDelegate.java | 6 +++++- ...FlutterActivityAndFragmentDelegateTest.java | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java index 93baa6e6b9..848ed43962 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java @@ -87,6 +87,7 @@ import java.util.List; private boolean isFlutterUiDisplayed; private boolean isFirstFrameRendered; private boolean isAttached; + private Integer previousVisibility; @NonNull private final FlutterUiDisplayListener flutterUiDisplayListener = @@ -399,7 +400,9 @@ import java.util.List; // 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); + if (previousVisibility != null) { + flutterView.setVisibility(previousVisibility); + } } /** @@ -599,6 +602,7 @@ import java.util.List; // 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 + previousVisibility = flutterView.getVisibility(); flutterView.setVisibility(View.GONE); } diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java index 745639d8ef..6fb840f3c9 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java @@ -1038,11 +1038,27 @@ public class FlutterActivityAndFragmentDelegateTest { // Verify that the flutterView is visible. assertEquals(View.VISIBLE, delegate.flutterView.getVisibility()); delegate.onStop(); - // Verify that the flutterView is not visible. + // Verify that the flutterView is gone. assertEquals(View.GONE, delegate.flutterView.getVisibility()); delegate.onStart(); // Verify that the flutterView is visible. assertEquals(View.VISIBLE, delegate.flutterView.getVisibility()); + + delegate.flutterView.setVisibility(View.INVISIBLE); + delegate.onStop(); + // Verify that the flutterView is gone. + assertEquals(View.GONE, delegate.flutterView.getVisibility()); + delegate.onStart(); + // Verify that the flutterView is invisible. + assertEquals(View.INVISIBLE, delegate.flutterView.getVisibility()); + + delegate.flutterView.setVisibility(View.GONE); + delegate.onStop(); + // Verify that the flutterView is gone. + assertEquals(View.GONE, delegate.flutterView.getVisibility()); + delegate.onStart(); + // Verify that the flutterView is gone. + assertEquals(View.GONE, delegate.flutterView.getVisibility()); } @Test