Skip to content

ScrollComponent: Fix scrollbar position set to NaN when scroll range is empty - #188

Merged
Johni0702 merged 1 commit into
masterfrom
fix/scrollcomponent-scrollbar-nan
Aug 20, 2026
Merged

Johni0702 merged 1 commit into
masterfrom
fix/scrollcomponent-scrollbar-nan

Conversation

@Johni0702

Copy link
Copy Markdown
Contributor

No description provided.

@Traben-0 Traben-0 left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, though comment should probably be considered

// Run our scroll adjust event, normally updating [scrollBarGrip]
var percent = (innerPadding - horizontalOffset) / horizontalRange.width()
var percent = if (horizontalRange.width() == 0f) 0f else (innerPadding - horizontalOffset) / horizontalRange.width()
var percentageOfParent = width / actualWidth

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question / issue: actualWidth & actualHeight also seems like it can be 0, so theoretically percentageOfParent can also NaN?

I havent looked too deeply, and cant see any usages to tell if it'll cause a problem

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, yeah, I believe it's used for the scrollbar size, so could be problematic too.

Re-visiting the scenario in which I ran into my issue, I realize that the problem actually wasn't that the scroller was empty, but merely that its size was matching the size of its content, so verticalRange was empty, while actualHeight was not.

Setting up a synthetic scenario with an empty scroller does confirm that actualHeight can also become 0. percentageOfParent thereby becomes Infinity though, not NaN. And I guess that kind of makes sense - or at least I wouldn't know how to reasonably fix it without a significant change to behavior - if you consider what happens as the content becomes smaller and smaller compared to the scroller: The percentageOfParent already grows and grows far beyond 1; it reaching Infinity as the content size reaches 0 is kind of what one should expect based on that behavior.

Looking at the scrollbar, that code seems to already clamp the percentageOfParent to 1 (ScrollComponent.kt:455), so I think percentageOfParent is actually fine to keep as is.

@Johni0702 Johni0702 changed the title ScrollComponent: Fix scrollbar position set to NaN when empty ScrollComponent: Fix scrollbar position set to NaN when scroll range is empty Aug 18, 2026
@Johni0702
Johni0702 merged commit 0139252 into master Aug 20, 2026
1 check passed
@Johni0702
Johni0702 deleted the fix/scrollcomponent-scrollbar-nan branch August 20, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants