react native 原生modal默認(rèn)不能覆蓋Android的statusbar.這對(duì)于一個(gè)強(qiáng)迫癥患者來說真是難受。也開始嘗試將statabar透明但還是不能繪制到statusbar。最后無奈之下只好參考react native的modal去自己寫一個(gè)啦。
參考modal目錄:node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/modal/

3DCF58A7-5C63-45B3-927B-F60E890DA8FF.png
打開ReactModalHostManager 可以看到
public class ReactModalHostManager extends ViewGroupManager<ReactModalHostView>ReactModalHostManager封裝的是ReactModalHostView這個(gè)ViewGroup.
于是打開ReactModalHostView這個(gè)View找到關(guān)鍵代碼
protected void showOrUpdate() {
// If the existing Dialog is currently up, we may need to redraw it or we may be able to update
// the property without having to recreate the dialog
if (mDialog != null) {
if (mPropertyRequiresNewDialog) {
dismiss();
} else {
updateProperties();
return;
}
}
// Reset the flag since we are going to create a new dialog
mPropertyRequiresNewDialog = false;
int theme = R.style.Theme_FullScreenDialog;
if (mAnimationType.equals("fade")) {
theme = R.style.Theme_FullScreenDialogAnimatedFade;
} else if (mAnimationType.equals("slide")) {
theme = R.style.Theme_FullScreenDialogAnimatedSlide;
}
Activity currentActivity = getCurrentActivity();
Context context = currentActivity == null ? getContext() : currentActivity;
mDialog = new Dialog(context, theme);
mDialog.setContentView(getContentView());
updateProperties();
mDialog.setOnShowListener(mOnShowListener);
mDialog.setOnKeyListener(
new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP) {
// We need to stop the BACK button from closing the dialog by default so we capture that
// event and instead inform JS so that it can make the decision as to whether or not to
// allow the back button to close the dialog. If it chooses to, it can just set visible
// to false on the Modal and the Modal will go away
if (keyCode == KeyEvent.KEYCODE_BACK) {
Assertions.assertNotNull(
mOnRequestCloseListener,
"setOnRequestCloseListener must be called by the manager");
mOnRequestCloseListener.onRequestClose(dialog);
return true;
} else {
// We redirect the rest of the key events to the current activity, since the activity
// expects to receive those events and react to them, ie. in the case of the dev menu
Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
return currentActivity.onKeyUp(keyCode, event);
}
}
}
return false;
}
});
mDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
if (mHardwareAccelerated) {
mDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
}
if (currentActivity == null || !currentActivity.isFinishing()) {
mDialog.show();
}
}
可以看到modal其內(nèi)部也封裝的Dialog,那么我們只需要將dialog替換為popwindow是不是也可以做到呢?
于是開始寫代碼。經(jīng)過一番bug調(diào)試完成。效果如下:

modalAndroid.gif
注意:
1:
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));//不設(shè)置 不是全屏 周圍會(huì)有空白部分popupWindow一定要設(shè)置背景否則周圍會(huì)顯示一點(diǎn)空隙。