尝试删除子计数错误以上的视图索引

Dam*_*ryx 13 react-native

这是什么意思?当我更新迭代视图列表时会发生这种情况

<View style={{ flexDirection: 'row', padding: 20, backgroundColor: '#fff' }}>
  <Ionicons name={jobIcon} color={theme.iconColor} size={30} />
  <Text>{jobService}</Text>
  <Text>{jobDate}</Text>
</View>
Run Code Online (Sandbox Code Playgroud)

映射在scrollview中.

当我从子场景修改数组时弹出此错误.scene1 - 是带有作业列表数组视图sence2的ScrollView - 我删除作业的地方,当我删除作业时应该更新scene1

在此输入图像描述

小智 16

如果您希望LayoutAnimationScrollView 一起使用,请替换

LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)

Run Code Online (Sandbox Code Playgroud)

        LayoutAnimation.configureNext({
                             duration: 300,
                             create: 
                             {
                                type: LayoutAnimation.Types.easeInEaseOut,
                                property: LayoutAnimation.Properties.opacity,
                             },
                             update: 
                             {
                                type: LayoutAnimation.Types.easeInEaseOut,
                             }
                            });
Run Code Online (Sandbox Code Playgroud)

这适用于 Android 和 iOS,没有任何崩溃。

  • 有什么解释可以解释为什么这可以解决问题吗? (4认同)

pin*_*eke 6

当您在布局动画已经在处理时调用布局动画时,就会发生这种情况。iOS 会显示警告,而 Android 会因此错误而爆炸。当您使用同一组件中的 LayoutAnimation 时,您可以使用这个简单的模式来修复它。

layoutAnimation()  {
  if (!this.layoutAnimationActive) {
    this.layoutAnimationActive = true;
    LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInOut, () => { this.layoutAnimationActive = false; });
  }
}
Run Code Online (Sandbox Code Playgroud)


Dam*_*ryx 5

就我而言,我在ScrollView中使用了LayoutAnimation。里面有一张物品地图。从列表中删除项目时,会发生这种情况。不使用LayoutAnimation似乎工作正常。