From 5168b2d440ff7ea801a43dc90ac5fcf4d9cf3d5c Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Fri, 6 Oct 2023 14:26:24 -0400 Subject: [PATCH] Don't extend both Objective-C and Kotlin types --- .../redwood/lazylayout/uiview/UIViewLazyList.kt | 10 +++++++--- .../lazylayout/widget/LazyListUpdateProcessor.kt | 16 +++++++--------- .../redwood/lazylayout/widget/FakeProcessor.kt | 10 +++++++--- 3 files changed, 21 insertions(+), 15 deletions(-) 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 2a3cd0671f..5cc3e063a6 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 @@ -89,6 +89,10 @@ internal open class UIViewLazyList( UITableViewRowAnimationNone, ) } + + override fun setContent(view: LazyListContainerCell, content: Widget) { + view.content = content + } } override val placeholder: Widget.Children = processor.placeholder @@ -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) } } @@ -214,9 +218,9 @@ private const val reuseIdentifier = "LazyListContainerCell" internal class LazyListContainerCell( style: UITableViewCellStyle, reuseIdentifier: String?, -) : UITableViewCell(style, reuseIdentifier), LazyListUpdateProcessor.BoundView { +) : UITableViewCell(style, reuseIdentifier) { internal var binding: Binding? = null - override var content: Widget? = null + internal var content: Widget? = null set(value) { field = value 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 9305b9ff02..077817c768 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 @@ -15,7 +15,6 @@ */ package app.cash.redwood.lazylayout.widget -import app.cash.redwood.lazylayout.widget.LazyListUpdateProcessor.BoundView import app.cash.redwood.widget.Widget /** @@ -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, W : Any> { +public abstract class LazyListUpdateProcessor { /** Pool of placeholder widgets. */ private val placeholdersQueue = ArrayDeque>() @@ -270,7 +269,7 @@ public abstract class LazyListUpdateProcessor, W : Any> { return loaded } - public fun getOrCreateBoundView( + public fun getOrCreateView( index: Int, createView: (binding: Binding) -> V, ): V { @@ -319,9 +318,7 @@ public abstract class LazyListUpdateProcessor, W : Any> { protected abstract fun deleteRows(index: Int, count: Int) - public interface BoundView { - public var content: Widget? - } + protected abstract fun setContent(view: V, content: Widget) /** * Binds a UI-managed view to model-managed content. @@ -338,7 +335,7 @@ public abstract class LazyListUpdateProcessor, 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, W : Any> internal constructor( + public class Binding internal constructor( internal val processor: LazyListUpdateProcessor, internal var isPlaceholder: Boolean = false, ) { @@ -348,7 +345,8 @@ public abstract class LazyListUpdateProcessor, W : Any> { internal var content: Widget? = null set(value) { field = value - view?.content = value + val view = this.view + if (view != null) processor.setContent(view, value!!) } public val isBound: Boolean @@ -358,7 +356,7 @@ public abstract class LazyListUpdateProcessor, W : Any> { require(this.view == null) { "already bound" } this.view = view - view.content = content!! + processor.setContent(view, content!!) } public fun unbind() { 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 eb8655f340..bf95b4aaf9 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 @@ -27,7 +27,7 @@ class FakeProcessor : LazyListUpdateProcessor( private val scrollWindowCells = mutableListOf() private fun getView(index: Int): StringCell { - return getOrCreateBoundView(index) { binding -> + return getOrCreateView(index) { binding -> StringCell(binding) } } @@ -78,6 +78,10 @@ class FakeProcessor : LazyListUpdateProcessor( } } + override fun setContent(view: StringCell, content: Widget) { + view.content = content + } + fun scrollTo(offset: Int, count: Int) { val oldWindowCells = ArrayDeque(scrollWindowCells) var oldWindowCellsOffset = scrollWindowOffset @@ -127,7 +131,7 @@ class FakeProcessor : LazyListUpdateProcessor( class StringCell( val binding: Binding, - ) : BoundView { - override var content: Widget? = null + ) { + var content: Widget? = null } }