[Compose][Breaking] Constrain unconstrained sizes to the composition size (#1892)
Before this change, LottieAnimation would fillMaxSize() by default. this isn't really expected. Now, Lottie will set its size to the composition size. This is still compatible with fillMaxSize() and all other constraint modifiers.
Fixes #1866
diff --git a/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieAnimation.kt b/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieAnimation.kt
index 7f8b83a..679a6ef 100644
--- a/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieAnimation.kt
+++ b/lottie-compose/src/main/java/com/airbnb/lottie/compose/LottieAnimation.kt
@@ -4,7 +4,7 @@
import androidx.annotation.FloatRange
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Box
-import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@@ -18,8 +18,10 @@
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.layout.ScaleFactor
import androidx.compose.ui.unit.IntSize
+import androidx.compose.ui.unit.dp
import com.airbnb.lottie.LottieComposition
import com.airbnb.lottie.LottieDrawable
+import com.airbnb.lottie.utils.Utils
import kotlin.math.roundToInt
/**
@@ -74,9 +76,10 @@
if (composition == null || composition.duration == 0f) return Box(modifier)
+
Canvas(
modifier = modifier
- .fillMaxSize()
+ .size((composition.bounds.width() / Utils.dpScale()).dp, (composition.bounds.height() / Utils.dpScale()).dp)
) {
drawIntoCanvas { canvas ->
val compositionSize = Size(composition.bounds.width().toFloat(), composition.bounds.height().toFloat())