Skip to content

Commit b289075

Browse files
committed
enforce maximum 1 instance of flashbar
1 parent bbc74d0 commit b289075

File tree

1 file changed

+7
-0
lines changed
  • flashbar/src/main/java/com/andrognito/flashbar

1 file changed

+7
-0
lines changed

flashbar/src/main/java/com/andrognito/flashbar/Flashbar.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ class Flashbar private constructor(private var builder: Builder) {
2828
* Shows a flashbar
2929
*/
3030
fun show() {
31+
Flashbar.currentInstance?.also {
32+
if (it.isShown() || it.isShowing())
33+
it.dismiss()
34+
}
3135
flashbarContainerView.show(builder.activity)
36+
Flashbar.currentInstance = this
3237
}
3338

3439
/**
@@ -774,6 +779,8 @@ class Flashbar private constructor(private var builder: Builder) {
774779
const val DURATION_SHORT = 1000L
775780
const val DURATION_LONG = 2500L
776781
const val DURATION_INDEFINITE = -1L
782+
783+
var currentInstance: Flashbar? = null
777784
}
778785

779786
enum class Gravity { TOP, BOTTOM }

0 commit comments

Comments
 (0)