React Native LayoutAnimation 错误与反应导航? [英] React Native LayoutAnimation bug with react navigation?

查看:31
本文介绍了React Native LayoutAnimation 错误与反应导航?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的应用程序中处理键盘...我已经读到在 android 上对其进行动画处理的最佳方法是使用 LayoutAnimation API,是的,它工作正常,但是当我导航回键盘没有的其他屏幕时不会出现与我的键盘高度相同的未知视图.

有没有人尝试过这个问题?在 iOS 上它可以完美运行,但在 Android 上却不能.

我尝试过 UIManager.setLayoutAnimationEnabledExperimental(false);当我的组件卸载并且返回时没有出现此视图时,但如果我再次打开键盘,动画就会消失.

解决方案

我在 Android 上使用 LayoutAnimation.configureNextReact Navigation 5 时遇到了类似的问题.我从未找到问题的根本原因,但为我解决的是启用 react-native-screens

运行:

# 裸 React Native 项目npm install react-native-screens# 如果你使用 Expo 管理的工作流程expo 安装 react-native-screens

然后在渲染任何屏幕之前将以下代码放在根文件的顶部:

import { enableScreens } from react-native-screens";启用屏幕();

<块引用>

注意:我使用的是 Expo SDK 38,所以我不确定这个 fix 是否适用于非 Expo 环境.这是世博会文档

的链接

I am handling the keyboard in my app... I have read that the best way to animate it on android is using the LayoutAnimation API, and yeah it works fine but when I navigate back to other screens in which keyboard doesn't appear an unknown View with the same height of my keyboard is shown.

Has anyone experimented with this problem? On iOS it works perfectly, but not on Android.

I have tried to do UIManager.setLayoutAnimationEnabledExperimental(false); when my component unmounts and this View doesn't appear when going back, but if I open the keyboard again the animation disappears.

解决方案

I had a similar issue when using LayoutAnimation.configureNext and React Navigation 5 on Android. I never found the root cause of the problem, but what solved it for me was enabling react-native-screens

Run:

# bare React Native project
npm install react-native-screens

# if you use Expo managed workflow
expo install react-native-screens

Then place the following code at the top of your root file before rendering any screens:

import { enableScreens } from "react-native-screens";

enableScreens();

Note: I am using Expo SDK 38, so I'm not sure if this fix is applicable in non-Expo environments. Here is a link to the Expo docs

这篇关于React Native LayoutAnimation 错误与反应导航?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆