Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 802ef43

Browse files
author
haoan.zzj
committed
Change visibility of FlutterView when onStop/onStart
1 parent b44cfce commit 802ef43

File tree

4 files changed

+11
-34
lines changed

4 files changed

+11
-34
lines changed

shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ void onStart() {
388388
Log.v(TAG, "onStart()");
389389
ensureAlive();
390390
doInitialFlutterViewRun();
391-
flutterView.onStart();
391+
flutterView.setVisibility(View.VISIBLE);
392392
}
393393

394394
/**
@@ -575,7 +575,7 @@ void onStop() {
575575
Log.v(TAG, "onStop()");
576576
ensureAlive();
577577
flutterEngine.getLifecycleChannel().appIsPaused();
578-
flutterView.onStop();
578+
flutterView.setVisibility(View.GONE);
579579
}
580580

581581
/**

shell/platform/android/io/flutter/embedding/android/FlutterView.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,20 +1420,6 @@ public void autofill(SparseArray<AutofillValue> values) {
14201420
textInputPlugin.autofill(values);
14211421
}
14221422

1423-
// Invoke this from {@code FlutterActivityAndFragmentDelegate#onStart()}
1424-
/* package */ void onStart() {
1425-
if (flutterSurfaceView != null) {
1426-
flutterSurfaceView.setVisibility(View.VISIBLE);
1427-
}
1428-
}
1429-
1430-
// Invoke this from {@code FlutterActivityAndFragmentDelegate#onStop()}
1431-
/* package */ void onStop() {
1432-
if (flutterSurfaceView != null) {
1433-
flutterSurfaceView.setVisibility(View.GONE);
1434-
}
1435-
}
1436-
14371423
/**
14381424
* Listener that is notified when a {@link io.flutter.embedding.engine.FlutterEngine} is attached
14391425
* to/detached from a given {@code FlutterView}.

shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.graphics.Color;
2222
import android.graphics.drawable.ColorDrawable;
2323
import android.net.Uri;
24+
import android.view.View;
2425
import androidx.annotation.NonNull;
2526
import androidx.lifecycle.Lifecycle;
2627
import io.flutter.FlutterInjector;
@@ -984,21 +985,23 @@ public void itThrowsWhenDelayingTheFirstDrawAndUsingATextureView() {
984985
}
985986

986987
@Test
987-
public void itNotifiesFlutterViewWhenOnStartAndOnStop() {
988+
public void itChangesFlutterViewVisibilityWhenOnStartAndOnStop() {
988989
// ---- Test setup ----
989990
// Create the real object that we're testing.
990991
FlutterActivityAndFragmentDelegate delegate = new FlutterActivityAndFragmentDelegate(mockHost);
991992

992993
// --- Execute the behavior under test ---
993994
delegate.onAttach(RuntimeEnvironment.application);
994995
delegate.onCreateView(null, null, null, 0, true);
995-
delegate.flutterView = mock(FlutterView.class);
996996
delegate.onStart();
997-
// Verify that the onStart of flutterView was called.
998-
verify(delegate.flutterView, times(1)).onStart();
997+
// Verify that the flutterView is visible.
998+
assertEquals(View.VISIBLE, delegate.flutterView.getVisibility());
999999
delegate.onStop();
1000-
// Verify that the onStop of flutterView was called.
1001-
verify(delegate.flutterView, times(1)).onStop();
1000+
// Verify that the flutterView is not visible.
1001+
assertEquals(View.GONE, delegate.flutterView.getVisibility());
1002+
delegate.onStart();
1003+
// Verify that the flutterView is visible.
1004+
assertEquals(View.VISIBLE, delegate.flutterView.getVisibility());
10021005
}
10031006

10041007
@Test

shell/platform/android/test/io/flutter/embedding/android/FlutterViewTest.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -687,18 +687,6 @@ public void itRegistersAndUnregistersToWindowManager() {
687687
verify(windowInfoRepo, times(1)).removeWindowLayoutInfoListener(any());
688688
}
689689

690-
@Test
691-
public void itChangesSurfaceViewVisibilityWhenOnStartAndOnStop() {
692-
Context context = Robolectric.setupActivity(Activity.class);
693-
FlutterView flutterView = spy(new FlutterView(context));
694-
FlutterSurfaceView flutterSurfaceView = (FlutterSurfaceView) flutterView.renderSurface;
695-
assertEquals(View.VISIBLE, flutterSurfaceView.getVisibility());
696-
flutterView.onStop();
697-
assertEquals(View.GONE, flutterSurfaceView.getVisibility());
698-
flutterView.onStart();
699-
assertEquals(View.VISIBLE, flutterSurfaceView.getVisibility());
700-
}
701-
702690
@Test
703691
public void itSendsHingeDisplayFeatureToFlutter() {
704692
Context context = Robolectric.setupActivity(Activity.class);

0 commit comments

Comments
 (0)