Skip to content

Commit

Permalink
Use Ktor3 and support Wasm for coil3
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed Sep 12, 2024
1 parent db02480 commit 1adb9b0
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import android.content.Context
import androidx.multidex.MultiDexApplication
import coil3.ImageLoader
import coil3.SingletonImageLoader
import coil3.network.ktor2.KtorNetworkFetcherFactory
import coil3.network.ktor3.KtorNetworkFetcherFactory
import com.facebook.drawee.backends.pipeline.Fresco
import com.facebook.imagepipeline.backends.okhttp3.OkHttpImagePipelineConfigFactory
import com.facebook.imagepipeline.core.DownsampleMode
import dagger.hilt.android.HiltAndroidApp
import okhttp3.OkHttpClient

Expand All @@ -38,7 +39,7 @@ class App : MultiDexApplication(), SingletonImageLoader.Factory {
OkHttpImagePipelineConfigFactory
.newBuilder(this, OkHttpClient.Builder().build())
.setDiskCacheEnabled(true)
.setDownsampleEnabled(true)
.setDownsampleMode(DownsampleMode.AUTO)
.setResizeAndRotateEnabledForNetwork(true)
.build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import android.app.Application
import android.content.Context
import coil3.ImageLoader
import coil3.SingletonImageLoader
import coil3.network.ktor2.KtorNetworkFetcherFactory
import coil3.network.ktor3.KtorNetworkFetcherFactory
import com.facebook.drawee.backends.pipeline.Fresco
import com.facebook.imagepipeline.backends.okhttp3.OkHttpImagePipelineConfigFactory
import com.facebook.imagepipeline.core.DownsampleMode
Expand Down
4 changes: 4 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ gradlePlugin {
id = "landscapist.library.compose.multiplatform"
implementationClass = "ComposeMultiplatformLibraryConventionPlugin"
}
register("composeMultiplatformWasmLibrary") {
id = "landscapist.library.compose.multiplatformWasm"
implementationClass = "ComposeMultiplatformWasmLibraryConventionPlugin"
}
register("spotless") {
id = "landscapist.spotless"
implementationClass = "SpotlessConventionPlugin"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Designed and developed by 2020-2022 skydoves (Jaewoong Eum)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import com.android.build.gradle.LibraryExtension
import com.skydoves.landscapist.configureAndroidCompose
import com.skydoves.landscapist.configureComposeMultiplatform
import com.skydoves.landscapist.configureKotlinAndroid
import com.skydoves.landscapist.kotlinOptions
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

class ComposeMultiplatformWasmLibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
pluginManager.apply("com.android.library")
pluginManager.apply("org.jetbrains.kotlin.multiplatform")
pluginManager.apply("org.jetbrains.compose")
pluginManager.apply("com.vanniktech.maven.publish")
pluginManager.apply("binary-compatibility-validator")
pluginManager.apply("androidx.baselineprofile")

extensions.configure<LibraryExtension> libraryExtension@{
extensions.configure<KotlinMultiplatformExtension> kmpExtension@{
configureComposeMultiplatform(this@libraryExtension, this@kmpExtension)
}
}

val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
tasks.withType(JavaCompile::class.java).configureEach {
this.targetCompatibility = libs.findVersion("jvmTarget").get().toString()
this.sourceCompatibility = libs.findVersion("jvmTarget").get().toString()
}

dependencies {
add("baselineProfile", project(":benchmark-landscapist"))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,18 @@ internal fun Project.configureComposeMultiplatform(
androidTarget { publishLibraryVariants("release") }
jvm("desktop")

js {
browser()
nodejs()
binaries.executable()
binaries.library()
}
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
binaries.executable()
browser {
testTask {
enabled = false
}
}
nodejs {
testTask {
enabled = false
}
}
binaries.library()
}

Expand Down Expand Up @@ -78,7 +82,6 @@ internal fun Project.configureComposeMultiplatform(
}
}
withJs()
withWasmJs()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Designed and developed by 2020-2022 skydoves (Jaewoong Eum)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:Suppress("UnstableApiUsage")

package com.skydoves.landscapist

import com.android.build.api.dsl.CommonExtension
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.kotlin.dsl.invoke
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

/**
* Configure Compose-Multiplatform-specific options
*/
internal fun Project.configureComposeMultiplatformWasm(
commonExtension: CommonExtension<*, *, *, *, *, *>,
kotlinMultiplatformExtension: KotlinMultiplatformExtension,
) {
pluginManager.apply("org.jetbrains.kotlin.plugin.compose")

kotlinMultiplatformExtension.apply {
androidTarget { publishLibraryVariants("release") }
jvm("desktop")

@OptIn(ExperimentalWasmDsl::class)
wasmJs {
browser {
testTask {
enabled = false
}
}
nodejs {
testTask {
enabled = false
}
}
binaries.library()
}

iosX64()
iosArm64()
iosSimulatorArm64()

macosX64()
macosArm64()

@Suppress("OPT_IN_USAGE")
applyHierarchyTemplate {
common {
group("jvm") {
withAndroidTarget()
withJvm()
}
group("skia") {
withJvm()
group("darwin") {
group("apple") {
group("ios") {
withIosX64()
withIosArm64()
withIosSimulatorArm64()
}
group("macos") {
withMacosX64()
withMacosArm64()
}
}
withJs()
withWasmJs()
}
}
}
}

explicitApi()
}

commonExtension.apply {
buildFeatures {
compose = true
}

packaging {
resources {
excludes.add("/META-INF/{AL2.0,LGPL2.1}")
}
}
}
}
4 changes: 2 additions & 2 deletions coil3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.github.skydoves.landscapist.Configuration

plugins {
id("landscapist.library.compose.multiplatform")
id("landscapist.library.compose.multiplatformWasm")
id("landscapist.spotless")
}

Expand Down Expand Up @@ -47,7 +47,7 @@ kotlin {
dependencies {
api(project(":landscapist"))
api(libs.coil3)
api(libs.coil3.network.ktor2)
api(libs.coil3.network.ktor3)
api(libs.ktor.core)

implementation(compose.ui)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.staticCompositionLocalOf
import coil3.ImageLoader
import coil3.SingletonImageLoader
import coil3.network.ktor2.KtorNetworkFetcherFactory
import coil3.network.ktor3.KtorNetworkFetcherFactory

/**
* Local containing the preferred [ImageLoader] for providing the same instance
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ glide = "4.16.0"
fresco = "3.2.0"
coil = "2.7.0"
coil3 = "3.0.0-alpha10"
ktor = "2.3.12"
ktor = "3.0.0-rc-1"
palette = "3.1.0"
hilt = "2.52"
spotless = "6.21.0"
Expand Down
2 changes: 1 addition & 1 deletion landscapist-animation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.github.skydoves.landscapist.Configuration

plugins {
id("landscapist.library.compose.multiplatform")
id("landscapist.library.compose.multiplatformWasm")
id("landscapist.spotless")
}

Expand Down
2 changes: 1 addition & 1 deletion landscapist-placeholder/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.github.skydoves.landscapist.Configuration

plugins {
id("landscapist.library.compose.multiplatform")
id("landscapist.library.compose.multiplatformWasm")
id("landscapist.spotless")
}

Expand Down
2 changes: 1 addition & 1 deletion landscapist/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.github.skydoves.landscapist.Configuration

plugins {
id("landscapist.library.compose.multiplatform")
id("landscapist.library.compose.multiplatformWasm")
id("landscapist.spotless")
}

Expand Down

0 comments on commit 1adb9b0

Please sign in to comment.