[英]How to animate height to 100% in react-native?
I have been trying to do:我一直在尝试做:
<Animated.View
style={[{
height: this.collapse.interpolate({
inputRange: [0, 1],
outputRange: ['0%', '100%'],
}),
}]}
>
{children}
</Animated.View>
But the one item from the list take the FlatList
total height.但是列表中的一项采用
FlatList
总高度。
I have tried to use minHeight
, but same problem.我曾尝试使用
minHeight
,但同样的问题。
How can I make my animated height on 100%?如何使我的动画高度达到 100%?
Snack : https://snack.expo.io/@kopax/petrified-cookies小吃: https ://snack.expo.io/@kopax/petrified-cookies
With a browser, the height is not of the height of the <FlatList />
, but on native, it looks like this:在浏览器中,高度不是
<FlatList />
的高度,但在本机上,它看起来像这样:
How can I use a dynamic height for this animation?如何为这个动画使用动态高度?
If your items are of different height then one solution would be to calculate this height using the onLayout function when the Swipeable items are rendered and then use this value for your animation.如果您的项目具有不同的高度,那么一种解决方案是在呈现可滑动项目时使用 onLayout 函数计算此高度,然后将此值用于您的动画。
class GmailStyleSwipeableRow extends Component {
static animationDeleteDuration = 200; // eslint-disable-line react/sort-comp
constructor(props) {
super(props);
this.collapse = new Animated.Value(1);
this.height = 75;
}
render () {
return (<Swipeable>
<Animated.View
onLayout={event => {
const { height } = event.nativeEvent.layout;
this.height = height;
}}
style={[
{
minHeight: 75, //give it a default minHeight
height: this.collapse.interpolate({
inputRange: [0, 1],
outputRange: [0, this.height], //base your animation on the calculated height
}),
},
]}
>
{children}
</Animated.View>
</Swipeable>)
}
}
But if your items are like your example then you can save all these calculations and just give the items the same height.但是,如果您的项目与您的示例类似,那么您可以保存所有这些计算并为项目提供相同的高度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.