Skip to content

Commit

Permalink
fix: 单独调用 notifyDataSetChanged() 方法对 stateView 生效的 bug #3822
Browse files Browse the repository at this point in the history
  • Loading branch information
limuyang2 committed Dec 7, 2023
1 parent 6e9e661 commit b3fc442
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ abstract class BaseQuickAdapter<T : Any, VH : RecyclerView.ViewHolder>(

final override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is StateLayoutVH) {
holder.changeStateView(stateView)
return
}

Expand Down Expand Up @@ -822,7 +823,7 @@ abstract class BaseQuickAdapter<T : Any, VH : RecyclerView.ViewHolder>(


companion object {
const val EMPTY_VIEW = 0x01000555
val EMPTY_VIEW = R.id.BaseQuickAdapter_empty_view

internal const val EMPTY_PAYLOAD = 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.chad.library.adapter4.fullspan.FullSpanAdapterType
* @property stateLayout
* @constructor Create empty Empty layout v h
*/
internal class StateLayoutVH constructor(
internal class StateLayoutVH(
parent: ViewGroup,
stateView: View?,
private val stateLayout: FrameLayout = FrameLayout(parent.context).apply {
Expand All @@ -37,6 +37,14 @@ internal class StateLayoutVH constructor(
return
}

if (rootView.childCount == 1) {
val old = rootView.getChildAt(0)
if (old == stateView) {
// 如果是同一个view,不进行操作
return
}
}

stateView.parent.run {
if (this is ViewGroup) {
this.removeView(stateView)
Expand Down
2 changes: 2 additions & 0 deletions library/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
<item name="BaseQuickAdapter_databinding_support" type="id"/>

<item name="BaseQuickAdapter_key_multi" type="id"/>

<item name="BaseQuickAdapter_empty_view" type="id"/>
</resources>

0 comments on commit b3fc442

Please sign in to comment.