Skip to content

Commit

Permalink
Fix UIView scroll offset max clamping (#2415)
Browse files Browse the repository at this point in the history
Take the view's bounds into effect when clamping the maximum offset value
  • Loading branch information
dellisd authored Oct 28, 2024
1 parent efe412e commit 3073629
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import app.cash.redwood.ui.Px
import app.cash.redwood.yoga.FlexDirection
import app.cash.redwood.yoga.Node
import app.cash.redwood.yoga.Size
import kotlin.math.max
import kotlinx.cinterop.CValue
import kotlinx.cinterop.cValue
import kotlinx.cinterop.useContents
Expand Down Expand Up @@ -140,12 +141,15 @@ internal class YogaUIView : UIScrollView(cValue { CGRectZero }), UIScrollViewDel
override fun scrollViewDidScroll(scrollView: UIScrollView) {
val onScroll = onScroll
if (onScroll != null) {
val size = scrollView.bounds.useContents {
if (isColumn()) size.height else size.width
}
val max = scrollView.contentSize.useContents {
if (isColumn()) height else width
}
val offset = scrollView.contentOffset.useContents {
if (isColumn()) y else x
}.coerceIn(minimumValue = 0.0, maximumValue = max)
}.coerceIn(minimumValue = 0.0, maximumValue = max(0.0, max - size))
onScroll(Px(offset))
}
}
Expand Down

0 comments on commit 3073629

Please sign in to comment.