Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Compose] Add safeMode #2455

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 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
Expand All @@ -88,6 +90,7 @@ fun LottieAnimation(
clipTextToBoundingBox: Boolean = false,
fontMap: Map<String, Typeface>? = null,
asyncUpdates: AsyncUpdates = AsyncUpdates.AUTOMATIC,
isSafeMode: Boolean = false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
isSafeMode: Boolean = false,
safeMode: Boolean = false,

Let's remove is to be consistent with the other boolean names here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gpeal done

) {
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(isSafeMode)
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,
isSafeMode: Boolean = false,
asyncUpdates: AsyncUpdates = AsyncUpdates.AUTOMATIC,
) {
LottieAnimation(
Expand All @@ -168,6 +173,7 @@ fun LottieAnimation(
contentScale = contentScale,
clipToCompositionBounds = clipToCompositionBounds,
asyncUpdates = asyncUpdates,
isSafeMode = isSafeMode
)
}

Expand Down Expand Up @@ -200,6 +206,7 @@ fun LottieAnimation(
clipToCompositionBounds: Boolean = true,
clipTextToBoundingBox: Boolean = false,
fontMap: Map<String, Typeface>? = null,
isSafeMode: 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,
isSafeMode = isSafeMode
)
}

Expand Down