Skip to content

Commit

Permalink
make Activity start/stop idempotent
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Feb 1, 2024
1 parent 3ad2fa0 commit cca9945
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions widget/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var _ fyne.Widget = (*Activity)(nil)
// Since: 2.5
type Activity struct {
BaseWidget

started bool
}

// NewActivity returns a widget for indicating activity
Expand All @@ -37,13 +39,29 @@ func (a *Activity) MinSize() fyne.Size {

// Start the activity indicator animation
func (a *Activity) Start() {
a.propertyLock.Lock()
defer a.propertyLock.Unlock()

if a.started {
return
}

a.started = true
if r, ok := cache.Renderer(a.super()).(*activityRenderer); ok {
r.start()
}
}

// Stop the activity indicator animation
func (a *Activity) Stop() {
a.propertyLock.Lock()
defer a.propertyLock.Unlock()

if !a.started {
return
}

a.started = false
if r, ok := cache.Renderer(a.super()).(*activityRenderer); ok {
r.stop()
}
Expand All @@ -60,6 +78,13 @@ func (a *Activity) CreateRenderer() fyne.WidgetRenderer {
RepeatCount: fyne.AnimationRepeatForever,
Tick: r.animate}
r.updateColor()

a.propertyLock.RLock()
if a.started {
r.start()
}
a.propertyLock.RUnlock()

return r
}

Expand Down

0 comments on commit cca9945

Please sign in to comment.