-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Compose] Allow custom cache keys, dynamic properties for images, and…
… remove font remapping (#1847) This set of changes is all around composition caching: 1) Increase the caching flexibility by allowing arbitrary cache keys. 2) Remove the cacheKey parameter from LottieCompositionSpec.JsonString because it was ambiguous with the new cacheKey parameter. 3) Add dynamic properties for bitmaps. This is helpful because it allows you to set a bitmap on a single LottieAnimation without overwriting the bitmap for the cacheable LottieComposition. 4) Removed fontRemapping for rememberLottieComposition because there was no way to know how to handle caching. Instead, dynamic properties can be used.
- Loading branch information
Showing
18 changed files
with
207 additions
and
74 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...le-compose/src/main/java/com/airbnb/lottie/sample/compose/examples/CachingExamplesPage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.airbnb.lottie.sample.compose.examples | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import com.airbnb.lottie.compose.LottieAnimation | ||
import com.airbnb.lottie.compose.LottieCompositionSpec | ||
import com.airbnb.lottie.compose.rememberLottieComposition | ||
import com.airbnb.lottie.sample.compose.R | ||
|
||
@Composable | ||
fun CachingExamplesPage() { | ||
UsageExamplePageScaffold { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.verticalScroll(rememberScrollState()) | ||
) { | ||
ExampleCard("Default Caching", "Lottie caches compositions by default") { | ||
Example1() | ||
} | ||
ExampleCard("Day/Night", "Animations in raw/res will automatically respect day and night mode") { | ||
Example2() | ||
} | ||
ExampleCard("Skip Cache", "Skip the cache") { | ||
Example3() | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun Example1() { | ||
// By default, Lottie will cache compositions with a key derived from your LottieCompositionSpec. | ||
// If you request the composition multiple times or request it again at some point later, it | ||
// will return the previous composition. LottieComposition itself it stateless. All stateful | ||
// actions should happen within LottieAnimation. | ||
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.heart)) | ||
LottieAnimation(composition) | ||
} | ||
|
||
@Composable | ||
private fun Example2() { | ||
val composition by rememberLottieComposition(LottieCompositionSpec.RawRes(R.raw.sun_moon)) | ||
LottieAnimation(composition) | ||
} | ||
|
||
@Composable | ||
private fun Example3() { | ||
val composition by rememberLottieComposition( | ||
LottieCompositionSpec.RawRes(R.raw.we_accept_inline_image), | ||
// Don't cache this composition. You may want to do this for animations that have images | ||
// because the bitmaps are much larger to store than the rest of the animation. | ||
cacheKey = null, | ||
) | ||
LottieAnimation(composition) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.