CymChad / BaseRecyclerViewAdapterHelper

BRVAH:Powerful and flexible RecyclerAdapter
http://www.recyclerview.org/
MIT License
24.3k stars 5.15k forks source link

BaseNodeAdapter 崩溃问题 #3770

Closed tdxtxt closed 1 year ago

tdxtxt commented 1 year ago
 /**
     * 从数组中移除
     * @param position Int
     * @return Int 被移除的数量
     */
    private fun removeNodesAt(position: Int): Int {
        if (position >= data.size) {
            return 0
        }
        // 记录被移除的item数量
        var removeCount = 0

        // 先移除子项
        removeCount = removeChildAt(position)

        // 移除node自己
        this.data.removeAt(position)
        removeCount += 1

        val node = this.data[position]
        // 移除脚部
        if (node is NodeFooterImp && node.footerNode != null) {
            this.data.removeAt(position)
            removeCount += 1
        }
        return removeCount
    }

这个方法会存在数组越界,建议作者尽快修复,修复如下

 /**
     * 从数组中移除
     * @param position Int
     * @return Int 被移除的数量
     */
    private fun removeNodesAtFix(position: Int): Int {
        if (position >= data.size) {
            return 0
        }
        // 记录被移除的item数量,先移除子项
        var removeCount = removeChildAt(position)
        val node = this.data[position]

        // 是否存在移除的脚部
        val isRemoveFooter = node is NodeFooterImp && node.footerNode != null

        // 移除node自己
        this.data.removeAt(position)
        removeCount += 1

        // 移除脚部
        if (isRemoveFooter) {
            this.data.removeAt(position)
            removeCount += 1
        }
        return removeCount
    }
limuyang2 commented 1 year ago

3.x 版本么?

tdxtxt commented 1 year ago

是的

limuyang2 commented 1 year ago

具体哪一行崩溃

limuyang2 commented 1 year ago

更新依赖试试

implementation "io.github.cymchad:BaseRecyclerViewAdapterHelper:3.0.14"