Skip to content

Commit

Permalink
ktor3 by default
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzhirkevich committed Sep 17, 2024
1 parent 9955b40 commit 42b1c05
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 474 deletions.
34 changes: 8 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ Compose Multiplatform Adobe After Effects Bodymovin (Lottie) animations renderin
> <br>Please [report](https://github.com/alexzhirkevich/compottie/issues) if you find any, preferably with a reproducible animation.
> <br>List of supported AE Lottie features can be found [here](/supported_features.md)
| Module | Description |
| :----: | ------------- |
| `compottie` | Main module with rendering engine and `JsonString` animation spec. Currently has two branches - 1.x (with platform renderers - Skottie and lottie-android) and 2.x (with own renderer). 1.x is maintained until the new renderer becomes stable |
| `compottie⁠-⁠dot` | Contains [dotLottie](https://dotlottie.io/) and ZIP animation spec. For Compottie 2.x only |
| `compottie⁠-⁠network` | Contains `Url` animation spec and asset/font managers (with [Ktor](https://ktor.io/) and local cache with [Okio](https://square.github.io/okio/)). Allows loading animations and assets from web. For Compottie 2.x only |
| `compottie⁠-⁠resources` | Contains asset and font managers powered by official Compose resources. For Compottie 2.x only |
| Module | Description |
|:--------------------------:|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `compottie` | Main module with rendering engine and `JsonString` animation spec. Currently has two branches - 1.x (with platform renderers - Skottie and lottie-android) and 2.x (with own renderer). 1.x is maintained until the new renderer becomes stable |
| `compottie⁠-⁠dot` | Contains [dotLottie](https://dotlottie.io/) and ZIP animation spec. For Compottie 2.x only |
| `compottie⁠-⁠network` | Contains `Url` animation spec and asset/font managers (with [Ktor3](https://ktor.io/) and local cache with [Okio](https://square.github.io/okio/)). Allows loading animations and assets from web. For Compottie 2.x only |
| `compottie⁠-⁠network-core` | Contains base HttpClient-free implementations for `network` module. Allows to specify custom HTTP client (Ktor3 or any other). |
| `compottie⁠-⁠resources` | Contains asset and font managers powered by official Compose resources. For Compottie 2.x only |

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.alexzhirkevich/compottie/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.alexzhirkevich/compottie)

Expand Down Expand Up @@ -234,7 +235,7 @@ Images should be avoided whenever possible. They are much larger, less performan
val painter = rememberLottiePainter(
composition = composition,
assetsManager = rememberResourcesAssetsManager(
directory = "files" // by default,
directory = "files", // by default
readBytes = Res::readBytes
)
)
Expand Down Expand Up @@ -285,22 +286,6 @@ The network module also brings the `NetworkAssetsManager` that have similar para
If you are using Url composition spec then specifying `NetworkAssetsManager` is redundant.
Url composition spec automatically prepares url assets

There is no stable Ktor client for wasm so to use network module on this target you need to add
the following to the bottom of your build script:

```kotlin
configurations
.filter { it.name.contains("wasmJs") }
.onEach {
it.resolutionStrategy.eachDependency {
if (requested.group.startsWith("io.ktor") &&
requested.name.startsWith("ktor-client-")
) {
useVersion("3.0.0-wasm2")
}
}
}
```
## Dynamic Properties

Lottie allows you to update animation properties at runtime. Some reasons you may want to do this are:
Expand Down Expand Up @@ -346,9 +331,6 @@ val painter = rememberLottiePainter(

// for each layer named 'Shape Layer 4' on any level deep
shapeLayer("**", "Shape Layer 4") {
transform {
rotation { current -> current * progress }
}
// for each fill named 'Fill 4' on the 2nd level deep
fill("*", "Fill 4") {
color { Color.Red }
Expand Down
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ plugins {
alias(libs.plugins.android.library) apply false
alias(libs.plugins.compose).apply(false)
alias(libs.plugins.composeCompiler).apply(false)
alias(libs.plugins.dokka).apply(false)
alias(libs.plugins.serialization).apply(false)
}

Expand Down
1 change: 0 additions & 1 deletion compottie-network/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
id("kotlinx-atomicfu")
id("ktorwasm.workaround")
}

kotlin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package io.github.alexzhirkevich.compottie
import io.ktor.client.HttpClient
import io.ktor.client.plugins.HttpRequestRetry
import io.ktor.client.request.get
import io.ktor.client.statement.bodyAsBytes
import io.ktor.client.statement.bodyAsChannel
import io.ktor.util.toByteArray
import io.ktor.utils.io.InternalAPI
import io.ktor.utils.io.toByteArray

internal val DefaultHttpClient by lazy {
HttpClient {
Expand All @@ -17,6 +19,7 @@ internal val DefaultHttpClient by lazy {
}
}

@OptIn(InternalAPI::class)
internal val DefaultHttpRequest : suspend (String) -> ByteArray = {
DefaultHttpClient.get(it).bodyAsChannel().toByteArray()
DefaultHttpClient.get(it).bodyAsBytes()
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ configurations
if (requested.group.startsWith("io.ktor") &&
requested.name.startsWith("ktor-client-")
) {
useVersion("3.0.0-wasm2")
useVersion("3.0.0-rc-1")
}
}
}
1 change: 0 additions & 1 deletion example/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
plugins {
id("module.android")
id("module.multiplatform")
id("ktorwasm.workaround")
alias(libs.plugins.serialization)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lottiefiles

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import io.github.alexzhirkevich.compottie.Compottie
import io.github.alexzhirkevich.compottie.InternalCompottieApi
import io.github.alexzhirkevich.compottie.ioDispatcher
import io.ktor.client.HttpClient
Expand Down Expand Up @@ -64,7 +65,7 @@ internal class LottieFilesViewModel() : ViewModel() {

init {
@OptIn(InternalCompottieApi::class)
viewModelScope.launch(ioDispatcher()) {
viewModelScope.launch(Compottie.ioDispatcher()) {
combine(search.debounce(1000), sortOrder, page) { q, s, p ->
Triple(q, s, p)
}.collectLatest { (q, s, p) ->
Expand Down Expand Up @@ -99,7 +100,7 @@ internal class LottieFilesViewModel() : ViewModel() {
}

@OptIn(InternalCompottieApi::class)
viewModelScope.launch(ioDispatcher()) {
viewModelScope.launch(Compottie.ioDispatcher()) {
search.debounce(1000)
.collectLatest { s ->
if (s.isBlank()){
Expand Down
1 change: 0 additions & 1 deletion example/webApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ kotlin {
}
}

plugins.apply("ktorwasm.workaround")

/**
./gradlew clean compatBrowserProductionDistribution
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Gradle
org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M"
org.gradle.jvmargs=-Xmx4096M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx4096M"

#Kotlin
kotlin.code.style=official
Expand Down
12 changes: 5 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
androidx-activity-compose="1.9.0"
androidx-core-ktx="1.13.1"
androidx-startup="1.1.1"
kotlin="2.0.0"
dokka="1.9.0"
kotlin="2.0.20"
compose="1.6.11"
agp = "8.1.1"
okio = "3.9.0"
serialization="1.6.3"
ktor="2.3.12"
serialization="1.7.2"
ktor="3.0.0-rc-1"
atomicfu="0.23.2"
coroutines="1.8.1"
nexus-publish="2.0.0"
coil="3.0.0-alpha08"
coil="3.0.0-alpha10"

[libraries]
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity-compose" }
Expand All @@ -31,13 +30,12 @@ nexus-publish = { module = "io.github.gradle-nexus.publish-plugin:io.github.grad
kotlin-gp = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
android-gp = { module = "com.android.tools.build:gradle", version.ref = "agp" }
coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil" }
coil-network = { module = "io.coil-kt.coil3:coil-network-ktor", version.ref = "coil" }
coil-network = { module = "io.coil-kt.coil3:coil-network-ktor3", version.ref = "coil" }

[plugins]
compose = { id = "org.jetbrains.compose", version.ref = "compose" }
kotlin-multiplatform = { id ="org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
android-application = { id = "com.android.application", version.ref = "agp" }
android-library = { id = "com.android.library", version.ref = "agp" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }
serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
composeCompiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
Loading

0 comments on commit 42b1c05

Please sign in to comment.