From b8e5111792ecb1b31e33f859b29f46400c49d55f Mon Sep 17 00:00:00 2001 From: Kunal Gupta Date: Tue, 30 Jan 2024 21:55:31 +0530 Subject: [PATCH 1/2] Add safeMode in compose LottieAnimation --- .../java/com/airbnb/lottie/compose/LottieAnimation.kt | 8 ++++++++ 1 file changed, 8 insertions(+) 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..4e5e7e0ce 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 isSafeMode 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, + isSafeMode: 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(isSafeMode) 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, + isSafeMode: Boolean = false, asyncUpdates: AsyncUpdates = AsyncUpdates.AUTOMATIC, ) { LottieAnimation( @@ -168,6 +173,7 @@ fun LottieAnimation( contentScale = contentScale, clipToCompositionBounds = clipToCompositionBounds, asyncUpdates = asyncUpdates, + isSafeMode = isSafeMode ) } @@ -200,6 +206,7 @@ fun LottieAnimation( clipToCompositionBounds: Boolean = true, clipTextToBoundingBox: Boolean = false, fontMap: Map? = null, + isSafeMode: Boolean = false, asyncUpdates: AsyncUpdates = AsyncUpdates.AUTOMATIC, ) { val progress by animateLottieCompositionAsState( @@ -227,6 +234,7 @@ fun LottieAnimation( clipTextToBoundingBox = clipTextToBoundingBox, fontMap = fontMap, asyncUpdates = asyncUpdates, + isSafeMode = isSafeMode ) } From dce2b3a67ea7258907cf81ccc42cc27fbc3a8ca1 Mon Sep 17 00:00:00 2001 From: Kunal Gupta Date: Tue, 30 Jan 2024 23:33:53 +0530 Subject: [PATCH 2/2] isSafeMode to safeMode --- .../com/airbnb/lottie/compose/LottieAnimation.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 4e5e7e0ce..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,7 +69,7 @@ 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 isSafeMode If set to true, draw will be wrapped with a try/catch which will cause Lottie to + * @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 @@ -90,7 +90,7 @@ fun LottieAnimation( clipTextToBoundingBox: Boolean = false, fontMap: Map? = null, asyncUpdates: AsyncUpdates = AsyncUpdates.AUTOMATIC, - isSafeMode: Boolean = false, + safeMode: Boolean = false, ) { val drawable = remember { LottieDrawable() } val matrix = remember { Matrix() } @@ -114,7 +114,7 @@ fun LottieAnimation( matrix.preScale(scale.scaleX, scale.scaleY) drawable.enableMergePathsForKitKatAndAbove(enableMergePaths) - drawable.setSafeMode(isSafeMode) + drawable.setSafeMode(safeMode) drawable.renderMode = renderMode drawable.asyncUpdates = asyncUpdates drawable.composition = composition @@ -156,7 +156,7 @@ fun LottieAnimation( alignment: Alignment = Alignment.Center, contentScale: ContentScale = ContentScale.Fit, clipToCompositionBounds: Boolean = true, - isSafeMode: Boolean = false, + safeMode: Boolean = false, asyncUpdates: AsyncUpdates = AsyncUpdates.AUTOMATIC, ) { LottieAnimation( @@ -173,7 +173,7 @@ fun LottieAnimation( contentScale = contentScale, clipToCompositionBounds = clipToCompositionBounds, asyncUpdates = asyncUpdates, - isSafeMode = isSafeMode + safeMode = safeMode ) } @@ -206,7 +206,7 @@ fun LottieAnimation( clipToCompositionBounds: Boolean = true, clipTextToBoundingBox: Boolean = false, fontMap: Map? = null, - isSafeMode: Boolean = false, + safeMode: Boolean = false, asyncUpdates: AsyncUpdates = AsyncUpdates.AUTOMATIC, ) { val progress by animateLottieCompositionAsState( @@ -234,7 +234,7 @@ fun LottieAnimation( clipTextToBoundingBox = clipTextToBoundingBox, fontMap = fontMap, asyncUpdates = asyncUpdates, - isSafeMode = isSafeMode + safeMode = safeMode ) }