当您不知道内容的大小时,如何在react native中设置高度的动画? [英] How do you animate the height in react native when you don't know the size of the content?
问题描述
在本机视图中,当您不知道视图内容的大小时,如何为视图的大小设置动画?
比如说View的内容高度可以在0-400pts之间,并且内容可以动态地增长和缩小,并且您想对高度的任何变化进行动画处理。
Let's say the View's content height can be anywhere from 0-400pts, and the content can grow and shrink dynamically, and you want to animate any changes to the height.
基本上,我希望不使用LayoutAnimation 而是使用Animated来重现LayoutAnimation 的行为。
Basically, I'm looking to reproduce the behaviour of LayoutAnimation without using LayoutAnimation but using Animated.
我想让我感到困惑的是,我不知道如何朝目标高度移动,因为我不知道内容的高度。
I think what eludes me is I don't know how to animate towards a target height since I don't know the height of the content.
推荐答案
为此,在状态更改之前,我使用 LayoutAnimation
导致组件的高度发生变化,请添加:
I use LayoutAnimation
for that, just before the state change that causes your component's height to change, add:
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
您可以使用不同的预设:
You can use different presets:
- spring
- easeInEaseOut
-
线性
- spring
- easeInEaseOut
linear
您可以阅读此处的更多信息 https://facebook.github.io/react-native/docs /layoutanimation.html
You can read more about it here https://facebook.github.io/react-native/docs/layoutanimation.html
这篇关于当您不知道内容的大小时,如何在react native中设置高度的动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!