Skip to content

Commit

Permalink
In UIViewLazyList's UITableView, adding special-case handling for pro…
Browse files Browse the repository at this point in the history
…grammatic scroll-to-top calls (#1944)
  • Loading branch information
dnagler authored Apr 10, 2024
1 parent c15b9ed commit 4a4bdb0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ New:
- Nothing yet!

Changed:
- Nothing yet!
- In `UIViewLazyList`'s `UITableView`, adding special-case handling for programmatic scroll-to-top calls.

Fixed:
- Work around a problem with our memory-leak fix where our old LazyList code would crash when its placeholders were unexpectedly removed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import kotlinx.cinterop.CValue
import kotlinx.cinterop.ObjCClass
import kotlinx.cinterop.convert
import kotlinx.cinterop.readValue
import kotlinx.cinterop.useContents
import platform.CoreGraphics.CGPoint
import platform.CoreGraphics.CGRect
import platform.CoreGraphics.CGRectZero
import platform.CoreGraphics.CGSize
Expand All @@ -56,17 +58,29 @@ import platform.UIKit.UITableViewDataSourceProtocol
import platform.UIKit.UITableViewDelegateProtocol
import platform.UIKit.UITableViewRowAnimationNone
import platform.UIKit.UITableViewScrollPosition
import platform.UIKit.UITableViewStyle
import platform.UIKit.UIView
import platform.UIKit.indexPathForItem
import platform.UIKit.item
import platform.darwin.NSInteger
import platform.darwin.NSObject

internal open class UIViewLazyList(
internal val tableView: UITableView = UITableView(
internal open class UIViewLazyList() : LazyList<UIView>, ChangeListener {
internal val tableView: UITableView = object : UITableView(
CGRectZero.readValue(),
),
) : LazyList<UIView>, ChangeListener {
UITableViewStyle.UITableViewStylePlain,
) {
override fun setContentOffset(contentOffset: CValue<CGPoint>, animated: Boolean) {
// If the caller is requesting a contentOffset with y == 0,
// and the current contentOffset.y is not 0,
// assume that it's a programmatic scroll-to-top call.
if (contentOffset.useContents { y } == 0.0 && this.contentOffset.useContents { y } != 0.0) {
isDoingProgrammaticScroll = true
}
super.setContentOffset(contentOffset, animated)
}
}

override var modifier: Modifier = Modifier

override val value: UIView
Expand Down Expand Up @@ -185,6 +199,10 @@ internal open class UIViewLazyList(
override fun scrollViewDidEndScrollingAnimation(scrollView: UIScrollView) {
isDoingProgrammaticScroll = false
}

override fun scrollViewDidScrollToTop(scrollView: UIScrollView) {
isDoingProgrammaticScroll = false
}
}

init {
Expand Down

0 comments on commit 4a4bdb0

Please sign in to comment.