Skip to content

Commit

Permalink
fixed dynamic image buttons not displaying anything
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnemotechnician committed Aug 24, 2022
1 parent a7ed8de commit 280baef
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/src/main/kotlin/extensions/dsl/ButtonDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ inline fun Table.imageButton(
})
}

/** Adds an image button with a dynamic image and an optional onclick listener, returns the created cell */
/** Adds an image button with a dynamic image and an optional onclick listener, returns the created cell. */
inline fun Table.imageButton(
crossinline provider: () -> Drawable?,
style: ImageButton.ImageButtonStyle = Styles.defaulti,
crossinline onclick: ImageButton.() -> Unit = {}
): Cell<ImageButton> {
return add(ImageButton(style).also {
return add(DynamicImageButton(style).also {
it.clicked { onclick(it) }
it.update { it.image.drawable = provider() }
})
Expand Down Expand Up @@ -209,3 +209,9 @@ fun Table.menuButton(
this.icon.drawable = icon()
}
})

/** Workarpund: ImageButton tries to change the drawable before drawing, so this class is required to fix that. */
@PublishedApi
internal class DynamicImageButton(style: ImageButton.ImageButtonStyle) : ImageButton(style) {
override fun updateImage() {}
}

0 comments on commit 280baef

Please sign in to comment.