From 6f094ed4a66824e66793b8cb7969237f754ec4bf Mon Sep 17 00:00:00 2001 From: Ryo Takeuchi Date: Tue, 5 Dec 2023 18:03:10 +0900 Subject: [PATCH] =?UTF-8?q?:wrench:=20Compose=20ImageLoader=20=E3=81=AB?= =?UTF-8?q?=E4=B9=97=E3=82=8A=E6=8F=9B=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/designsystem/build.gradle.kts | 1 + core/ui/build.gradle.kts | 5 ---- .../club/nito/core/ui/ProfileImage.android.kt | 29 ------------------- .../kotlin/club/nito/core/ui/ProfileImage.kt | 18 ++++++++++-- .../iosMain/kotlin/club/nito/core/ui/.gitkeep | 0 .../club/nito/core/ui/ProfileImage.ios.kt | 15 ---------- .../jsMain/kotlin/club/nito/core/ui/.gitkeep | 0 .../club/nito/core/ui/ProfileImage.js.kt | 9 ------ gradle/libs.versions.toml | 3 +- 9 files changed, 19 insertions(+), 61 deletions(-) delete mode 100644 core/ui/src/androidMain/kotlin/club/nito/core/ui/ProfileImage.android.kt create mode 100644 core/ui/src/iosMain/kotlin/club/nito/core/ui/.gitkeep delete mode 100644 core/ui/src/iosMain/kotlin/club/nito/core/ui/ProfileImage.ios.kt create mode 100644 core/ui/src/jsMain/kotlin/club/nito/core/ui/.gitkeep delete mode 100644 core/ui/src/jsMain/kotlin/club/nito/core/ui/ProfileImage.js.kt diff --git a/core/designsystem/build.gradle.kts b/core/designsystem/build.gradle.kts index 10b1dd07..24960bc1 100644 --- a/core/designsystem/build.gradle.kts +++ b/core/designsystem/build.gradle.kts @@ -19,6 +19,7 @@ kotlin { sourceSets { commonMain { dependencies { + api(libs.imageLoader) } } } diff --git a/core/ui/build.gradle.kts b/core/ui/build.gradle.kts index 6d4fca16..2b9dd2c6 100644 --- a/core/ui/build.gradle.kts +++ b/core/ui/build.gradle.kts @@ -31,10 +31,5 @@ kotlin { implementation(libs.kermit) } } - androidMain { - dependencies { - implementation(libs.composeCoil) - } - } } } diff --git a/core/ui/src/androidMain/kotlin/club/nito/core/ui/ProfileImage.android.kt b/core/ui/src/androidMain/kotlin/club/nito/core/ui/ProfileImage.android.kt deleted file mode 100644 index fc542f9c..00000000 --- a/core/ui/src/androidMain/kotlin/club/nito/core/ui/ProfileImage.android.kt +++ /dev/null @@ -1,29 +0,0 @@ -package club.nito.core.ui - -import androidx.compose.foundation.shape.CircleShape -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip -import androidx.compose.ui.layout.ContentScale -import androidx.compose.ui.platform.LocalContext -import club.nito.core.model.UserProfile -import coil.compose.AsyncImage -import coil.request.ImageRequest - -@Composable -public actual fun ProfileImage( - profile: UserProfile, - modifier: Modifier, -) { - val context = LocalContext.current - - AsyncImage( - model = ImageRequest.Builder(context) - .data(profile.avatarUrl) - .crossfade(true) - .build(), - contentDescription = profile.displayName, - contentScale = ContentScale.Crop, - modifier = modifier.clip(CircleShape), - ) -} diff --git a/core/ui/src/commonMain/kotlin/club/nito/core/ui/ProfileImage.kt b/core/ui/src/commonMain/kotlin/club/nito/core/ui/ProfileImage.kt index 743a2203..ff6e69d2 100644 --- a/core/ui/src/commonMain/kotlin/club/nito/core/ui/ProfileImage.kt +++ b/core/ui/src/commonMain/kotlin/club/nito/core/ui/ProfileImage.kt @@ -1,11 +1,25 @@ package club.nito.core.ui +import androidx.compose.foundation.Image +import androidx.compose.foundation.shape.CircleShape import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.layout.ContentScale import club.nito.core.model.UserProfile +import com.seiko.imageloader.rememberImagePainter @Composable -public expect fun ProfileImage( +public fun ProfileImage( profile: UserProfile, modifier: Modifier = Modifier, -) +) { + Image( + painter = rememberImagePainter( + url = profile.avatarUrl, + ), + contentDescription = profile.displayName, + contentScale = ContentScale.Crop, + modifier = modifier.clip(CircleShape), + ) +} diff --git a/core/ui/src/iosMain/kotlin/club/nito/core/ui/.gitkeep b/core/ui/src/iosMain/kotlin/club/nito/core/ui/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/core/ui/src/iosMain/kotlin/club/nito/core/ui/ProfileImage.ios.kt b/core/ui/src/iosMain/kotlin/club/nito/core/ui/ProfileImage.ios.kt deleted file mode 100644 index 70f38d6e..00000000 --- a/core/ui/src/iosMain/kotlin/club/nito/core/ui/ProfileImage.ios.kt +++ /dev/null @@ -1,15 +0,0 @@ -package club.nito.core.ui - -import androidx.compose.foundation.layout.Box -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import club.nito.core.model.UserProfile - -@Composable -public actual fun ProfileImage( - profile: UserProfile, - modifier: Modifier, -) { - // TODO - Box { } -} diff --git a/core/ui/src/jsMain/kotlin/club/nito/core/ui/.gitkeep b/core/ui/src/jsMain/kotlin/club/nito/core/ui/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/core/ui/src/jsMain/kotlin/club/nito/core/ui/ProfileImage.js.kt b/core/ui/src/jsMain/kotlin/club/nito/core/ui/ProfileImage.js.kt deleted file mode 100644 index d4616477..00000000 --- a/core/ui/src/jsMain/kotlin/club/nito/core/ui/ProfileImage.js.kt +++ /dev/null @@ -1,9 +0,0 @@ -package club.nito.core.ui - -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import club.nito.core.model.UserProfile - -@Composable -public actual fun ProfileImage(profile: UserProfile, modifier: Modifier) { -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 20cc7b9a..27a702cc 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -31,6 +31,7 @@ logback = "1.4.14" graphqlKotlin = "7.0.2" kotest = "5.8.0" precompose = "1.5.8" +imageLoader = "1.7.1" [libraries] androidGradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" } @@ -60,7 +61,7 @@ kotlinxCollectionsImmutable = { module = "org.jetbrains.kotlinx:kotlinx-collecti kotlinxDatetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version = "0.5.0" } kotlinxAtomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version = "0.23.1" } -composeCoil = { module = "io.coil-kt:coil-compose", version = "2.5.0" } +imageLoader = { module = "io.github.qdsfdhvh:image-loader", version.ref = "imageLoader" } androidxActivityActivityCompose = { module = "androidx.activity:activity-compose", version.ref = "androidxActivity" } androidxDatastoreDatastorePreferences = { module = "androidx.datastore:datastore-preferences-core", version = "1.1.0-alpha06" }