Fix spoiler animation running after view is returned to cache.
This commit is contained in:
parent
36ef36be61
commit
a35a167e7a
1 changed files with 13 additions and 2 deletions
|
@ -5,6 +5,8 @@ import android.graphics.Canvas
|
|||
import android.text.Annotation
|
||||
import android.text.Layout
|
||||
import android.text.Spanned
|
||||
import android.view.View
|
||||
import android.view.View.OnAttachStateChangeListener
|
||||
import android.view.animation.LinearInterpolator
|
||||
import android.widget.TextView
|
||||
import org.thoughtcrime.securesms.components.spoiler.SpoilerAnnotation.SpoilerClickableSpan
|
||||
|
@ -42,6 +44,11 @@ class SpoilerRendererDelegate @JvmOverloads constructor(private val view: TextVi
|
|||
spoilerDrawable = SpoilerDrawable(textColor)
|
||||
single = SingleLineSpoilerRenderer(spoilerDrawable)
|
||||
multi = MultiLineSpoilerRenderer(spoilerDrawable)
|
||||
|
||||
view.addOnAttachStateChangeListener(object : OnAttachStateChangeListener {
|
||||
override fun onViewDetachedFromWindow(v: View) = stopAnimating()
|
||||
override fun onViewAttachedToWindow(v: View) = Unit
|
||||
})
|
||||
}
|
||||
|
||||
fun updateFromTextColor() {
|
||||
|
@ -90,11 +97,15 @@ class SpoilerRendererDelegate @JvmOverloads constructor(private val view: TextVi
|
|||
animatorRunning = true
|
||||
}
|
||||
} else {
|
||||
animator.pause()
|
||||
animatorRunning = false
|
||||
stopAnimating()
|
||||
}
|
||||
}
|
||||
|
||||
private fun stopAnimating() {
|
||||
animator.pause()
|
||||
animatorRunning = false
|
||||
}
|
||||
|
||||
private inline fun <V> MutableMap<Int, V>.getFromCache(vararg keys: Any, default: () -> V): V {
|
||||
if (renderForComposing) {
|
||||
return default()
|
||||
|
|
Loading…
Add table
Reference in a new issue