Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In UIViewLazyList's UITableView, adding special-case handling for programmatic scroll-to-top calls #1944

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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