Add support for tgs files in Compose
diff --git a/lottie-compose/src/main/java/com/airbnb/lottie/compose/rememberLottieComposition.kt b/lottie-compose/src/main/java/com/airbnb/lottie/compose/rememberLottieComposition.kt
index dfa486c..f5ca1fb 100644
--- a/lottie-compose/src/main/java/com/airbnb/lottie/compose/rememberLottieComposition.kt
+++ b/lottie-compose/src/main/java/com/airbnb/lottie/compose/rememberLottieComposition.kt
@@ -22,6 +22,7 @@
import kotlinx.coroutines.withContext
import java.io.FileInputStream
import java.io.IOException
+import java.util.zip.GZIPInputStream
import java.util.zip.ZipInputStream
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
@@ -157,14 +158,19 @@
null
} else {
val fis = FileInputStream(spec.fileName)
+ val actualCacheKey = if (cacheKey == DefaultCacheKey) spec.fileName else cacheKey
when {
spec.fileName.endsWith("zip") -> LottieCompositionFactory.fromZipStream(
ZipInputStream(fis),
- if (cacheKey == DefaultCacheKey) spec.fileName else cacheKey,
+ actualCacheKey,
+ )
+ spec.fileName.endsWith("tgs") -> LottieCompositionFactory.fromJsonInputStream(
+ GZIPInputStream(fis),
+ actualCacheKey,
)
else -> LottieCompositionFactory.fromJsonInputStream(
fis,
- if (cacheKey == DefaultCacheKey) spec.fileName else cacheKey,
+ actualCacheKey,
)
}
}
@@ -181,8 +187,22 @@
LottieCompositionFactory.fromJsonString(spec.jsonString, jsonStringCacheKey)
}
is LottieCompositionSpec.ContentProvider -> {
- val inputStream = context.contentResolver.openInputStream(spec.uri)
- LottieCompositionFactory.fromJsonInputStream(inputStream, if (cacheKey == DefaultCacheKey) spec.uri.toString() else cacheKey)
+ val fis = context.contentResolver.openInputStream(spec.uri)
+ val actualCacheKey = if (cacheKey == DefaultCacheKey) spec.uri.toString() else cacheKey
+ when {
+ spec.uri.toString().endsWith("zip") -> LottieCompositionFactory.fromZipStream(
+ ZipInputStream(fis),
+ actualCacheKey,
+ )
+ spec.uri.toString().endsWith("tgs") -> LottieCompositionFactory.fromJsonInputStream(
+ GZIPInputStream(fis),
+ actualCacheKey,
+ )
+ else -> LottieCompositionFactory.fromJsonInputStream(
+ fis,
+ actualCacheKey,
+ )
+ }
}
}
}
@@ -310,4 +330,4 @@
isBlank() -> this
startsWith(".") -> this
else -> ".$this"
-}
\ No newline at end of file
+}
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 e5149c6..0e6de82 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
@@ -12,18 +12,12 @@
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Text
-import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.airbnb.lottie.compose.LottieAnimation
-import com.airbnb.lottie.compose.LottieCompositionSpec
-import com.airbnb.lottie.compose.LottieConstants
-import com.airbnb.lottie.compose.animateLottieCompositionAsState
-import com.airbnb.lottie.compose.rememberLottieComposition
-import com.airbnb.lottie.snapshots.R
import com.airbnb.lottie.snapshots.SnapshotTestCase
import com.airbnb.lottie.snapshots.SnapshotTestCaseContext
import com.airbnb.lottie.snapshots.loadCompositionFromAssetsSync