skiaMain.skiaComposition.SkiaComposition.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kottie Show documentation
Show all versions of kottie Show documentation
Kotlin Multiplatform Animation Library
package skiaComposition
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import io.ktor.client.HttpClient
import io.ktor.client.request.get
import io.ktor.client.statement.bodyAsText
import kottie.lib.generated.resources.Res
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.skia.Data
import org.jetbrains.skia.skottie.Animation
@OptIn(ExperimentalResourceApi::class)
@Composable
internal fun rememberSkiaComposition(
spec: SkiaCompositionSpec
): Animation? {
var animationState by remember(spec) {
mutableStateOf(null)
}
LaunchedEffect(spec) {
val animation = when (spec) {
is SkiaCompositionSpec.File -> {
Animation.makeFromData(
Data.makeFromBytes(
Res.readBytes(spec.path)
)
)
}
is SkiaCompositionSpec.Url -> {
val httpClient = HttpClient()
val data = httpClient.get(spec.url)
Animation.makeFromData(
Data.makeFromBytes(data.bodyAsText().encodeToByteArray())
)
}
is SkiaCompositionSpec.JsonString -> {
Animation.makeFromString(spec.jsonString)
}
}
animationState = animation
}
return animationState
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy