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
Open
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
7 changes: 5 additions & 2 deletions internal/widget/scroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

}
s.scrollBy(0, -1*(s.Content.MinSize().Height-s.Size().Height-s.Offset.Y))
s.Refresh()
}

// 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!

}

// DragEnd will stop scrolling on mobile has stopped
Expand Down
Loading