Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用分组功能出现崩溃 #79

Closed
6YK5 opened this issue Dec 15, 2021 · 10 comments
Closed

使用分组功能出现崩溃 #79

6YK5 opened this issue Dec 15, 2021 · 10 comments

Comments

@6YK5
Copy link

6YK5 commented Dec 15, 2021

当使用分组时,某一分组的Item超出一屏后点击分组标题收缩分组时会导致崩溃。

错误信息:
image

@TxcA
Copy link
Collaborator

TxcA commented Dec 15, 2021

  1. 标注BRV版本
  2. sample 是否存在该问题
  3. 如果sample 正常,请提供相应可复现代码

@liangjingkanji
Copy link
Owner

我在sample无法复现

@6YK5 6YK5 closed this as completed Dec 15, 2021
@6YK5 6YK5 reopened this Dec 15, 2021
@6YK5
Copy link
Author

6YK5 commented Dec 15, 2021

我下午改一下sample代码 看看能复现错误不能

@6YK5
Copy link
Author

6YK5 commented Dec 15, 2021

已解决,原因是分组里面的item对应的实体类未继承ItemExpand(看文档以为只有外部的组实体类需要继承ItemExpand),导致点击收缩时移除元素时把其他分组属性相同的item也一并移除了,导致下标计算错误。

@6YK5 6YK5 closed this as completed Dec 15, 2021
@liangjingkanji
Copy link
Owner

collapse折叠的核心代码

(this@BindingAdapter.models as MutableList).removeAll(sublistFlat)

理论上不要求子列表一定实现ItemExpand. 存在子列表的item才要求实现ItemExpand
你debug查看下具体什么地方下标错误. 或者fork仓库复现发我

@6YK5
Copy link
Author

6YK5 commented Dec 15, 2021

我的使用场景是一个通讯录,顶部是一个常用联系人分组,与下方的地区分组中存在相同的联系人。
现在的问题变成了,如果我折叠常用联系人分组,那么下方包含相同联系人的分组也会移除那个存在于常用联系人分组的联系人。

@6YK5
Copy link
Author

6YK5 commented Dec 16, 2021

东哥,使用sample代码可以复现.
将GroupBasicModel改为DataClass
GroupModel中的itemExpand默认值改为true,finalList给定一个随机长度的list
然后点击分组进行折叠,就能复现我上面说的问题了

@liangjingkanji
Copy link
Owner

liangjingkanji commented Dec 16, 2021

这属于Java自带函数removeAll问题

val element = Element()
val list = mutableListOf(element, Element())
println("size = ${list.size}") // output 2
list.removeAll(listOf(element))
println("size = ${list.size}") // output 0

数据类data class 会重写equals导致字段属性相等的类被判断为同一个, 然后被集合删除

data class Data(var name: String = "data")

解决方法两个

  • 不要使用data class
  • 重写equals
    data class Element(var name: String = "data") {
      override fun equals(other: Any?): Boolean {
          return this === other // 使用内存地址判断
      }
    }

@liangjingkanji
Copy link
Owner

这个问题等我确定下是BRV内部修改还是文档提示

@6YK5
Copy link
Author

6YK5 commented Dec 16, 2021

是的,我也想明白了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants