|
9 | 9 |
|
10 | 10 | import android.app.Activity;
|
11 | 11 | import android.app.Dialog;
|
| 12 | +import android.graphics.Color; |
| 13 | +import android.graphics.drawable.ColorDrawable; |
| 14 | +import android.os.Bundle; |
12 | 15 | import android.view.KeyEvent;
|
13 | 16 | import android.view.Window;
|
| 17 | +import android.widget.FrameLayout; |
14 | 18 | import androidx.annotation.Nullable;
|
| 19 | +import androidx.core.graphics.Insets; |
| 20 | +import androidx.core.view.ViewCompat; |
| 21 | +import androidx.core.view.WindowInsetsCompat; |
15 | 22 | import com.facebook.common.logging.FLog;
|
16 | 23 | import com.facebook.react.R;
|
17 | 24 | import com.facebook.react.common.ReactConstants;
|
18 | 25 | import com.facebook.react.common.SurfaceDelegate;
|
19 | 26 | import com.facebook.react.devsupport.interfaces.DevSupportManager;
|
20 | 27 | import com.facebook.react.devsupport.interfaces.RedBoxHandler;
|
| 28 | +import java.util.Objects; |
21 | 29 |
|
22 | 30 | /**
|
23 | 31 | * The implementation of SurfaceDelegate with {@link Activity}. This is the default SurfaceDelegate
|
@@ -102,6 +110,29 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
|
102 | 110 | }
|
103 | 111 | return super.onKeyUp(keyCode, event);
|
104 | 112 | }
|
| 113 | + |
| 114 | + @Override |
| 115 | + protected void onCreate(Bundle savedInstanceState) { |
| 116 | + Objects.requireNonNull(getWindow()); |
| 117 | + // set background color so it will show below transparent system bars on forced |
| 118 | + // edge-to-edge |
| 119 | + getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK)); |
| 120 | + // register insets listener to update margins on the ReactRootView to avoid overlap w/ |
| 121 | + // system bars |
| 122 | + int insetsType = |
| 123 | + WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout(); |
| 124 | + |
| 125 | + ViewCompat.setOnApplyWindowInsetsListener( |
| 126 | + mRedBoxContentView, |
| 127 | + (view, windowInsetsCompat) -> { |
| 128 | + Insets insets = windowInsetsCompat.getInsets(insetsType); |
| 129 | + |
| 130 | + FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) view.getLayoutParams(); |
| 131 | + lp.setMargins(insets.left, insets.top, insets.right, insets.bottom); |
| 132 | + |
| 133 | + return WindowInsetsCompat.CONSUMED; |
| 134 | + }); |
| 135 | + } |
105 | 136 | };
|
106 | 137 | mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
107 | 138 | mDialog.setContentView(mRedBoxContentView);
|
|
0 commit comments