Skip to content

Commit

Permalink
Track setContent() API change
Browse files Browse the repository at this point in the history
  • Loading branch information
squarejesse committed Oct 6, 2023
1 parent 72f43c8 commit f08c6e0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal open class UIViewLazyList(
)
}

override fun setContent(view: LazyListContainerCell, content: Widget<UIView>) {
override fun setContent(view: LazyListContainerCell, content: Widget<UIView>?) {
view.content = content
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>?) {
view.content = content
}
}

override val items: Widget.Children<View> = processor.items
Expand Down Expand Up @@ -231,10 +234,10 @@ internal open class ViewLazyList private constructor(

inner class ViewHolder(
private val container: FrameLayout,
) : RecyclerView.ViewHolder(container), BoundView<View> {
) : RecyclerView.ViewHolder(container) {
var binding: Binding<ViewHolder, View>? = null

override var content: Widget<View>? = null
var content: Widget<View>? = null
set(value) {
field = value
container.removeAllViews()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public abstract class LazyListUpdateProcessor<V : Any, W : Any> {

protected abstract fun deleteRows(index: Int, count: Int)

protected abstract fun setContent(view: V, content: Widget<W>)
protected abstract fun setContent(view: V, content: Widget<W>?)

/**
* Binds a UI-managed view to model-managed content.
Expand All @@ -347,14 +347,14 @@ public abstract class LazyListUpdateProcessor<V : Any, W : Any> {
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<W>? = 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
Expand All @@ -364,14 +364,14 @@ public abstract class LazyListUpdateProcessor<V : Any, W : Any> {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class FakeProcessor : LazyListUpdateProcessor<FakeProcessor.StringCell, String>(
}
}

override fun setContent(view: StringCell, content: Widget<String>) {
override fun setContent(view: StringCell, content: Widget<String>?) {
view.content = content
}

Expand Down

0 comments on commit f08c6e0

Please sign in to comment.