Fixes #222: ensure pooled PageHeaders don't hold onto old state in closures

This commit is contained in:
Drew Weymouth
2023-07-17 17:07:13 -07:00
parent 5a5f551613
commit 5bb65ee6aa
3 changed files with 17 additions and 11 deletions
+7 -5
View File
@@ -189,6 +189,8 @@ type AlbumPageHeader struct {
}
func NewAlbumPageHeader(page *AlbumPage) *AlbumPageHeader {
// due to widget reuse a.page can change so page MUST NOT
// be directly captured in a closure throughout this function!
a := &AlbumPageHeader{page: page}
a.ExtendBaseWidget(a)
a.cover = widgets.NewTappableImage(func(*fyne.PointEvent) { go a.showPopUpCover() })
@@ -202,19 +204,19 @@ func NewAlbumPageHeader(page *AlbumPage) *AlbumPageHeader {
}
a.artistLabel = widgets.NewCustomHyperlink()
a.artistLabel.OnTapped = func() {
page.contr.NavigateTo(controller.ArtistRoute(a.artistID))
a.page.contr.NavigateTo(controller.ArtistRoute(a.artistID))
}
a.genreLabel = widgets.NewCustomHyperlink()
a.genreLabel.OnTapped = func() {
page.contr.NavigateTo(controller.GenreRoute(a.genre))
a.page.contr.NavigateTo(controller.GenreRoute(a.genre))
}
a.miscLabel = widget.NewLabel("")
playButton := widget.NewButtonWithIcon("Play", theme.MediaPlayIcon(), func() {
go page.pm.PlayAlbum(page.albumID, 0, false)
go a.page.pm.PlayAlbum(a.page.albumID, 0, false)
})
shuffleBtn := widget.NewButtonWithIcon(" Shuffle", myTheme.ShuffleIcon, func() {
page.pm.LoadTracks(page.tracklist.GetTracks(), false, true)
page.pm.PlayFromBeginning()
a.page.pm.LoadTracks(a.page.tracklist.GetTracks(), false, true)
a.page.pm.PlayFromBeginning()
})
var pop *widget.PopUpMenu
menuBtn := widget.NewButtonWithIcon("", theme.MoreHorizontalIcon(), nil)