Skip to content

Commit

Permalink
Fix spoiler animation running after view is returned to cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
cody-signal authored and greyson-signal committed Apr 12, 2023
1 parent 36ef36b commit a35a167
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit a35a167

Please sign in to comment.