[Compose] Use the correct type for dynamic gradient properties (#1969)
Fixes #1966
diff --git a/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieDynamicProperties.kt b/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieDynamicProperties.kt
index c6333a1..3bec245 100644
--- a/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieDynamicProperties.kt
+++ b/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieDynamicProperties.kt
@@ -96,7 +96,8 @@
private val floatProperties: List<LottieDynamicProperty<Float>>,
private val scaleProperties: List<LottieDynamicProperty<ScaleXY>>,
private val colorFilterProperties: List<LottieDynamicProperty<ColorFilter>>,
- private val intArrayProperties: List<LottieDynamicProperty<IntArray>>,
+ // Java doesn't have reified types. All LottieProperty arrays are Integer[].
+ private val intArrayProperties: List<LottieDynamicProperty<Array<*>>>,
private val typefaceProperties: List<LottieDynamicProperty<Typeface>>,
private val bitmapProperties: List<LottieDynamicProperty<Bitmap>>,
) {
@@ -107,7 +108,7 @@
properties.filter { it.property is Float } as List<LottieDynamicProperty<Float>>,
properties.filter { it.property is ScaleXY } as List<LottieDynamicProperty<ScaleXY>>,
properties.filter { it.property is ColorFilter } as List<LottieDynamicProperty<ColorFilter>>,
- properties.filter { it.property is IntArray } as List<LottieDynamicProperty<IntArray>>,
+ properties.filter { it.property is Array<*> } as List<LottieDynamicProperty<Array<*>>>,
properties.filter { it.property is Typeface } as List<LottieDynamicProperty<Typeface>>,
properties.filter { it.property is Bitmap } as List<LottieDynamicProperty<Bitmap>>,
)
@@ -157,7 +158,7 @@
drawable.addValueCallback(p.keyPath, p.property, null as LottieValueCallback<ColorFilter>?)
}
intArrayProperties.forEach { p ->
- drawable.addValueCallback(p.keyPath, p.property, null as LottieValueCallback<IntArray>?)
+ drawable.addValueCallback(p.keyPath, p.property, null as LottieValueCallback<Array<*>>?)
}
typefaceProperties.forEach { p ->
drawable.addValueCallback(p.keyPath, p.property, null as LottieValueCallback<Typeface>?)
diff --git a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/LottieSnapshotTest.kt b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/LottieSnapshotTest.kt
index 6df7cd4..e758e18 100644
--- a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/LottieSnapshotTest.kt
+++ b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/LottieSnapshotTest.kt
@@ -5,7 +5,6 @@
import android.content.Context
import android.content.res.Configuration
import android.util.Log
-import android.view.View
import android.widget.FrameLayout
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.rules.ActivityScenarioRule
@@ -17,6 +16,7 @@
import com.airbnb.lottie.snapshots.tests.ApplyOpacityToLayerTestCase
import com.airbnb.lottie.snapshots.tests.AssetsTestCase
import com.airbnb.lottie.snapshots.tests.ColorStateListColorFilterTestCase
+import com.airbnb.lottie.snapshots.tests.ComposeDynamicPropertiesTestCase
import com.airbnb.lottie.snapshots.tests.CustomBoundsTestCase
import com.airbnb.lottie.snapshots.tests.DynamicPropertiesTestCase
import com.airbnb.lottie.snapshots.tests.FailureTestCase
@@ -119,6 +119,7 @@
ApplyOpacityToLayerTestCase(),
OutlineMasksAndMattesTestCase(),
LargeCompositionSoftwareRendering(),
+ ComposeDynamicPropertiesTestCase(),
ProdAnimationsTestCase(),
)
diff --git a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/ComposeDynamicPropertiesTestCase.kt b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/ComposeDynamicPropertiesTestCase.kt
new file mode 100644
index 0000000..6356baf
--- /dev/null
+++ b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/ComposeDynamicPropertiesTestCase.kt
@@ -0,0 +1,38 @@
+package com.airbnb.lottie.snapshots.tests
+
+import android.graphics.Color
+import androidx.compose.ui.platform.ComposeView
+import com.airbnb.lottie.LottieCompositionFactory
+import com.airbnb.lottie.LottieProperty
+import com.airbnb.lottie.compose.LottieAnimation
+import com.airbnb.lottie.compose.rememberLottieDynamicProperties
+import com.airbnb.lottie.compose.rememberLottieDynamicProperty
+import com.airbnb.lottie.snapshots.SnapshotTestCase
+import com.airbnb.lottie.snapshots.SnapshotTestCaseContext
+import com.airbnb.lottie.snapshots.snapshotComposable
+import com.airbnb.lottie.snapshots.snapshotComposition
+
+class ComposeDynamicPropertiesTestCase : SnapshotTestCase {
+ override suspend fun SnapshotTestCaseContext.run() {
+ val composition = LottieCompositionFactory.fromAssetSync(context, "Tests/DynamicGradient.json").value!!
+ snapshotComposable("Compose Dynamic Gradient") {
+ val dynamicProperties = rememberLottieDynamicProperties(
+ rememberLottieDynamicProperty(
+ LottieProperty.GRADIENT_COLOR,
+ arrayOf(Color.YELLOW, Color.GREEN),
+ "Linear",
+ "Rectangle",
+ "Gradient Fill"
+ ),
+ rememberLottieDynamicProperty(
+ LottieProperty.GRADIENT_COLOR,
+ arrayOf(Color.YELLOW, Color.GREEN),
+ "Radial",
+ "Rectangle",
+ "Gradient Fill"
+ )
+ )
+ LottieAnimation(composition, 0f, dynamicProperties = dynamicProperties)
+ }
+ }
+}
\ No newline at end of file