airbnb / lottie-android

Render After Effects animations natively on Android and iOS, Web, and React Native
http://airbnb.io/lottie/
Apache License 2.0
34.95k stars 5.4k forks source link

[a11y] Check for reduced motion frame names #2451

Closed bassettsj closed 7 months ago

bassettsj commented 7 months ago

Brings parity to the android for the changes in iOS airbnb/lottie-ios/pull/2110

This PR adds support for respecting the system "reduction motion" option.

Animations Enabled

https://github.com/airbnb/lottie-android/assets/1218420/d29b62f6-db07-49f9-a7de-221949eef646

Animations Disabled

https://github.com/airbnb/lottie-android/assets/1218420/2f346a78-d637-4c4a-8f60-8aa4e69e140d

github-actions[bot] commented 7 months ago

Snapshot Tests API 23: Report Diff API 31: Report Diff

gpeal commented 7 months ago

If you want to create a ReducedMotionTestCase, that would be great 😄 https://github.com/airbnb/lottie-android/tree/master/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests

bassettsj commented 7 months ago

@gpeal I think I added the test case that might work. Wasn't able to run locally, but we will see with the workflow here.

gpeal commented 7 months ago

Could you apply this patch to fix the test:

diff --git a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/SnapshotTestCaseContext.kt b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/SnapshotTestCaseContext.kt
index c5693a82..92df041d 100644
--- a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/SnapshotTestCaseContext.kt
+++ b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/SnapshotTestCaseContext.kt
@@ -56,7 +56,7 @@ suspend fun SnapshotTestCaseContext.withDrawable(
     assetName: String,
     snapshotName: String,
     snapshotVariant: String,
-    callback: (LottieDrawable) -> Unit,
+    callback: suspend (LottieDrawable) -> Unit,
 ) {
     val result = LottieCompositionFactory.fromAssetSync(context, assetName)
     val composition = result.value ?: throw IllegalArgumentException("Unable to parse $assetName.", result.exception)
@@ -254,4 +254,4 @@ private suspend fun View.awaitFrame() {
             cont.resume(Unit)
         }
     }
-}
\ No newline at end of file
+}
diff --git a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/DisabledAnimationsTestCase.kt b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/DisabledAnimationsTestCase.kt
index f535ae8e..b669635b 100644
--- a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/DisabledAnimationsTestCase.kt
+++ b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/DisabledAnimationsTestCase.kt
@@ -3,17 +3,23 @@ package com.airbnb.lottie.snapshots.tests
 import com.airbnb.lottie.snapshots.SnapshotTestCase
 import com.airbnb.lottie.snapshots.SnapshotTestCaseContext
 import com.airbnb.lottie.snapshots.withDrawable
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext

 class DisabledAnimationsTestCase : SnapshotTestCase {
     override suspend fun SnapshotTestCaseContext.run() {
         withDrawable("Tests/ReducedMotion.json", "System Animations", "Disabled") { drawable ->
-            drawable.setSystemAnimationsAreEnabled(false)
-            drawable.playAnimation()
+            withContext(Dispatchers.Main) {
+                drawable.setSystemAnimationsAreEnabled(false)
+                drawable.playAnimation()
+            }
         }

         withDrawable("Tests/ReducedMotion.json", "System Animations", "Enabled") { drawable ->
-            drawable.setSystemAnimationsAreEnabled(false)
-            drawable.playAnimation()
+            withContext(Dispatchers.Main) {
+                drawable.setSystemAnimationsAreEnabled(false)
+                drawable.playAnimation()
+            }
         }
     }
 }
github-actions[bot] commented 7 months ago

Snapshot Tests API 23: Report Diff API 31: Report Diff

github-actions[bot] commented 7 months ago

Snapshot Tests API 23: Report Diff API 31: Report Diff