diff --git a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index de4208e546..1bdc187d54 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -15,6 +15,8 @@ import android.os.Build; import android.view.HapticFeedbackConstants; import android.view.SoundEffectConstants; import android.view.View; +import android.view.Window; +import android.util.Log; import io.flutter.plugin.common.ActivityLifecycleListener; import io.flutter.plugin.common.MethodChannel.MethodCallHandler; @@ -30,6 +32,7 @@ import org.json.JSONObject; */ public class PlatformPlugin implements MethodCallHandler, ActivityLifecycleListener { private final Activity mActivity; + private JSONObject mCurrentTheme; public static final int DEFAULT_SYSTEM_UI = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; private static final String kTextPlainFormat = "text/plain"; @@ -60,7 +63,7 @@ public class PlatformPlugin implements MethodCallHandler, ActivityLifecycleListe setSystemChromeEnabledSystemUIOverlays((JSONArray) arguments); result.success(null); } else if (method.equals("SystemChrome.setSystemUIOverlayStyle")) { - setSystemChromeSystemUIOverlayStyle((String) arguments); + setSystemChromeSystemUIOverlayStyle((JSONObject) arguments); result.success(null); } else if (method.equals("SystemNavigator.pop")) { popSystemNavigator(); @@ -218,14 +221,70 @@ public class PlatformPlugin implements MethodCallHandler, ActivityLifecycleListe updateSystemUiOverlays(); } - private void updateSystemUiOverlays() { + private void updateSystemUiOverlays(){ mActivity.getWindow().getDecorView().setSystemUiVisibility(mEnabledOverlays); + if (mCurrentTheme != null) { + setSystemChromeSystemUIOverlayStyle(mCurrentTheme); + } } - private void setSystemChromeSystemUIOverlayStyle(String style) { - // You can change the navigation bar color (including translucent colors) - // in Android, but you can't change the color of the navigation buttons, - // so LIGHT vs DARK effectively isn't supported in Android. + private void setSystemChromeSystemUIOverlayStyle(JSONObject message) { + Window window = mActivity.getWindow(); + View view = window.getDecorView(); + int flags = view.getSystemUiVisibility(); + try { + // You can change the navigation bar color (including translucent colors) + // in Android, but you can't change the color of the navigation buttons until Android O. + // LIGHT vs DARK effectively isn't supported until then. + // Build.VERSION_CODES.O + if (Build.VERSION.SDK_INT >= 26) { + if (!message.isNull("systemNavigationBarIconBrightness")) { + String systemNavigationBarIconBrightness = message.getString("systemNavigationBarIconBrightness"); + switch (systemNavigationBarIconBrightness) { + case "Brightness.dark": + //View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR + flags |= 0x10; + break; + case "Brightness.light": + if ((flags & 0x10) == 0x10) { + flags ^= 0x10; + } + break; + } + } + if (!message.isNull("systemNavigationBarColor")) { + window.setNavigationBarColor(message.getInt("systemNavigationBarColor")); + } + } + // Build.VERSION_CODES.M + if (Build.VERSION.SDK_INT >= 23) { + if (!message.isNull("statusBarIconBrightness")) { + String statusBarIconBrightness = message.getString("statusBarIconBrightness"); + switch (statusBarIconBrightness) { + case "Brightness.dark": + // View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR + flags |= 0x2000; + break; + case "Brightness.light": + if ((flags & 0x2000) == 0x2000) { + flags ^= 0x2000; + } + break; + } + } + if (!message.isNull("statusBarColor")) { + window.setStatusBarColor(message.getInt("statusBarColor")); + } + } + if (!message.isNull("systemNavigationBarDividerColor")) { + // Not availible until Android P. + // window.setNavigationBarDividerColor(systemNavigationBarDividerColor); + } + view.setSystemUiVisibility(flags); + mCurrentTheme = message; + } catch (JSONException err) { + Log.i("PlatformPlugin", err.toString()); + } } private void popSystemNavigator() { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm index c312cac28b..51df7e1aec 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformPlugin.mm @@ -137,11 +137,12 @@ using namespace shell; ![overlays containsObject:@"SystemUiOverlay.top"]; } -- (void)setSystemChromeSystemUIOverlayStyle:(NSString*)style { - UIStatusBarStyle statusBarStyle; - if ([style isEqualToString:@"SystemUiOverlayStyle.light"]) +- (void)setSystemChromeSystemUIOverlayStyle:(NSDictionary*)message { + NSString* style = message[@"statusBarBrightness"] + UIStatusBarStyle statusBarStyle + if ([style isEqualToString:@"Brightness.light"]) statusBarStyle = UIStatusBarStyleLightContent; - else if ([style isEqualToString:@"SystemUiOverlayStyle.dark"]) + else if ([style isEqualToString:@"Brightness.dark"]) statusBarStyle = UIStatusBarStyleDefault; else return;