Updated tests
diff --git a/sample-compose/src/androidTest/java/com/airbnb/lottie/samples/InfiniteAnimationTest.kt b/sample-compose/src/androidTest/java/com/airbnb/lottie/samples/InfiniteAnimationTest.kt
index 624c122..1ebb7c6 100644
--- a/sample-compose/src/androidTest/java/com/airbnb/lottie/samples/InfiniteAnimationTest.kt
+++ b/sample-compose/src/androidTest/java/com/airbnb/lottie/samples/InfiniteAnimationTest.kt
@@ -36,7 +36,7 @@
) {
LottieAnimation(
composition,
- progress,
+ { progress },
)
Text(
"Composition Loaded!",
diff --git a/sample-compose/src/androidTest/java/com/airbnb/lottie/samples/WalkthroughAnimationTest.kt b/sample-compose/src/androidTest/java/com/airbnb/lottie/samples/WalkthroughAnimationTest.kt
index ec62397..6bdb3f5 100644
--- a/sample-compose/src/androidTest/java/com/airbnb/lottie/samples/WalkthroughAnimationTest.kt
+++ b/sample-compose/src/androidTest/java/com/airbnb/lottie/samples/WalkthroughAnimationTest.kt
@@ -32,7 +32,7 @@
) {
LottieAnimation(
composition,
- progress,
+ { progress },
)
}
diff --git a/sample-compose/src/main/java/com/airbnb/lottie/sample/compose/examples/BasicUsageExamplesPage.kt b/sample-compose/src/main/java/com/airbnb/lottie/sample/compose/examples/BasicUsageExamplesPage.kt
index f82e2ba..7febf7d 100644
--- a/sample-compose/src/main/java/com/airbnb/lottie/sample/compose/examples/BasicUsageExamplesPage.kt
+++ b/sample-compose/src/main/java/com/airbnb/lottie/sample/compose/examples/BasicUsageExamplesPage.kt
@@ -124,7 +124,7 @@
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.heart))
LottieAnimation(
composition,
- progress = 0.65f,
+ progress = { 0.65f },
)
}
diff --git a/sample-compose/src/main/java/com/airbnb/lottie/sample/compose/examples/ContentScaleExamplesPage.kt b/sample-compose/src/main/java/com/airbnb/lottie/sample/compose/examples/ContentScaleExamplesPage.kt
index f12438c..8599a6d 100644
--- a/sample-compose/src/main/java/com/airbnb/lottie/sample/compose/examples/ContentScaleExamplesPage.kt
+++ b/sample-compose/src/main/java/com/airbnb/lottie/sample/compose/examples/ContentScaleExamplesPage.kt
@@ -61,7 +61,7 @@
) {
LottieAnimation(
composition,
- progress = 0f,
+ progress = { 0f },
alignment = alignment,
contentScale = contentScale,
)
diff --git a/sample-compose/src/main/java/com/airbnb/lottie/sample/compose/examples/TextExamplesPage.kt b/sample-compose/src/main/java/com/airbnb/lottie/sample/compose/examples/TextExamplesPage.kt
index 6c17fb3..0bab4ea 100644
--- a/sample-compose/src/main/java/com/airbnb/lottie/sample/compose/examples/TextExamplesPage.kt
+++ b/sample-compose/src/main/java/com/airbnb/lottie/sample/compose/examples/TextExamplesPage.kt
@@ -51,7 +51,7 @@
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.name))
LottieAnimation(
composition,
- progress = 0f,
+ progress = { 0f },
)
}
@@ -65,7 +65,7 @@
LottieAnimation(
composition,
- progress = 0f,
+ progress = { 0f },
dynamicProperties = dynamicProperties,
)
}
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 35dc7e5..bd8ed08 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
@@ -13,7 +13,10 @@
import android.widget.LinearLayout
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.compositionLocalOf
+import androidx.compose.runtime.getValue
import androidx.compose.ui.platform.ComposeView
import com.airbnb.lottie.FontAssetDelegate
import com.airbnb.lottie.LottieAnimationView
@@ -189,7 +192,12 @@
CompositionLocalProvider(LocalSnapshotReady provides readyFlow) {
content(RenderMode.SOFTWARE)
}
- if (readyFlow.value == null) readyFlow.value = true
+ val readyFlowValue by readyFlow.collectAsState()
+ LaunchedEffect(readyFlowValue) {
+ if (readyFlowValue == null) {
+ readyFlow.value = true
+ }
+ }
}
onActivity { activity ->
activity.binding.content.addView(composeView)
@@ -211,7 +219,12 @@
CompositionLocalProvider(LocalSnapshotReady provides readyFlow) {
content(RenderMode.HARDWARE)
}
- if (readyFlow.value == null) readyFlow.value = true
+ val readyFlowValue by readyFlow.collectAsState()
+ LaunchedEffect(readyFlowValue) {
+ if (readyFlowValue == null) {
+ readyFlow.value = true
+ }
+ }
}
readyFlow.first { it == true }
composeView.awaitFrame()
diff --git a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/ClipChildrenTestCase.kt b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/ClipChildrenTestCase.kt
index f2408e8..f8cb06c 100644
--- a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/ClipChildrenTestCase.kt
+++ b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/ClipChildrenTestCase.kt
@@ -27,7 +27,7 @@
) {
LottieAnimation(
composition,
- 0.7f,
+ { 0.7f },
contentScale = ContentScale.Crop,
renderMode = renderMode,
modifier = Modifier
@@ -44,7 +44,7 @@
) {
LottieAnimation(
composition,
- 0.7f,
+ { 0.7f },
contentScale = ContentScale.Crop,
renderMode = renderMode,
clipToCompositionBounds = false,
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
index a4b9be7..00bc92d 100644
--- 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
@@ -3,6 +3,7 @@
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
+import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import com.airbnb.lottie.LottieCompositionFactory
import com.airbnb.lottie.LottieProperty
@@ -36,45 +37,48 @@
"Gradient Fill"
)
)
- LottieAnimation(composition, 0f, dynamicProperties = dynamicProperties)
+ LottieAnimation(composition, { 0f }, dynamicProperties = dynamicProperties)
}
val heartComposition = LottieCompositionFactory.fromAssetSync(context, "Tests/Heart.json").value!!
snapshotComposable("Compose Dynamic Image", "Default") {
val composition by rememberLottieComposition(LottieCompositionSpec.Asset("Tests/Heart.json"))
- LocalSnapshotReady.current.value = composition != null
- LottieAnimation(composition, 0f)
+ val snapshotReady = LocalSnapshotReady.current
+ LaunchedEffect(snapshotReady, composition != null) {
+ snapshotReady.value = composition != null
+ }
+ LottieAnimation(composition, { 0f })
}
snapshotComposable("Compose Dynamic Image", "Default - Maintain Original Bounds") {
- LottieAnimation(heartComposition, 0f, maintainOriginalImageBounds = true)
+ LottieAnimation(heartComposition, { 0f }, maintainOriginalImageBounds = true)
}
snapshotComposable("Compose Dynamic Image", "Smaller") {
val bitmap = getBitmapFromAssets("Images/Heart-80.png")
val dynamicProperties = rememberLottieDynamicProperties(
rememberLottieDynamicProperty(LottieProperty.IMAGE, bitmap, "Heart"),
)
- LottieAnimation(heartComposition, 0f, dynamicProperties = dynamicProperties)
+ LottieAnimation(heartComposition, { 0f }, dynamicProperties = dynamicProperties)
}
snapshotComposable("Compose Dynamic Image", "Smaller - Maintain Original Bounds") {
val bitmap = getBitmapFromAssets("Images/Heart-80.png")
val dynamicProperties = rememberLottieDynamicProperties(
rememberLottieDynamicProperty(LottieProperty.IMAGE, bitmap, "Heart"),
)
- LottieAnimation(heartComposition, 0f, dynamicProperties = dynamicProperties, maintainOriginalImageBounds = true)
+ LottieAnimation(heartComposition, { 0f }, dynamicProperties = dynamicProperties, maintainOriginalImageBounds = true)
}
snapshotComposable("Compose Dynamic Image", "Larger") {
val bitmap = getBitmapFromAssets("Images/Heart-1200.png")
val dynamicProperties = rememberLottieDynamicProperties(
rememberLottieDynamicProperty(LottieProperty.IMAGE, bitmap, "Heart"),
)
- LottieAnimation(heartComposition, 0f, dynamicProperties = dynamicProperties)
+ LottieAnimation(heartComposition, { 0f }, dynamicProperties = dynamicProperties)
}
snapshotComposable("Compose Dynamic Image", "Larger - Maintain Original Bounds") {
val bitmap = getBitmapFromAssets("Images/Heart-1200.png")
val dynamicProperties = rememberLottieDynamicProperties(
rememberLottieDynamicProperty(LottieProperty.IMAGE, bitmap, "Heart"),
)
- LottieAnimation(heartComposition, 0f, dynamicProperties = dynamicProperties, maintainOriginalImageBounds = true)
+ LottieAnimation(heartComposition, { 0f }, dynamicProperties = dynamicProperties, maintainOriginalImageBounds = true)
}
}
diff --git a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/ComposeScaleTypesTestCase.kt b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/ComposeScaleTypesTestCase.kt
index fa99b35..54f993d 100644
--- a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/ComposeScaleTypesTestCase.kt
+++ b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/ComposeScaleTypesTestCase.kt
@@ -17,7 +17,7 @@
snapshotComposable("Compose Scale Types", "Wrap Content", renderHardwareAndSoftware = true) { renderMode ->
LottieAnimation(
composition,
- 1f,
+ { 1f },
renderMode = renderMode,
)
}
@@ -25,7 +25,7 @@
snapshotComposable("Compose Scale Types", "720p", renderHardwareAndSoftware = true) { renderMode ->
LottieAnimation(
composition,
- 1f,
+ { 1f },
renderMode = renderMode,
modifier = Modifier
.size(720.dp, 1280.dp)
@@ -35,7 +35,7 @@
snapshotComposable("Compose Scale Types", "300x300@2x", renderHardwareAndSoftware = true) { renderMode ->
LottieAnimation(
composition,
- 1f,
+ { 1f },
renderMode = renderMode,
modifier = Modifier
.size(300.dp, 300.dp)
@@ -46,7 +46,7 @@
snapshotComposable("Compose Scale Types", "300x300@4x", renderHardwareAndSoftware = true) { renderMode ->
LottieAnimation(
composition,
- 1f,
+ { 1f },
renderMode = renderMode,
modifier = Modifier
.size(300.dp, 300.dp)
@@ -57,7 +57,7 @@
snapshotComposable("Compose Scale Types", "300x300 Crop", renderHardwareAndSoftware = true) { renderMode ->
LottieAnimation(
composition,
- 1f,
+ { 1f },
contentScale = ContentScale.Crop,
renderMode = renderMode,
modifier = Modifier
@@ -68,7 +68,7 @@
snapshotComposable("Compose Scale Types", "300x300 Inside", renderHardwareAndSoftware = true) { renderMode ->
LottieAnimation(
composition,
- 1f,
+ { 1f },
contentScale = ContentScale.Inside,
renderMode = renderMode,
modifier = Modifier
@@ -79,7 +79,7 @@
snapshotComposable("Compose Scale Types", "300x300 FillBounds", renderHardwareAndSoftware = true) { renderMode ->
LottieAnimation(
composition,
- 1f,
+ { 1f },
contentScale = ContentScale.FillBounds,
renderMode = renderMode,
modifier = Modifier
@@ -90,7 +90,7 @@
snapshotComposable("Compose Scale Types", "300x300 Fit 2x", renderHardwareAndSoftware = true) { renderMode ->
LottieAnimation(
composition,
- 1f,
+ { 1f },
contentScale = ContentScale.Fit,
renderMode = renderMode,
modifier = Modifier
@@ -102,7 +102,7 @@
snapshotComposable("Compose Scale Types", "300x300 Crop 2x", renderHardwareAndSoftware = true) { renderMode ->
LottieAnimation(
composition,
- 1f,
+ { 1f },
contentScale = ContentScale.Crop,
renderMode = renderMode,
modifier = Modifier
@@ -114,7 +114,7 @@
snapshotComposable("Compose Scale Types", "600x600 Inside", renderHardwareAndSoftware = true) { renderMode ->
LottieAnimation(
composition,
- 1f,
+ { 1f },
contentScale = ContentScale.Inside,
renderMode = renderMode,
modifier = Modifier
@@ -125,7 +125,7 @@
snapshotComposable("Compose Scale Types", "600x600 FillBounds", renderHardwareAndSoftware = true) { renderMode ->
LottieAnimation(
composition,
- 1f,
+ { 1f },
contentScale = ContentScale.FillBounds,
renderMode = renderMode,
modifier = Modifier
@@ -136,7 +136,7 @@
snapshotComposable("Compose Scale Types", "600x600 Fit", renderHardwareAndSoftware = true) { renderMode ->
LottieAnimation(
composition,
- 1f,
+ { 1f },
contentScale = ContentScale.Fit,
renderMode = renderMode,
modifier = Modifier
@@ -147,7 +147,7 @@
snapshotComposable("Compose Scale Types", "300x600 FitBounds", renderHardwareAndSoftware = true) { renderMode ->
LottieAnimation(
composition,
- 1f,
+ { 1f },
contentScale = ContentScale.FillBounds,
renderMode = renderMode,
modifier = Modifier
diff --git a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/LargeCompositionSoftwareRendering.kt b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/LargeCompositionSoftwareRendering.kt
index ae4fb16..ddcbc4a 100644
--- a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/LargeCompositionSoftwareRendering.kt
+++ b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/LargeCompositionSoftwareRendering.kt
@@ -6,7 +6,6 @@
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
-import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
@@ -15,8 +14,6 @@
import com.airbnb.lottie.LottieComposition
import com.airbnb.lottie.LottieCompositionFactory
import com.airbnb.lottie.compose.LottieAnimation
-import com.airbnb.lottie.compose.LottieCompositionSpec
-import com.airbnb.lottie.compose.rememberLottieComposition
import com.airbnb.lottie.snapshots.SnapshotTestCase
import com.airbnb.lottie.snapshots.SnapshotTestCaseContext
import com.airbnb.lottie.snapshots.snapshotComposable
@@ -55,25 +52,25 @@
}
snapshotWithComposable("Fit") { comp ->
- LottieAnimation(comp, progress = 0f, contentScale = ContentScale.Fit)
+ LottieAnimation(comp, progress = { 0f }, contentScale = ContentScale.Fit)
}
snapshotWithComposable("Crop") { comp ->
- LottieAnimation(comp, progress = 0f, contentScale = ContentScale.Crop)
+ LottieAnimation(comp, progress = { 0f }, contentScale = ContentScale.Crop)
}
snapshotWithComposable("FillBounds") { comp ->
- LottieAnimation(comp, progress = 0f, contentScale = ContentScale.FillBounds)
+ LottieAnimation(comp, progress = { 0f }, contentScale = ContentScale.FillBounds)
}
snapshotWithComposable("FillWidth") { comp ->
- LottieAnimation(comp, progress = 0f, contentScale = ContentScale.FillWidth)
+ LottieAnimation(comp, progress = { 0f }, contentScale = ContentScale.FillWidth)
}
snapshotWithComposable("FillHeight") { comp ->
- LottieAnimation(comp, progress = 0f, contentScale = ContentScale.FillHeight)
+ LottieAnimation(comp, progress = { 0f }, contentScale = ContentScale.FillHeight)
}
snapshotWithComposable("Inside") { comp ->
- LottieAnimation(comp, progress = 0f, contentScale = ContentScale.Inside)
+ LottieAnimation(comp, progress = { 0f }, contentScale = ContentScale.Inside)
}
snapshotWithComposable("None") { comp ->
- LottieAnimation(comp, progress = 0f, contentScale = ContentScale.None)
+ LottieAnimation(comp, progress = { 0f }, contentScale = ContentScale.None)
}
}
diff --git a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/TextTestCase.kt b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/TextTestCase.kt
index 601c0ac..ebb7ea8 100644
--- a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/TextTestCase.kt
+++ b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/TextTestCase.kt
@@ -1,7 +1,7 @@
package com.airbnb.lottie.snapshots.tests
+import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
-import com.airbnb.lottie.LottieCompositionFactory
import com.airbnb.lottie.LottieProperty
import com.airbnb.lottie.TextDelegate
import com.airbnb.lottie.compose.LottieAnimation
@@ -12,7 +12,6 @@
import com.airbnb.lottie.snapshots.LocalSnapshotReady
import com.airbnb.lottie.snapshots.SnapshotTestCase
import com.airbnb.lottie.snapshots.SnapshotTestCaseContext
-import com.airbnb.lottie.snapshots.loadCompositionFromAssetsSync
import com.airbnb.lottie.snapshots.snapshotComposable
import com.airbnb.lottie.snapshots.withAnimationView
@@ -140,53 +139,68 @@
snapshotComposable("Compose Dynamic Text", "Emoji") {
val composition by rememberLottieComposition(LottieCompositionSpec.Asset("Tests/DynamicText.json"))
- LocalSnapshotReady.current.value = composition != null
+ val snapshotReady = LocalSnapshotReady.current
+ LaunchedEffect(snapshotReady, composition != null) {
+ snapshotReady.value = composition != null
+ }
val dynamicProperties = rememberLottieDynamicProperties(
rememberLottieDynamicProperty(LottieProperty.TEXT, "NAME") {
"🔥💪💯"
},
)
- LottieAnimation(composition, 0f, dynamicProperties = dynamicProperties)
+ LottieAnimation(composition, { 0f }, dynamicProperties = dynamicProperties)
}
snapshotComposable("Compose Dynamic Text", "Taiwanese") {
val composition by rememberLottieComposition(LottieCompositionSpec.Asset("Tests/DynamicText.json"))
- LocalSnapshotReady.current.value = composition != null
+ val snapshotReady = LocalSnapshotReady.current
+ LaunchedEffect(snapshotReady, composition != null) {
+ snapshotReady.value = composition != null
+ }
val dynamicProperties = rememberLottieDynamicProperties(
rememberLottieDynamicProperty(LottieProperty.TEXT, "我的密碼", "NAME"),
)
- LottieAnimation(composition, 0f, dynamicProperties = dynamicProperties)
+ LottieAnimation(composition, { 0f }, dynamicProperties = dynamicProperties)
}
snapshotComposable("Compose Dynamic Text", "Hindi") {
val composition by rememberLottieComposition(LottieCompositionSpec.Asset("Tests/DynamicText.json"))
- LocalSnapshotReady.current.value = composition != null
+ val snapshotReady = LocalSnapshotReady.current
+ LaunchedEffect(snapshotReady, composition != null) {
+ snapshotReady.value = composition != null
+ }
val dynamicProperties = rememberLottieDynamicProperties(
rememberLottieDynamicProperty(LottieProperty.TEXT, "आपका लेख", "NAME"),
)
- LottieAnimation(composition, 0f, dynamicProperties = dynamicProperties)
+ LottieAnimation(composition, { 0f }, dynamicProperties = dynamicProperties)
}
snapshotComposable("Compose Dynamic Text", "FrameInfo.startValue") {
val composition by rememberLottieComposition(LottieCompositionSpec.Asset("Tests/DynamicText.json"))
- LocalSnapshotReady.current.value = composition != null
+ val snapshotReady = LocalSnapshotReady.current
+ LaunchedEffect(snapshotReady, composition != null) {
+ snapshotReady.value = composition != null
+ }
val dynamicProperties = rememberLottieDynamicProperties(
rememberLottieDynamicProperty(LottieProperty.TEXT, "NAME") { frameInfo ->
"${frameInfo.startValue}!!!"
},
)
- LottieAnimation(composition, 0f, dynamicProperties = dynamicProperties)
+ LottieAnimation(composition, { 0f }, dynamicProperties = dynamicProperties)
}
snapshotComposable("Compose Dynamic Text", "FrameInfo.endValue") {
val composition by rememberLottieComposition(LottieCompositionSpec.Asset("Tests/DynamicText.json"))
- LocalSnapshotReady.current.value = composition != null
+ val snapshotReady = LocalSnapshotReady.current
+ LaunchedEffect(snapshotReady, composition != null) {
+ snapshotReady.value = composition != null
+ }
val dynamicProperties = rememberLottieDynamicProperties(
rememberLottieDynamicProperty(LottieProperty.TEXT, "NAME") { frameInfo ->
"${frameInfo.endValue}!!!"
},
)
- LottieAnimation(composition, 0f, dynamicProperties = dynamicProperties)
+ LottieAnimation(composition, { 0f }, dynamicProperties = dynamicProperties)
}
}
}
\ No newline at end of file