fix(android)!: styleDefault not working on new devices (#238)

This commit is contained in:
jcesarmobile 2022-09-05 23:17:55 +02:00 committed by GitHub
parent b7b6c66cbe
commit 49b94aed6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,6 +26,9 @@ import android.view.View;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import org.apache.cordova.CallbackContext; import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaArgs; import org.apache.cordova.CordovaArgs;
import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaInterface;
@ -253,8 +256,9 @@ public class StatusBar extends CordovaPlugin {
private void setStatusBarStyle(final String style) { private void setStatusBarStyle(final String style) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (style != null && !style.isEmpty()) { if (style != null && !style.isEmpty()) {
View decorView = cordova.getActivity().getWindow().getDecorView(); Window window = cordova.getActivity().getWindow();
int uiOptions = decorView.getSystemUiVisibility(); View decorView = window.getDecorView();
WindowInsetsControllerCompat windowInsetsControllerCompat = WindowCompat.getInsetsController(window, decorView);
String[] darkContentStyles = { String[] darkContentStyles = {
"default", "default",
@ -267,12 +271,12 @@ public class StatusBar extends CordovaPlugin {
}; };
if (Arrays.asList(darkContentStyles).contains(style.toLowerCase())) { if (Arrays.asList(darkContentStyles).contains(style.toLowerCase())) {
decorView.setSystemUiVisibility(uiOptions | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); windowInsetsControllerCompat.setAppearanceLightStatusBars(true);
return; return;
} }
if (Arrays.asList(lightContentStyles).contains(style.toLowerCase())) { if (Arrays.asList(lightContentStyles).contains(style.toLowerCase())) {
decorView.setSystemUiVisibility(uiOptions & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); windowInsetsControllerCompat.setAppearanceLightStatusBars(false);
return; return;
} }