Fix inverted setSystemUIChangeCallback (flutter/engine#36248)

This commit is contained in:
Jia Hao
2022-09-20 23:37:11 +08:00
committed by GitHub
parent 24edd79e45
commit 2e404ea083
2 changed files with 34 additions and 5 deletions

View File

@@ -239,12 +239,12 @@ public class PlatformPlugin {
// controls. Another common action is to set a timer to dismiss
// the system bars and restore the fullscreen mode that was
// previously enabled.
platformChannel.systemChromeChanged(false);
platformChannel.systemChromeChanged(true);
} else {
// The system bars are NOT visible. Make any desired adjustments
// to your UI, such as hiding the action bar or other
// navigational controls.
platformChannel.systemChromeChanged(true);
platformChannel.systemChromeChanged(false);
}
});
}

View File

@@ -372,7 +372,36 @@ public class PlatformPluginTest {
}
@Test
public void setSystemUiModeListener() {
public void setSystemUiModeListener_overlaysAreHidden() {
ActivityController<Activity> controller = Robolectric.buildActivity(Activity.class);
controller.setup();
Activity fakeActivity = controller.get();
PlatformChannel fakePlatformChannel = mock(PlatformChannel.class);
PlatformPlugin platformPlugin = new PlatformPlugin(fakeActivity, fakePlatformChannel);
// Subscribe to system UI visibility events.
platformPlugin.mPlatformMessageHandler.setSystemUiChangeListener();
// Simulate system UI changed to full screen.
fakeActivity
.getWindow()
.getDecorView()
.dispatchSystemUiVisibilityChanged(View.SYSTEM_UI_FLAG_FULLSCREEN);
// No events should have been sent to the platform channel yet. They are scheduled for
// the next frame.
verify(fakePlatformChannel, never()).systemChromeChanged(anyBoolean());
// Simulate the next frame.
ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
// Now the platform channel should receive the event.
verify(fakePlatformChannel).systemChromeChanged(false);
}
@Test
public void setSystemUiModeListener_overlaysAreVisible() {
ActivityController<Activity> controller = Robolectric.buildActivity(Activity.class);
controller.setup();
Activity fakeActivity = controller.get();
@@ -383,7 +412,7 @@ public class PlatformPluginTest {
// Subscribe to system Ui visibility events.
platformPlugin.mPlatformMessageHandler.setSystemUiChangeListener();
// Simulate changing of the system ui visibility.
// Simulate system UI changed to *not* full screen.
fakeActivity.getWindow().getDecorView().dispatchSystemUiVisibilityChanged(0);
// No events should have been sent to the platform channel yet. They are scheduled for
@@ -394,7 +423,7 @@ public class PlatformPluginTest {
ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
// Now the platform channel should receive the event.
verify(fakePlatformChannel).systemChromeChanged(anyBoolean());
verify(fakePlatformChannel).systemChromeChanged(true);
}
@Config(sdk = 28)