Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
// 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;
Expand Down Expand Up @@ -388,6 +388,12 @@ void onStart() {
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please add some comment(s) here and below about why we're doing this, with a link to the bug

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link

@zxjzerg zxjzerg Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meet an issue because of this edit. My use case is I use FlutterFragment as a tab in Activity, when user switched to other tabs, I will hide the FlutterFragment. After this commit, every time Activity resumed, the flutterView will be foreced to visible, even the FlutterFragment is set to hide.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please file a new issue with minimum reproducible code, thank you.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please file a new issue with minimum reproducible code, thank you.

this merge doest fix the issue;

this is my code to reproduce,

}

/**
Expand Down Expand Up @@ -574,6 +580,12 @@ void onStop() {
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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -484,6 +485,7 @@ public void itForwardsOnRequestPermissionsResultToFlutterEngine() {
// --- 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();

Expand Down Expand Up @@ -511,6 +513,7 @@ public void itForwardsOnRequestPermissionsResultToFlutterEngine() {
// --- 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();

Expand Down Expand Up @@ -538,6 +541,7 @@ public void itForwardsOnRequestPermissionsResultToFlutterEngine() {
// --- 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();

Expand Down Expand Up @@ -565,6 +569,7 @@ public void itForwardsOnRequestPermissionsResultToFlutterEngine() {
// --- 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();

Expand All @@ -590,6 +595,7 @@ public void itSendsdefaultInitialRouteOnStartIfNotDeepLinkingFromIntent() {
// --- 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();

Expand Down Expand Up @@ -978,6 +984,26 @@ public void itThrowsWhenDelayingTheFirstDrawAndUsingATextureView() {
});
}

@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())
Expand Down