Expose updateSystemUiOverlays in FlutterActivity and FlutterFragment (flutter/engine#29013)

This commit is contained in:
Emmanuel Garcia 2021-10-04 19:03:02 -07:00 committed by GitHub
parent 6d0920a925
commit 93ca319487
4 changed files with 43 additions and 8 deletions

View File

@ -1127,6 +1127,13 @@ public class FlutterActivity extends Activity
return false;
}
@Override
public void updateSystemUiOverlays() {
if (delegate != null) {
delegate.updateSystemUiOverlays();
}
}
private boolean stillAttachedForEvent(String event) {
if (delegate == null) {
Log.w(TAG, "FlutterActivity " + hashCode() + " " + event + " called after release.");

View File

@ -507,19 +507,25 @@ import java.util.Arrays;
Log.v(TAG, "onPostResume()");
ensureAlive();
if (flutterEngine != null) {
if (platformPlugin != null) {
// TODO(mattcarroll): find a better way to handle the update of UI overlays than calling
// through
// to platformPlugin. We're implicitly entangling the Window, Activity,
// Fragment,
// and engine all with this one call.
platformPlugin.updateSystemUiOverlays();
}
updateSystemUiOverlays();
} else {
Log.w(TAG, "onPostResume() invoked before FlutterFragment was attached to an Activity.");
}
}
/**
* Refreshes Android's window system UI (AKA system chrome) to match Flutter's desired system
* chrome style.
*/
void updateSystemUiOverlays() {
if (platformPlugin != null) {
// TODO(mattcarroll): find a better way to handle the update of UI overlays than calling
// through to platformPlugin. We're implicitly entangling the Window, Activity,
// Fragment, and engine all with this one call.
platformPlugin.updateSystemUiOverlays();
}
}
/**
* Invoke this from {@code Activity#onPause()} or {@code Fragment#onPause()}.
*
@ -1009,5 +1015,17 @@ import java.util.Arrays;
* <p>This defaults to true, unless a cached engine is used.
*/
boolean shouldRestoreAndSaveState();
/**
* Refreshes Android's window system UI (AKA system chrome) to match Flutter's desired system
* chrome style.
*
* <p>This is useful when using the splash screen API available in Android 12. {@code
* SplashScreenView#remove} resets the system UI colors to the values set prior to the execution
* of the Dart entrypoint. As a result, the values set from Dart are reverted by this API. To
* workaround this issue, call this method after removing the splash screen with {@code
* SplashScreenView#remove}.
*/
void updateSystemUiOverlays();
}
}

View File

@ -1275,6 +1275,13 @@ public class FlutterFragment extends Fragment
return true;
}
@Override
public void updateSystemUiOverlays() {
if (delegate != null) {
delegate.updateSystemUiOverlays();
}
}
/**
* {@inheritDoc}
*

View File

@ -384,6 +384,9 @@ public class FlutterAndroidComponentTest {
@Override
public void detachFromFlutterEngine() {}
@Override
public void updateSystemUiOverlays() {}
@Override
public boolean popSystemNavigator() {
return false;