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

add OnScroll event to list #5329

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from 2 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
6 changes: 6 additions & 0 deletions widget/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type List struct {
UpdateItem func(id ListItemID, item fyne.CanvasObject) `json:"-"`
OnSelected func(id ListItemID) `json:"-"`
OnUnselected func(id ListItemID) `json:"-"`
OnFocus func(id ListItemID) `json:"-"`
Copy link
Contributor

Choose a reason for hiding this comment

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

The naming here should be "OnFocused" to match the convention. Also we will need a comment with a "Since: 2.6" line (see the HideSeparators property for example)


// HideSeparators hides the separators between list rows
//
Expand Down Expand Up @@ -186,6 +187,11 @@ func (l *List) scrollTo(id ListItemID) {
l.scroller.Offset.Y = y + lastItemHeight - l.scroller.Size().Height
}
l.offsetUpdated(l.scroller.Offset)
defer func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

You will want to call this callback whenever l.currentFocus or l.focused changes, not here in scrollTo, since scrollTo is invoked sometimes for things that don't change the focus (like list.ScrollToItem). You will probably also want to add an OnFocusLost API, or else call OnFocused with -1 as the argument whenever the list loses focus.

if f := l.OnFocus; f != nil {
f(id)
}
}()
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, please add some unit tests to verify the behavior, see the existing examples in list_test.go

Copy link
Author

Choose a reason for hiding this comment

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

Done!
Thanks a lot for your hints, let me know if it can be enough

}

// Resize is called when this list should change size. We refresh to ensure invisible items are drawn.
Expand Down