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

Fix ScrollToBottom and ScrollToTop #4493

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

lorypelli
Copy link

Description:

I managed to fix scroll to bottom issue, I tested and it works...

Fixes #2917

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

Where applicable:

  • Public APIs match existing style and have Since: line.
  • Any breaking changes have a deprecation path or have been discussed.
  • Check for binary size increases when importing new modules.

@andydotxyz
Copy link
Member

I have realised that the tests are basically no-ops as the X/Y and assertions were confused.

Try the following test cases (maybe commit them in this PR if you agree with them):

func TestScrollContainer_ScrollToTop(t *testing.T) {
	rect := canvas.NewRectangle(color.Black)
	rect.SetMinSize(fyne.NewSize(100, 500))
	scroll := NewScroll(rect)
	scroll.Resize(fyne.NewSize(100, 50))

	scroll.scrollBy(0, -100)
	assert.Equal(t, float32(100), scroll.Offset.Y)

	scroll.ScrollToTop()
	assert.Equal(t, float32(0), scroll.Offset.Y)
}

func TestScrollContainer_ScrollToBottom(t *testing.T) {
	rect := canvas.NewRectangle(color.Black)
	rect.SetMinSize(fyne.NewSize(100, 500))
	scroll := NewScroll(rect)
	scroll.Resize(fyne.NewSize(100, 50))
	scroll.ScrollToBottom()
	assert.Equal(t, float32(450), scroll.Offset.Y)
}

Copy link
Member

@andydotxyz andydotxyz left a comment

Choose a reason for hiding this comment

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

Great work but the ScrollToBottom does not seem correct - it's got two codepaths and can be simplified as noted inline.

}

// ScrollToTop will scroll content to container top
func (s *Scroll) ScrollToTop() {
s.scrollBy(0, -s.Offset.Y)
s.scrollBy(0, s.Offset.Y)
Copy link
Member

Choose a reason for hiding this comment

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

Good catch!

@@ -393,13 +393,16 @@ func (s *Scroll) CreateRenderer() fyne.WidgetRenderer {

// ScrollToBottom will scroll content to container bottom - to show latest info which end user just added
func (s *Scroll) ScrollToBottom() {
if s.Content.MinSize().Height > s.Size().Height {
s.Offset.Y = s.Content.MinSize().Height - s.Size().Height
s.Base.Refresh()
Copy link
Member

Choose a reason for hiding this comment

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

This fix doesn't seem right - making a change then refreshing but then also making another change.

Really it should call scrollBy so the fix should be revising the parameters to that method.
And that Refresh looks like it's not needed any more.

Copy link
Member

Choose a reason for hiding this comment

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

You should also save the result of MinSize() and Size() instead of computing it multiple times in succession.

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.

None yet

3 participants