Skip to content

Commit

Permalink
fix accordion locking
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Feb 1, 2024
1 parent 3ad2fa0 commit 29435b0
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions widget/accordion.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,11 @@ func (a *Accordion) Append(item *AccordionItem) {

// Close collapses the item at the given index.
func (a *Accordion) Close(index int) {
a.propertyLock.RLock()
numItems := len(a.Items)
a.propertyLock.RUnlock()

if index < 0 || index >= numItems {
a.propertyLock.Lock()
if index < 0 || index >= len(a.Items) {
a.propertyLock.Unlock()
return
}

a.propertyLock.Lock()
a.Items[index].Open = false
a.propertyLock.Unlock()

Expand Down Expand Up @@ -79,15 +75,13 @@ func (a *Accordion) MinSize() fyne.Size {

// Open expands the item at the given index.
func (a *Accordion) Open(index int) {
a.propertyLock.RLock()
numItems := len(a.Items)
a.propertyLock.RUnlock()
a.propertyLock.Lock()

if index < 0 || index >= numItems {
if index < 0 || index >= len(a.Items) {
a.propertyLock.Unlock()
return
}

a.propertyLock.Lock()
for i, ai := range a.Items {
if i == index {
ai.Open = true
Expand Down Expand Up @@ -134,15 +128,11 @@ func (a *Accordion) Remove(item *AccordionItem) {

// RemoveIndex deletes the item at the given index from this Accordion.
func (a *Accordion) RemoveIndex(index int) {
a.propertyLock.RLock()
numItems := len(a.Items)
a.propertyLock.RUnlock()

if index < 0 || index >= numItems {
a.propertyLock.Lock()
if index < 0 || index >= len(a.Items) {
a.propertyLock.Unlock()
return
}

a.propertyLock.Lock()
a.Items = append(a.Items[:index], a.Items[index+1:]...)
a.propertyLock.Unlock()

Expand Down

0 comments on commit 29435b0

Please sign in to comment.