Skip to content

Commit

Permalink
[Compose] Add safeMode (#2455)
Browse files Browse the repository at this point in the history
This allows to use the safeModeApi in LottieAnimation for compose 

Fixes #2452
  • Loading branch information
kunal-jar authored Jan 30, 2024
1 parent 6185eda commit 8b8c22b
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -88,6 +90,7 @@ fun LottieAnimation(
clipTextToBoundingBox: Boolean = false,
fontMap: Map<String, Typeface>? = null,
asyncUpdates: AsyncUpdates = AsyncUpdates.AUTOMATIC,
safeMode: Boolean = false,
) {
val drawable = remember { LottieDrawable() }
val matrix = remember { Matrix() }
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -168,6 +173,7 @@ fun LottieAnimation(
contentScale = contentScale,
clipToCompositionBounds = clipToCompositionBounds,
asyncUpdates = asyncUpdates,
safeMode = safeMode
)
}

Expand Down Expand Up @@ -200,6 +206,7 @@ fun LottieAnimation(
clipToCompositionBounds: Boolean = true,
clipTextToBoundingBox: Boolean = false,
fontMap: Map<String, Typeface>? = null,
safeMode: Boolean = false,
asyncUpdates: AsyncUpdates = AsyncUpdates.AUTOMATIC,
) {
val progress by animateLottieCompositionAsState(
Expand Down Expand Up @@ -227,6 +234,7 @@ fun LottieAnimation(
clipTextToBoundingBox = clipTextToBoundingBox,
fontMap = fontMap,
asyncUpdates = asyncUpdates,
safeMode = safeMode
)
}

Expand Down

0 comments on commit 8b8c22b

Please sign in to comment.