content: package com.mf.translucentmodal;
  
  import android.annotation.TargetApi;
  import android.app.Activity;
  import android.app.Dialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.graphics.Color;
  import android.os.Build;
  import androidx.core.view.ViewCompat;
  import android.view.View;
  import android.view.Window;
  import android.view.WindowInsets;
  import android.view.WindowManager;
  
  import com.facebook.react.bridge.ReactContext;
  import com.facebook.react.views.modal.ReactModalHostView;
  
  /**
   * React Native Modal（Android） 延伸到状态栏
   * 由于React Native 提供的 Modal 组件不能延伸到状态栏，因此，只有对原生{@link ReactModalHostView}实现修改。
   */
  public class TranslucentModalHostView extends ReactModalHostView {
  
      public TranslucentModalHostView(Context context) {
          super(context);
      }
  
      @Override
      protected void setOnShowListener(DialogInterface.OnShowListener listener) {
          super.setOnShowListener(listener);
      }
  
      @Override
      protected void setOnRequestCloseListener(OnRequestCloseListener listener) {
          super.setOnRequestCloseListener(listener);
      }
  
      @Override
      protected void setTransparent(boolean transparent) {
          super.setTransparent(transparent);
      }
  
      @Override
      protected void setHardwareAccelerated(boolean hardwareAccelerated) {
          super.setHardwareAccelerated(hardwareAccelerated);
      }
  
      @Override
      protected void setAnimationType(String animationType) {
          super.setAnimationType(animationType);
      }
  
      @Override
      protected void showOrUpdate() {
          super.showOrUpdate();
          Dialog dialog = getDialog();
          if (dialog != null) {
              setStatusBarTranslucent(dialog.getWindow(), true);
              setStatusBarColor(dialog.getWindow(), Color.TRANSPARENT);
              setStatusBarStyle(dialog.getWindow(), isDark());
          }
      }
  
      @TargetApi(23)
      private boolean isDark() {
          Activity activity = ((ReactContext) getContext()).getCurrentActivity();
          // fix activity NPE
          if (activity == null) {
              return true;
          }
          return (activity.getWindow().getDecorView().getSystemUiVisibility() & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) != 0;
      }
  
      public static void setStatusBarTranslucent(Window window, boolean translucent) {
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
              View decorView = window.getDecorView();
              if (translucent) {
                  decorView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
                      @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                      @Override
                      public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                          WindowInsets defaultInsets = v.onApplyWindowInsets(insets);
                          return defaultInsets.replaceSystemWindowInsets(
                                  defaultInsets.getSystemWindowInsetLeft(),
                                  0,
                                  defaultInsets.getSystemWindowInsetRight(),
                                  defaultInsets.getSystemWindowInsetBottom());
                      }
                  });
              } else {
                  decorView.setOnApplyWindowInsetsListener(null);
              }
              ViewCompat.requestApplyInsets(decorView);
          }
      }
  
      public static void setStatusBarColor(final Window window, int color) {
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
              window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
              window.setStatusBarColor(color);
          }
      }
  
      public static void setStatusBarStyle(Window window, boolean dark) {
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
              View decorView = window.getDecorView();
              decorView.setSystemUiVisibility(
                      dark ? View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR : 0);
          }
      }
  }
  
  