-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zhirkevich Alexander Y
authored and
Zhirkevich Alexander Y
committed
Oct 21, 2024
1 parent
9dc11ba
commit 9bf8a57
Showing
15 changed files
with
280 additions
and
44 deletions.
There are no files selected for viewing
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
37 changes: 37 additions & 0 deletions
37
compottie/src/commonMain/kotlin/io/github/alexzhirkevich/compottie/internal/Slots.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,37 @@ | ||
package io.github.alexzhirkevich.compottie.internal | ||
|
||
import io.github.alexzhirkevich.compottie.internal.animation.AnimatedColor | ||
import io.github.alexzhirkevich.compottie.internal.animation.AnimatedGradient | ||
import io.github.alexzhirkevich.compottie.internal.animation.AnimatedNumber | ||
import io.github.alexzhirkevich.compottie.internal.animation.AnimatedShape | ||
import io.github.alexzhirkevich.compottie.internal.animation.AnimatedVector2 | ||
import io.github.alexzhirkevich.compottie.internal.animation.RawProperty | ||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlinx.serialization.json.JsonElement | ||
|
||
internal class Slots( | ||
private val slots : Map<String, JsonElement> | ||
) { | ||
private val cache = mutableMapOf<String, RawProperty<*>>() | ||
|
||
fun number(sid: String): AnimatedNumber? = property(sid, AnimatedNumber.serializer()) | ||
fun vector(sid: String): AnimatedVector2? = property(sid, AnimatedVector2.serializer()) | ||
fun color(sid: String): AnimatedColor? = property(sid, AnimatedColor.serializer()) | ||
fun gradient(sid: String): AnimatedGradient? = property(sid, AnimatedGradient.serializer()) | ||
fun shape(sid: String) : AnimatedShape? = property(sid, AnimatedShape.serializer()) | ||
|
||
private fun <T : RawProperty<*>> property( | ||
sid : String, | ||
deserializer : DeserializationStrategy<T>, | ||
) : T? { | ||
println("Slot requested: $sid") | ||
val json = slots[sid] ?: return null | ||
val cached = cache[sid] | ||
if (cached != null){ | ||
return cached as T | ||
} | ||
val new = LottieJson.decodeFromJsonElement(deserializer, json) | ||
cache[sid] = new | ||
return new | ||
} | ||
} |
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
Oops, something went wrong.