mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 12:38:33 +00:00
Fix spoiler animation running after view is returned to cache.
This commit is contained in:
committed by
Greyson Parrelli
parent
36ef36be61
commit
a35a167e7a
@@ -5,6 +5,8 @@ import android.graphics.Canvas
|
|||||||
import android.text.Annotation
|
import android.text.Annotation
|
||||||
import android.text.Layout
|
import android.text.Layout
|
||||||
import android.text.Spanned
|
import android.text.Spanned
|
||||||
|
import android.view.View
|
||||||
|
import android.view.View.OnAttachStateChangeListener
|
||||||
import android.view.animation.LinearInterpolator
|
import android.view.animation.LinearInterpolator
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import org.thoughtcrime.securesms.components.spoiler.SpoilerAnnotation.SpoilerClickableSpan
|
import org.thoughtcrime.securesms.components.spoiler.SpoilerAnnotation.SpoilerClickableSpan
|
||||||
@@ -42,6 +44,11 @@ class SpoilerRendererDelegate @JvmOverloads constructor(private val view: TextVi
|
|||||||
spoilerDrawable = SpoilerDrawable(textColor)
|
spoilerDrawable = SpoilerDrawable(textColor)
|
||||||
single = SingleLineSpoilerRenderer(spoilerDrawable)
|
single = SingleLineSpoilerRenderer(spoilerDrawable)
|
||||||
multi = MultiLineSpoilerRenderer(spoilerDrawable)
|
multi = MultiLineSpoilerRenderer(spoilerDrawable)
|
||||||
|
|
||||||
|
view.addOnAttachStateChangeListener(object : OnAttachStateChangeListener {
|
||||||
|
override fun onViewDetachedFromWindow(v: View) = stopAnimating()
|
||||||
|
override fun onViewAttachedToWindow(v: View) = Unit
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateFromTextColor() {
|
fun updateFromTextColor() {
|
||||||
@@ -90,10 +97,14 @@ class SpoilerRendererDelegate @JvmOverloads constructor(private val view: TextVi
|
|||||||
animatorRunning = true
|
animatorRunning = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
stopAnimating()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun stopAnimating() {
|
||||||
animator.pause()
|
animator.pause()
|
||||||
animatorRunning = false
|
animatorRunning = false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private inline fun <V> MutableMap<Int, V>.getFromCache(vararg keys: Any, default: () -> V): V {
|
private inline fun <V> MutableMap<Int, V>.getFromCache(vararg keys: Any, default: () -> V): V {
|
||||||
if (renderForComposing) {
|
if (renderForComposing) {
|
||||||
|
|||||||
Reference in New Issue
Block a user