Skip to content

Commit

Permalink
Don't extend both Objective-C and Kotlin types
Browse files Browse the repository at this point in the history
  • Loading branch information
squarejesse committed Oct 6, 2023
1 parent f31da99 commit 5168b2d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ internal open class UIViewLazyList(
UITableViewRowAnimationNone,
)
}

override fun setContent(view: LazyListContainerCell, content: Widget<UIView>) {
view.content = content
}
}

override val placeholder: Widget.Children<UIView> = processor.placeholder
Expand All @@ -109,7 +113,7 @@ internal open class UIViewLazyList(
cellForRowAtIndexPath: NSIndexPath,
): LazyListContainerCell {
val index = cellForRowAtIndexPath.item.toInt()
return processor.getOrCreateBoundView(index) { binding ->
return processor.getOrCreateView(index) { binding ->
createView(tableView, binding, index)
}
}
Expand Down Expand Up @@ -214,9 +218,9 @@ private const val reuseIdentifier = "LazyListContainerCell"
internal class LazyListContainerCell(
style: UITableViewCellStyle,
reuseIdentifier: String?,
) : UITableViewCell(style, reuseIdentifier), LazyListUpdateProcessor.BoundView<UIView> {
) : UITableViewCell(style, reuseIdentifier) {
internal var binding: Binding<LazyListContainerCell, UIView>? = null
override var content: Widget<UIView>? = null
internal var content: Widget<UIView>? = null
set(value) {
field = value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package app.cash.redwood.lazylayout.widget

import app.cash.redwood.lazylayout.widget.LazyListUpdateProcessor.BoundView
import app.cash.redwood.widget.Widget

/**
Expand All @@ -36,7 +35,7 @@ import app.cash.redwood.widget.Widget
*
* This class keeps track of the two windows, and of firing precise updates as the window changes.
*/
public abstract class LazyListUpdateProcessor<V : BoundView<W>, W : Any> {
public abstract class LazyListUpdateProcessor<V : Any, W : Any> {

/** Pool of placeholder widgets. */
private val placeholdersQueue = ArrayDeque<Widget<W>>()
Expand Down Expand Up @@ -270,7 +269,7 @@ public abstract class LazyListUpdateProcessor<V : BoundView<W>, W : Any> {
return loaded
}

public fun getOrCreateBoundView(
public fun getOrCreateView(
index: Int,
createView: (binding: Binding<V, W>) -> V,
): V {
Expand Down Expand Up @@ -319,9 +318,7 @@ public abstract class LazyListUpdateProcessor<V : BoundView<W>, W : Any> {

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

public interface BoundView<W : Any> {
public var content: Widget<W>?
}
protected abstract fun setContent(view: V, content: Widget<W>)

/**
* Binds a UI-managed view to model-managed content.
Expand All @@ -338,7 +335,7 @@ public abstract class LazyListUpdateProcessor<V : BoundView<W>, W : Any> {
* (due to view recycling), or because it is discarded (due to the view discarding it). This class
* assumes that a view that is discarded will never be bound again.
*/
public class Binding<V : BoundView<W>, W : Any> internal constructor(
public class Binding<V : Any, W : Any> internal constructor(
internal val processor: LazyListUpdateProcessor<V, W>,
internal var isPlaceholder: Boolean = false,
) {
Expand All @@ -348,7 +345,8 @@ public abstract class LazyListUpdateProcessor<V : BoundView<W>, W : Any> {
internal var content: Widget<W>? = null
set(value) {
field = value
view?.content = value
val view = this.view
if (view != null) processor.setContent(view, value!!)
}

public val isBound: Boolean
Expand All @@ -358,7 +356,7 @@ public abstract class LazyListUpdateProcessor<V : BoundView<W>, W : Any> {
require(this.view == null) { "already bound" }

this.view = view
view.content = content!!
processor.setContent(view, content!!)
}

public fun unbind() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FakeProcessor : LazyListUpdateProcessor<FakeProcessor.StringCell, String>(
private val scrollWindowCells = mutableListOf<StringCell>()

private fun getView(index: Int): StringCell {
return getOrCreateBoundView(index) { binding ->
return getOrCreateView(index) { binding ->
StringCell(binding)
}
}
Expand Down Expand Up @@ -78,6 +78,10 @@ class FakeProcessor : LazyListUpdateProcessor<FakeProcessor.StringCell, String>(
}
}

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

fun scrollTo(offset: Int, count: Int) {
val oldWindowCells = ArrayDeque(scrollWindowCells)
var oldWindowCellsOffset = scrollWindowOffset
Expand Down Expand Up @@ -127,7 +131,7 @@ class FakeProcessor : LazyListUpdateProcessor<FakeProcessor.StringCell, String>(

class StringCell(
val binding: Binding<StringCell, String>,
) : BoundView<String> {
override var content: Widget<String>? = null
) {
var content: Widget<String>? = null
}
}

0 comments on commit 5168b2d

Please sign in to comment.