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)的更多相关文章

  1. React Native App设置&Android版发布

    React Native系列 <逻辑性最强的React Native环境搭建与调试> <ReactNative开发工具有这一篇足矣> <解决React Native un ...

  2. React Native移植原生Android

    (一)前言 之前已经写过了有关React Native移植原生Android项目的文章,不过因为RN版本更新的原因吧,跟着以前的文章可能会出现一些问题,对于初学者来讲还是会有很多疑难的困惑的,而且官方 ...

  3. 将React Native集成至Android原生应用

    将React Native集成至Android原生应用 Android Studio 2.1 Preview 4生成的空项目 react-native 环境 0.22.2 初次编译后apk有1.1M, ...

  4. React Native hot reloading & Android & iOS

    React Native hot reloading & Android & iOS https://facebook.github.io/react-native/docs/debu ...

  5. React Native 4 for Android源码分析 一《JNI智能指针之介绍篇》

    文/ Tamic: http://blog.csdn.net/sk719887916/article/details/53455441 原文:http://blog.csdn.net/eewolf/a ...

  6. 关于React Native项目在android上UI性能调试实践

    我们尽最大的努力来争取使UI组件的性能如丝般顺滑,但有的时候这根本不可能做到.要知道,Android有超过一万种不同型号的手机,而在框架底层进行软件渲染的时候是统一处理的,这意味着你没办法像iOS那样 ...

  7. React Native工程修改Android包名

    默认初始化的React Native工程,生成Android工程的时候,包名默认是React Native工程的名字,跟一般Android工程com.company.xxx不一样. 这时候就需要手动修 ...

  8. React Native升级方法——升级到最新版本0.59

    React Native最近有大动作,于2019年3月12日发布新版本0.59.主要有两点值得升级:支持React Hooks:升级了JavaScriptCore,使Android性能有大幅提升.据用 ...

  9. 【React Native开发】React Native移植原生Android项目(4)

    ),React Native技术交流4群(458982758),请不要反复加群!欢迎各位大牛,React Native技术爱好者加入交流!同一时候博客左側欢迎微信扫描关注订阅号,移动技术干货,精彩文章 ...

随机推荐

  1. Oracle提取中文字符串拼音首字母函数

    通过oracle的NLSSORT函数对汉字按照拼音排序,然后根据汉字的区间返回对应的首字母. 效果1,获取拼音简码: 效果2,获取姓名首字母: 创建函数: /* 获取拼音简码函数 */ CREATE ...

  2. Cowboy http服务器 websocket

    一.基础介绍 cowboy是一个小巧.快速.模块化的http服务器,采用Erlang开发.其中良好的clean module使得我们可以扩展到多种网络协议之中,cowboy自带的有tcp和ssl,而也 ...

  3. Oracle角色,权限,表空间基础语句

    控制台: -sqlplus         -----连接数据库 -conn sys/123456@orcl as sysdba        -----登录sys -create tablespac ...

  4. C++中的字符串的输入输出函数、空字符与空格的区别、字符变量赋值和字符串初始化

      一.字符串输入输出函数 1.  cin.get()   逐个字符输入输出 2.  cin 可以将整个字符串一次性输入,但是,cin将空格.Tab和回车键,因此不能用于数组的一次性输入. 注意:ci ...

  5. mongo-2ds索引对超过半球范围的适用性测试

    以下测试均基于mongo v4.0 win10 一.GeoJSON GeoJSON是一种基于json的经纬度描述数据格式.在这里主要服务于2dsphere索引查询. 基本格式  <type:&q ...

  6. flask 登录验证码 字母和数字

    captcha.py #!/usr/bin/env python# -*- coding: utf-8 -*- # refer to `https://bitbucket.org/akorn/whee ...

  7. [Java] [Singleton] [DCL][happens-before]

    Singleton 只能有一个实例:必须自己创建自己的实例:必须给其他所有对象提供这一实例 实现方法 饿汉式singleton 预先加载法 class Single { private Single( ...

  8. shell版的nginx安装

    #!/bin/bash # Name:Centos 6.4 安装nginx1.8.1 # Date:-- # Author:qifei@meizu.com Home=$(cd ``;pwd) #这个命 ...

  9. 安装linux虚拟机配置静态ip(NAT模式)

    1.centOs7.VMware Workstation14 2.常规配置硬件和基本信息后,在图形安装界面将以太网链接打开,安装后配置ifcfg-e****,这里是我的配置文件 修改BOOTPROTO ...

  10. react中Redux应用框架学习

    1. 最普通的react-redux 2.应用context的傻瓜组件和聪明组件的redux框架  3. 精简版react-redux,利用react-redux模块的redux(推荐)  4.多个模 ...