Fix Do not animate spoilers if system animations are disabled.

Closes #13016
This commit is contained in:
Sgn-32
2023-06-22 16:54:55 +02:00
committed by Nicholas
parent f51fb9da29
commit 14b41a93e2
2 changed files with 5 additions and 6 deletions

View File

@@ -11,7 +11,6 @@ import androidx.annotation.MainThread
import org.signal.core.util.DimensionUnit import org.signal.core.util.DimensionUnit
import org.signal.core.util.dp import org.signal.core.util.dp
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
import org.thoughtcrime.securesms.util.AccessibilityUtil
import org.thoughtcrime.securesms.util.Util import org.thoughtcrime.securesms.util.Util
import kotlin.random.Random import kotlin.random.Random
@@ -65,14 +64,14 @@ object SpoilerPaint {
bounds.bottom + strokeWidth.toInt() bounds.bottom + strokeWidth.toInt()
) )
update(!AccessibilityUtil.areAnimationsDisabled(ApplicationDependencies.getApplication())) update()
} }
/** /**
* Invoke every time before you need to use the [shader]. * Invoke every time before you need to use the [shader].
*/ */
@MainThread @MainThread
fun update(animationsEnabled: Boolean) { fun update() {
val now = System.currentTimeMillis() val now = System.currentTimeMillis()
var dt = now - lastDrawTime var dt = now - lastDrawTime
if (dt < 48) { if (dt < 48) {
@@ -87,7 +86,7 @@ object SpoilerPaint {
// To avoid that, we draw into a buffer, then swap the buffer into the shader when it's fully drawn. // To avoid that, we draw into a buffer, then swap the buffer into the shader when it's fully drawn.
val canvas = Canvas(bufferBitmap) val canvas = Canvas(bufferBitmap)
bufferBitmap.eraseColor(Color.TRANSPARENT) bufferBitmap.eraseColor(Color.TRANSPARENT)
draw(canvas, if (animationsEnabled) dt else 0) draw(canvas, dt)
val swap = shaderBitmap val swap = shaderBitmap
shaderBitmap = bufferBitmap shaderBitmap = bufferBitmap

View File

@@ -38,7 +38,7 @@ class SpoilerRendererDelegate @JvmOverloads constructor(
private val animator = TimeAnimator().apply { private val animator = TimeAnimator().apply {
setTimeListener { _, _, _ -> setTimeListener { _, _, _ ->
SpoilerPaint.update(systemAnimationsEnabled) SpoilerPaint.update()
view.invalidate() view.invalidate()
} }
} }
@@ -114,7 +114,7 @@ class SpoilerRendererDelegate @JvmOverloads constructor(
hasSpoilersToRender = true hasSpoilersToRender = true
} }
if (hasSpoilersToRender) { if (hasSpoilersToRender && systemAnimationsEnabled) {
if (!animatorRunning) { if (!animatorRunning) {
animator.start() animator.start()
animatorRunning = true animatorRunning = true