diff --git a/redwood-lazylayout-uiview/src/commonMain/kotlin/app/cash/redwood/lazylayout/uiview/UIViewLazyList.kt b/redwood-lazylayout-uiview/src/commonMain/kotlin/app/cash/redwood/lazylayout/uiview/UIViewLazyList.kt index 9dae1be951..4a9c9feaf6 100644 --- a/redwood-lazylayout-uiview/src/commonMain/kotlin/app/cash/redwood/lazylayout/uiview/UIViewLazyList.kt +++ b/redwood-lazylayout-uiview/src/commonMain/kotlin/app/cash/redwood/lazylayout/uiview/UIViewLazyList.kt @@ -90,7 +90,7 @@ internal open class UIViewLazyList( ) } - override fun setContent(view: LazyListContainerCell, content: Widget) { + override fun setContent(view: LazyListContainerCell, content: Widget?) { view.content = content } } diff --git a/redwood-lazylayout-view/src/main/kotlin/app/cash/redwood/lazylayout/view/ViewLazyList.kt b/redwood-lazylayout-view/src/main/kotlin/app/cash/redwood/lazylayout/view/ViewLazyList.kt index e25bd1e85c..22a7fec161 100644 --- a/redwood-lazylayout-view/src/main/kotlin/app/cash/redwood/lazylayout/view/ViewLazyList.kt +++ b/redwood-lazylayout-view/src/main/kotlin/app/cash/redwood/lazylayout/view/ViewLazyList.kt @@ -38,7 +38,6 @@ import app.cash.redwood.lazylayout.api.ScrollItemIndex import app.cash.redwood.lazylayout.widget.LazyList import app.cash.redwood.lazylayout.widget.LazyListUpdateProcessor import app.cash.redwood.lazylayout.widget.LazyListUpdateProcessor.Binding -import app.cash.redwood.lazylayout.widget.LazyListUpdateProcessor.BoundView import app.cash.redwood.lazylayout.widget.RefreshableLazyList import app.cash.redwood.ui.Density import app.cash.redwood.ui.Margin @@ -80,6 +79,10 @@ internal open class ViewLazyList private constructor( override fun deleteRows(index: Int, count: Int) { adapter.notifyItemRangeRemoved(index, count) } + + override fun setContent(view: ViewHolder, content: Widget?) { + view.content = content + } } override val items: Widget.Children = processor.items @@ -231,10 +234,10 @@ internal open class ViewLazyList private constructor( inner class ViewHolder( private val container: FrameLayout, - ) : RecyclerView.ViewHolder(container), BoundView { + ) : RecyclerView.ViewHolder(container) { var binding: Binding? = null - override var content: Widget? = null + var content: Widget? = null set(value) { field = value container.removeAllViews() diff --git a/redwood-lazylayout-widget/src/commonMain/kotlin/app/cash/redwood/lazylayout/widget/LazyListUpdateProcessor.kt b/redwood-lazylayout-widget/src/commonMain/kotlin/app/cash/redwood/lazylayout/widget/LazyListUpdateProcessor.kt index a6349fc1d1..3b1c6fe98a 100644 --- a/redwood-lazylayout-widget/src/commonMain/kotlin/app/cash/redwood/lazylayout/widget/LazyListUpdateProcessor.kt +++ b/redwood-lazylayout-widget/src/commonMain/kotlin/app/cash/redwood/lazylayout/widget/LazyListUpdateProcessor.kt @@ -321,7 +321,7 @@ public abstract class LazyListUpdateProcessor { protected abstract fun deleteRows(index: Int, count: Int) - protected abstract fun setContent(view: V, content: Widget) + protected abstract fun setContent(view: V, content: Widget?) /** * Binds a UI-managed view to model-managed content. @@ -347,14 +347,14 @@ public abstract class LazyListUpdateProcessor { private set /** - * The currently-bound content. This should be `lateinit`, but it can't be because of the - * side-effect in set(). + * The content of this binding; either a loaded widget or a placeholder. This should be + * `lateinit`, but it can't be because of the side-effect in set(). */ internal var content: Widget? = null set(value) { field = value val view = this.view - if (view != null) processor.setContent(view, value!!) + if (view != null) processor.setContent(view, value) } public val isBound: Boolean @@ -364,14 +364,14 @@ public abstract class LazyListUpdateProcessor { require(this.view == null) { "already bound" } this.view = view - processor.setContent(view, content!!) + processor.setContent(view, content) } public fun unbind() { val view = this.view ?: return // Detach the view. - view.content = null + processor.setContent(view, null) this.view = null if (isPlaceholder) { diff --git a/redwood-lazylayout-widget/src/commonTest/kotlin/app/cash/redwood/lazylayout/widget/FakeProcessor.kt b/redwood-lazylayout-widget/src/commonTest/kotlin/app/cash/redwood/lazylayout/widget/FakeProcessor.kt index bf95b4aaf9..a61ebe9327 100644 --- a/redwood-lazylayout-widget/src/commonTest/kotlin/app/cash/redwood/lazylayout/widget/FakeProcessor.kt +++ b/redwood-lazylayout-widget/src/commonTest/kotlin/app/cash/redwood/lazylayout/widget/FakeProcessor.kt @@ -78,7 +78,7 @@ class FakeProcessor : LazyListUpdateProcessor( } } - override fun setContent(view: StringCell, content: Widget) { + override fun setContent(view: StringCell, content: Widget?) { view.content = content }