angcyo / DslTabLayout

:hearts: Android界最万能的TabLayout(不仅仅是TabLayout), 支持任意类型的item, 支持Drawable类型的指示器,智能开启滚动,支持横竖向布局等
https://github.com/angcyo/DslAdapter
MIT License
1.55k stars 145 forks source link

observeIndexChange 重复点击时不触发 #75

Closed aheven closed 2 years ago

aheven commented 2 years ago

查看源码后发现很难有条件满足needNotify这个参数,导致重复的时候reselect一直不会触发。

/**
     * 操作单个
     * @param index 操作目标的索引值
     * @param select 选中 or 取消选中
     * @param notify 是否需要通知事件
     * @param forceNotify 是否强制通知事件.child使用[CompoundButton]时, 推荐使用
     * */
    fun selector(
        index: Int,
        select: Boolean = true,
        notify: Boolean = true,
        fromUser: Boolean = false,
        forceNotify: Boolean = false
    ) {
        val oldSelectorList = selectorIndexList.toList()
        val lastSelectorIndex: Int? = oldSelectorList.lastOrNull()
        val reselect = !dslSelectorConfig.dslMultiMode &&
                oldSelectorList.isNotEmpty() &&
                oldSelectorList.contains(index)

        var _needNotify_ = _selector(index, select, fromUser) || forceNotify

        if (!oldSelectorList.isChange(selectorIndexList)) {
            //选中项, 未改变时不通知
            needNotify = false
        }

        if (needNotify) {
            dslSelectIndex = selectorIndexList.lastOrNull() ?: -1
            if (notify) {
                notifySelectChange(lastSelectorIndex ?: -1, reselect, fromUser)
            }
        }
    }
angcyo commented 2 years ago

3.2.5已修复.

 fun selector(
     index: Int,
     select: Boolean = true,
     notify: Boolean = true,
     fromUser: Boolean = false,
     forceNotify: Boolean = false
 ) {
     ...
     if (needNotify || reselect) {
         ...
     }
 }