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 55e4b6b0d..6ea695d86 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 @@ -69,6 +69,8 @@ import kotlin.math.roundToInt * @param fontMap A map of keys to Typefaces. The key can be: "fName", "fFamily", or "fFamily-fStyle" as specified in your Lottie file. * @param asyncUpdates When set to true, some parts of animation updates will be done off of the main thread. * For more details, refer to the docs of [AsyncUpdates]. + * @param safeMode If set to true, draw will be wrapped with a try/catch which will cause Lottie to + * render an empty frame rather than crash your app. */ @Composable @JvmOverloads @@ -88,6 +90,7 @@ fun LottieAnimation( clipTextToBoundingBox: Boolean = false, fontMap: Map? = null, asyncUpdates: AsyncUpdates = AsyncUpdates.AUTOMATIC, + safeMode: Boolean = false, ) { val drawable = remember { LottieDrawable() } val matrix = remember { Matrix() } @@ -111,6 +114,7 @@ fun LottieAnimation( matrix.preScale(scale.scaleX, scale.scaleY) drawable.enableMergePathsForKitKatAndAbove(enableMergePaths) + drawable.setSafeMode(safeMode) drawable.renderMode = renderMode drawable.asyncUpdates = asyncUpdates drawable.composition = composition @@ -152,6 +156,7 @@ fun LottieAnimation( alignment: Alignment = Alignment.Center, contentScale: ContentScale = ContentScale.Fit, clipToCompositionBounds: Boolean = true, + safeMode: Boolean = false, asyncUpdates: AsyncUpdates = AsyncUpdates.AUTOMATIC, ) { LottieAnimation( @@ -168,6 +173,7 @@ fun LottieAnimation( contentScale = contentScale, clipToCompositionBounds = clipToCompositionBounds, asyncUpdates = asyncUpdates, + safeMode = safeMode ) } @@ -200,6 +206,7 @@ fun LottieAnimation( clipToCompositionBounds: Boolean = true, clipTextToBoundingBox: Boolean = false, fontMap: Map? = null, + safeMode: Boolean = false, asyncUpdates: AsyncUpdates = AsyncUpdates.AUTOMATIC, ) { val progress by animateLottieCompositionAsState( @@ -227,6 +234,7 @@ fun LottieAnimation( clipTextToBoundingBox = clipTextToBoundingBox, fontMap = fontMap, asyncUpdates = asyncUpdates, + safeMode = safeMode ) }