the status bar issue of react-native Modal on Android ( RN v0.57.0)
Problem: When use Modal in react-native, the status bar is not included if you make a full-screen mask like a translucent background. I found the below method is able to make the status-bar to be included in.
forgive my poor English, I'm practicing.
what I do is to replace the default Modal implementation on Android as below.
1. make directory like below , and copy code from

code in file 'ModifiedReactModalHostManager' and 'ModifiedReactModalHostView' is completely copied from
'react-native/com/facebook/react/views/modal/ReactModalHostManager' and
'react-native/com/facebook/react/views/modal/ReactModalHostView'. And replace all 'ReactModalHostView' words with 'ModifiedReactModalHostView' in both files.
2. use a self-defined MainReactPackage instead of the default react-native MainReactPackage.
public class MyMainReactPackage extends MainReactPackage {
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
List<ViewManager> list = super.createViewManagers(reactContext);
for (int i = 0; i < list.size(); i++) {
if (list.get(i) instanceof ReactModalHostManager) {
list.remove(i);
list.add(new ModifiedReactModalHostManager());
break;
}
}
return list;
}
}
in your ReactApplication class , replace MainReactPackage.
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MyMainReactPackage() // previously is MainReactPackage()
);
}
as above, replace the ReactModalHostManager with ModifiedReactModalHostManager. Now every Modal in react-native code will use the implementation of ModifiedReactModalHostView rather than the default ReactModalHostView.
3. include the status bar of Modal in ModifiedReactModalHostView.
replace function `private void updateProperties` with code below.
private void updateProperties() {
Assertions.assertNotNull(mDialog, "mDialog must exist when we call updateProperties");
Window window = mDialog.getWindow();
mDialog.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
);
Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
FrameLayout content = window.getDecorView().findViewById(android.R.id.content);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) content.getLayoutParams();
View preContentView = currentActivity.getWindow().findViewById(android.R.id.content);
if (preContentView != null) {
layoutParams.height = currentActivity.getWindow().findViewById(android.R.id.content).getHeight();
}
content.setLayoutParams(layoutParams);
}
if (mTransparent) {
mDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
} else {
mDialog.getWindow().setDimAmount(0.5f);
mDialog.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_DIM_BEHIND,
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
}
}
Then it is OK to build application and test your Modal.
Note that this method is related to your react-native's version, when your rn's version changes, you should also make change to the ModifiedModal to make sure it is suitable.
练英语,练英语的,兄弟们别笑,也是方便遇到这个问题的国际友人们嘛。。。
the status bar issue of react-native Modal on Android ( RN v0.57.0)的更多相关文章
- React Native App设置&Android版发布
React Native系列 <逻辑性最强的React Native环境搭建与调试> <ReactNative开发工具有这一篇足矣> <解决React Native un ...
- React Native移植原生Android
(一)前言 之前已经写过了有关React Native移植原生Android项目的文章,不过因为RN版本更新的原因吧,跟着以前的文章可能会出现一些问题,对于初学者来讲还是会有很多疑难的困惑的,而且官方 ...
- 将React Native集成至Android原生应用
将React Native集成至Android原生应用 Android Studio 2.1 Preview 4生成的空项目 react-native 环境 0.22.2 初次编译后apk有1.1M, ...
- React Native hot reloading & Android & iOS
React Native hot reloading & Android & iOS https://facebook.github.io/react-native/docs/debu ...
- React Native 4 for Android源码分析 一《JNI智能指针之介绍篇》
文/ Tamic: http://blog.csdn.net/sk719887916/article/details/53455441 原文:http://blog.csdn.net/eewolf/a ...
- 关于React Native项目在android上UI性能调试实践
我们尽最大的努力来争取使UI组件的性能如丝般顺滑,但有的时候这根本不可能做到.要知道,Android有超过一万种不同型号的手机,而在框架底层进行软件渲染的时候是统一处理的,这意味着你没办法像iOS那样 ...
- React Native工程修改Android包名
默认初始化的React Native工程,生成Android工程的时候,包名默认是React Native工程的名字,跟一般Android工程com.company.xxx不一样. 这时候就需要手动修 ...
- React Native升级方法——升级到最新版本0.59
React Native最近有大动作,于2019年3月12日发布新版本0.59.主要有两点值得升级:支持React Hooks:升级了JavaScriptCore,使Android性能有大幅提升.据用 ...
- 【React Native开发】React Native移植原生Android项目(4)
),React Native技术交流4群(458982758),请不要反复加群!欢迎各位大牛,React Native技术爱好者加入交流!同一时候博客左側欢迎微信扫描关注订阅号,移动技术干货,精彩文章 ...
随机推荐
- 类型限定词——const
类型限定词有三个:const volatile restrict. const:一般也叫常量修饰符. 作用:是修饰变量,被修饰的变量就变成常量了,不能被二次修改了. const int a=12:a ...
- c#基础之异常处理及自定义异常
一.什么是c#中的异常? 异常是程序运行中发生的错误,异常处理是程序的一部分.c#中的异常类主要是直接或者间接的派生于 System.Exception类 ,也就是说System.Exception类 ...
- react native第一天--------KnightRider
今天是2017年6月8,是我的项目react native-CRM(用户关系管理)的第一天,一早就配置了一上午Mac的环境,然后运行项目,在react-native init project的时候一直 ...
- 随手心得(浅谈iOS)
前一段时间去一个公司面试,面试官问我关于iOS的ARC,当然ARC对于一般有经验的iOS程序员来说一般不是什么问题,但是他问我苹果是怎么实现的,我就说通过地址指针解决的,然后他问我那苹果指针指向地址是 ...
- DevExpress v18.2新版亮点——DevExtreme篇(一)
行业领先的.NET界面控件2018年第二次重大更新——DevExpress v18.2日前正式发布,本站将以连载的形式为大家介绍新版本新功能.本文将介绍了DevExtreme Complete Sub ...
- python基础学习之文件操作&函数
1.文件处理相关 1.编码问题 ①python2与python3中的默认编码: py2默认使用ASCII码,py3默认使用utf-8 ②为什么会出现中文乱码,中文乱码的情况有哪些? #sys.stdo ...
- 主成分分析法PCA原理
PCA(Principal Component Analysis)是一种常用的数据分析方法.PCA通过线性变换将原始数据变换为一组各维度线性无关的表示,可用于提取数据的主要特征分量,常用于高维数据的降 ...
- Linux 使用硬盘
一.硬盘分区规划: swap(交换,掉期交易,互换)分区:虚拟内存使用,不能保存用户信息. boot(引导)分区:保存启动系统得相关文件. root(根)分区:放置系统文件得根,所有文件都保存在该分区 ...
- Hadoop 搭建集群的步骤
1.安装jdk,配置环境变量 root@localhost java]# vi /etc/profile 在profile中添加如下内容: #set java environmentexport J ...
- Idea常用功能汇总
1.格式化代码:Ctrl+Alt+L 2.重命名变量:光标停留在变量上,Shift+F6 3.打开文件或者项目所在目录: 右键>Show in Explorer 4.添加包围代码块的快捷键:Ct ...