简体   繁体   English

显示键盘时出现 React-native/Splash-Screen

[英]React-native / Splash-Screen appear when showing keyboard

I added a splash-screen to my react native project, everything works fine exept when i open the keyboard it show briefly the splash-screen behind it.我在我的本机项目中添加了一个闪屏,当我打开键盘时,一切正常,但它会简要显示其背后的闪屏。 Video : https://drive.google.com/open?id=14ahrc-dyYnNEYAAX3iMQVwqqV6fVo_xG视频: https : //drive.google.com/open?id=14ahrc-dyYnNEYAAX3iMQVwqqV6fVo_xG

To Reproduce再现

create background_splash.xml in drawable with this code in it :在 drawable 中创建 background_splash.xml ,其中包含以下代码:

 <?xml version="1.0" encoding="utf-8" ?>

<layer-list 
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/primary"/>
</layer-list>

Then add it in the styles.xml file然后在styles.xml文件中添加

<item name="android:windowBackground">
     @drawable/background_splash
</item>

Expected Behavior预期行为

The splash-screen should not display when the keyboard appears.出现键盘时不应显示启动画面。

Code Example代码示例

Everything is in the To Reproduce tab, you just need to add a TextInput for it to appear.一切都在 To Reproduce 选项卡中,您只需要添加一个 TextInput 即可显示。

Environment环境

React Native Environment Info: System: OS: Windows 10 CPU: (4) x64 Intel(R) Xeon(R) CPU E5-1603 v4 @ 2.80GHz Memory: 9.57 GB / 15.92 GB Binaries: npm: 6.4.1 - C:\\Program Files\\nodejs\\npm.CMD React Native 环境信息:系统:操作系统:Windows 10 CPU:(4) x64 Intel(R) Xeon(R) CPU E5-1603 v4 @ 2.80GHz 内存:9.57 GB / 15.92 GB 二进制文件:npm:6.4.1 - C: \\Program Files\\nodejs\\npm.CMD

I had the same problem with my app, here is my workaround.我的应用程序遇到了同样的问题,这是我的解决方法。 First you have to install the module react-native-background-color which allows you to set the background color of your root Activity.首先,您必须安装react-native-background-color模块,它允许您设置根 Activity 的背景颜色。

After call the setColor method in your App.jsx (with a short timeout to avoid a "flash" immediately after splash screen) example with hooks :在你的 App.jsx 中调用setColor方法后(有一个短暂的超时以避免在启动画面后立即“闪烁”)带有钩子的示例:

export default function App(): Element {
    useEffect(() => {
        if (Platform.OS === "android") {
            setTimeout(() => {
                BackgroundColor.setColor("#FFFFFF");
            }, 500);
        }
    }, []);
    return <AppContainer />;
}

Hope this help !希望这有帮助!

Edit: improve the code with a Platform.OS test.编辑:使用Platform.OS测试改进代码。

These libraries ( react-native-root-view-background & react-native-background-color ) did not work for me probably due to being outdated, but this one worked for me flawlessly tested with "react-native": "~0.63.4" :这些库( react-native-root-view-backgroundreact-native-background-color )对我不起作用可能是因为已经过时了,但是这个库对我有用,用"react-native": "~0.63.4"完美测试"react-native": "~0.63.4"

https://www.npmjs.com/package/react-native-root-view-background-color https://www.npmjs.com/package/react-native-root-view-background-color

import RootViewBackgroundColor from 'react-native-root-view-background-color';
 
 
// Set the Root View background color to black
RootViewBackgroundColor.setBackground(0, 0, 0, 1);
 
// Set the Root View background color to white
RootViewBackgroundColor.setBackground(255, 255, 255, 1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM