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技术爱好者加入交流!同一时候博客左側欢迎微信扫描关注订阅号,移动技术干货,精彩文章 ...
随机推荐
- js查漏补缺
js中: 1.对空(Null).未定义(Undefined).Symbol .函数(Function) 都是数据类型(js不像java中,声明了变量会有默认值,在js中只声明变量而没有赋值的时候,类型 ...
- 使用Python统计函数绘制复杂图形matplotlib
一.堆积图 1.堆积柱状图 如果将函数bar()中的参数bottom的取值设定为列表y.列表y1代表另一个数,函数bar(x,y1,bottom=y,color="r")就会输出堆 ...
- php实现遍历目录
用递归方法实现目录的遍历: <?php header("Content-type: text/html; charset=utf-8"); date_default_time ...
- 远程连接SqlServer 数据库时提示 "在与SQL Server 建立连接时出现与网络相关的或特定实例的错误" 解决方法
前言 由于在之前的职业生涯中, 无论是数据库还是开发环境, 都是前人弄好的,自己只管使用就好啦.并不知安装过程中会出现各种各样的错.最近接触服务器之后,开发环境以及配置各方面都是从头到脚开始安装到配置 ...
- C语言:开平方根sqrt程序02
#include <stdio.h> int sqrt01(int x); void main(void){ int x=49,y; y=sqrt01(x); if(y<0) pri ...
- lunx中部分命令总结
一.文件和目录操作命令ls 全拼list,功能是列出目录的内容及其内容属性信息. cd 全拼change directory,功能是从当前工作目录切换到指定的工作目录. cp 全拼copy,其功 ...
- DD常用命令组合
管理一个系统经常需要备份磁盘数据,那么在UNIX/Linux系统中如何备份整个分区或整个硬盘的数据呢? dd命令就可以很方便实现这个功能. 1.把一个分区复制到一个文件中 dd if=/dev/sda ...
- Js的运算符
JS的运算符 1.运算符的分类: a) 算数运算符 b) 字符串运算符 c) 赋值运算符 d) 比较运算符 e) 逻辑运算符 f) 位运算符 g) 其他运算符 2.算数运算符 + 加法运算符 - 减法 ...
- 只有自身跟上时代,offer就会如期而至
[官宣]只有自身跟上时代,offer就会如期而至 最近对求职者来说,似乎颇不太平,各种裁员扑面而来,许多企业(易车.滴滴等)相继官宣裁员信息,包括阿里缩减校招,百度减少社招等,都让人不禁打嗦.但我们华 ...
- 前端学习roadmap