如何折叠按下数组上的项目-反应本机?

我有一张卡片清单, 当按下其中任何一个时,我想提高该卡的高度, 因此,我使用layoutAnimation处理这种情况,因为当我从RN使用Animated API时,当setNativeDrive“ height”出现错误 无论如何, 就我而言,它会增加列表中每张卡的高度,

那我该如何解决呢?

代码段

Live Demo

sizeof
iCMS 回答:如何折叠按下数组上的项目-反应本机?

更改此:

<Animated.View
  style={[
    styles.itemContainer,{
      height: cardHeight,},]
>
{...}
</Animated.View>

作者

<Animated.View
  style={[
    styles.itemContainer,{
      height: currentIndex === index ? cardHeight : 140,]
>
{...}
</Animated.View>

如果要提高效率,请设置卡片的默认高度,将其定义为常数(例如:const = DEFAULT_CARD_HEIGHT = 140),并在将140用作卡片高度的任何地方使用此常数

本文链接:https://www.f2er.com/1737729.html

大家都在问