Skip to content

Commit 971b5f5

Browse files
committed
make sure the animation is only started once, to improve the animation
inspired by razir#30
1 parent 6fee891 commit 971b5f5

2 files changed

Lines changed: 4 additions & 7 deletions

File tree

progressbutton/src/main/java/com/github/razir/progressbutton/DrawableButtonExtensions.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@ private fun TextView.showDrawable(
180180

181181
addDrawableAttachViewListener()
182182
setupDrawableCallback(this, drawable)
183-
if (drawable is Animatable) {
184-
drawable.start()
185-
}
186183
}
187184

188185
private fun setupDrawableCallback(textView: TextView, drawable: Drawable) {
@@ -199,7 +196,7 @@ private fun setupDrawableCallback(textView: TextView, drawable: Drawable) {
199196
}
200197
activeViews[textView] = DrawableViewData(drawable, callback)
201198
drawable.callback = callback
202-
if (drawable is Animatable) {
199+
if (drawable is Animatable && !drawable.isRunning) {
203200
drawable.start()
204201
}
205202
}

progressbutton/src/main/java/com/github/razir/progressbutton/ProgressButtonHolder.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fun LifecycleOwner.bindProgressButton(button: TextView) {
2727
fun TextView.cleanUpDrawable() {
2828
if (activeViews.containsKey(this)) {
2929
activeViews[this]?.drawable?.apply {
30-
if (this is Animatable) {
30+
if (this is Animatable && drawable.isRunning) {
3131
stop()
3232
}
3333
callback = null
@@ -83,7 +83,7 @@ private val drawablesAttachListener = object : View.OnAttachStateChangeListener
8383
override fun onViewDetachedFromWindow(v: View?) {
8484
if (activeViews.containsKey(v)) {
8585
activeViews[v]?.drawable?.apply {
86-
if (this is Animatable) {
86+
if (this is Animatable && drawable.isRunning) {
8787
stop()
8888
}
8989
}
@@ -93,7 +93,7 @@ private val drawablesAttachListener = object : View.OnAttachStateChangeListener
9393
override fun onViewAttachedToWindow(v: View?) {
9494
if (activeViews.containsKey(v)) {
9595
activeViews[v]?.drawable?.apply {
96-
if (this is Animatable) {
96+
if (this is Animatable && !drawable.isRunning) {
9797
start()
9898
}
9999
}

0 commit comments

Comments
 (0)