Skip to content

Commit 036605b

Browse files
committed
Migrate coil to coil3
1 parent bb53285 commit 036605b

File tree

11 files changed

+63
-43
lines changed

11 files changed

+63
-43
lines changed

app/build.gradle.kts

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ android {
3535
}
3636

3737
dependencies {
38-
implementation(libs.bundles.ui.compose)
38+
implementation(platform(libs.compose.bom))
39+
implementation(libs.bundles.compose.bom)
3940
implementation(libs.androidx.appcompat)
4041
implementation(project(":jchucomponents-core"))
4142
implementation(project(":jchucomponents-ui"))

gradle/libs.versions.toml

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
[versions]
2-
jchucomponents = "2.0.0-alpha18"
2+
jchucomponents = "2.0.0-beta01"
33
agp = "8.5.2"
44
kotlin = "2.1.10"
55
dokka = "1.9.20"
66
androidx-activity = "1.10.0"
7-
androidx-compose = "1.7.7"
87
androidx-lifecycle = "2.8.7"
98
androidx-navigation = "2.8.6"
109
com-squareup-okhttp3 = "4.12.0"
1110
com-squareup-retrofit2 = "2.11.0"
12-
coil-kt = "2.7.0"
11+
coil-kt = "3.1.0"
1312
org-jetbrains-kotlin = "2.1.10"
1413
org-jetbrains-kotlinx = "1.10.1"
14+
composeBom = "2025.01.01"
1515

1616
[libraries]
1717
androidx-datastore = "androidx.datastore:datastore-preferences:1.1.2"
1818
androidx-activity-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" }
1919
androidx-browser = "androidx.browser:browser:1.8.0"
20-
androidx-compose-animation = { module = "androidx.compose.animation:animation", version.ref = "androidx-compose" }
21-
androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "androidx-compose" }
22-
androidx-compose-foundation-foundation-layout = { module = "androidx.compose.foundation:foundation-layout", version.ref = "androidx-compose" }
23-
androidx-compose-material = { module = "androidx.compose.material:material", version.ref = "androidx-compose" }
24-
androidx-compose-material-material-icons-extended = { module = "androidx.compose.material:material-icons-extended", version.ref = "androidx-compose" }
20+
androidx-compose-animation = { module = "androidx.compose.animation:animation" }
21+
androidx-compose-foundation = { module = "androidx.compose.foundation:foundation" }
22+
androidx-compose-foundation-foundation-layout = { module = "androidx.compose.foundation:foundation-layout" }
23+
androidx-compose-material = { module = "androidx.compose.material:material" }
24+
androidx-compose-material-material-icons-extended = { module = "androidx.compose.material:material-icons-extended" }
2525
androidx-compose-material3 = "androidx.compose.material3:material3:1.3.1"
26-
androidx-compose-runtime = { module = "androidx.compose.runtime:runtime", version.ref = "androidx-compose" }
27-
androidx-compose-ui = { module = "androidx.compose.ui:ui", version.ref = "androidx-compose" }
28-
androidx-compose-ui-ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "androidx-compose" }
29-
androidx-compose-ui-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "androidx-compose" }
26+
androidx-compose-runtime = { module = "androidx.compose.runtime:runtime" }
27+
androidx-compose-ui = { module = "androidx.compose.ui:ui" }
28+
androidx-compose-ui-ui-tooling = { module = "androidx.compose.ui:ui-tooling" }
29+
androidx-compose-ui-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview" }
3030
androidx-core-core-ktx = "androidx.core:core-ktx:1.15.0"
3131
androidx-core-core-splashscreen = "androidx.core:core-splashscreen:1.0.1"
3232
androidx-lifecycle-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidx-lifecycle" }
@@ -40,11 +40,12 @@ com-squareup-okhttp3-logging-interceptor = { module = "com.squareup.okhttp3:logg
4040
com-squareup-okhttp3-okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "com-squareup-okhttp3" }
4141
com-squareup-retrofit2-converter-gson = { module = "com.squareup.retrofit2:converter-gson", version.ref = "com-squareup-retrofit2" }
4242
com-squareup-retrofit2-retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "com-squareup-retrofit2" }
43-
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil-kt" }
43+
coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil-kt" }
4444
org-jetbrains-kotlinx-kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "org-jetbrains-kotlinx" }
4545
org-jetbrains-kotlinx-kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "org-jetbrains-kotlinx" }
4646
androidx-appcompat = "androidx.appcompat:appcompat:1.7.0"
4747
revenuecat = "com.revenuecat.purchases:purchases:8.10.4"
48+
compose-bom = { group = "androidx.compose", name ="compose-bom", version.ref = "composeBom" }
4849

4950
[plugins]
5051
android-application = { id = "com.android.application", version.ref = "agp" }
@@ -89,7 +90,7 @@ qr-third-party = [
8990
ui-androidx = [
9091
"androidx-core-core-splashscreen",
9192
]
92-
ui-compose = [
93+
compose-bom = [
9394
"androidx-activity-activity-compose",
9495
"androidx-compose-animation",
9596
"androidx-compose-foundation",

jchucomponents-prefs/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ android {
4949
dependencies {
5050
implementation(libs.bundles.preferences.androidx)
5151
implementation(libs.bundles.preferences.google)
52+
implementation(platform(libs.compose.bom))
5253
implementation(libs.bundles.preferences.compose)
5354
}
5455

jchucomponents-ui/build.gradle.kts

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ android {
4848
}
4949

5050
dependencies {
51-
implementation(libs.bundles.ui.compose)
51+
implementation(platform(libs.compose.bom))
52+
implementation(libs.bundles.compose.bom)
5253
implementation(libs.bundles.ui.androidx)
5354
implementation(project(":jchucomponents-ktx"))
5455
debugImplementation(libs.androidx.compose.ui.ui.tooling.preview)

jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/cards/BenefitsCard.kt

+7-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ fun BenefitsCard(
6666
}
6767

6868
Column(
69-
modifier = Modifier.weight(1f)
69+
modifier = Modifier.weight(1f),
70+
horizontalAlignment = Alignment.Start,
71+
verticalArrangement = Arrangement.spacedBy(5.dp)
7072
) {
7173
Row(
7274
verticalAlignment = Alignment.CenterVertically,
@@ -81,14 +83,15 @@ fun BenefitsCard(
8183

8284
if (benefitsDefaults.isNew) {
8385
Surface(
84-
shape = 5.cornerRadius(),
86+
shape = 7.cornerRadius(),
8587
color = benefitsDefaults.colors.badgeContainerColor
8688
) {
8789
Text(
8890
text = "New",
8991
fontSize = 16.sp,
9092
modifier = Modifier.padding(
91-
horizontal = 5.dp
93+
vertical = 3.dp,
94+
horizontal = 9.dp
9295
),
9396
fontWeight = FontWeight.ExtraBold,
9497
color = benefitsDefaults.colors.badgeContentColor
@@ -101,6 +104,7 @@ fun BenefitsCard(
101104
description?.let { description ->
102105
Text(
103106
fontSize = 12.sp,
107+
lineHeight = 17.sp,
104108
text = description,
105109
color = benefitsDefaults.colors.contentColor.copy(.7f),
106110
)

jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/images/BlurImage.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import androidx.compose.ui.Modifier
66
import androidx.compose.ui.graphics.DefaultAlpha
77
import androidx.compose.ui.layout.ContentScale
88
import androidx.compose.ui.platform.LocalContext
9-
import coil.compose.AsyncImage
10-
import coil.request.ImageRequest
9+
import coil3.compose.AsyncImage
10+
import coil3.request.ImageRequest
11+
import coil3.request.allowHardware
12+
import coil3.request.crossfade
13+
import coil3.request.transformations
1114
import com.jeluchu.jchucomponents.ui.composables.images.transformations.BlurTransformation
1215

1316
@Composable

jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/images/CoilExtensions.kt

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.jeluchu.jchucomponents.ui.composables.images
22

3+
import android.annotation.SuppressLint
34
import androidx.compose.runtime.Composable
45
import androidx.compose.ui.graphics.painter.Painter
56
import androidx.compose.ui.platform.LocalContext
6-
import coil.compose.rememberAsyncImagePainter
7-
import coil.request.ImageRequest
8-
import coil.size.Size
7+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
8+
import coil3.compose.rememberAsyncImagePainter
9+
import coil3.request.ImageRequest
10+
import coil3.size.Size
11+
import kotlinx.coroutines.flow.collect
912

1013
@Composable
1114
fun String.remotetoPaiter(): Painter? =
@@ -16,8 +19,11 @@ fun String.remotetoPaiter(): Painter? =
1619
.build()
1720
)
1821
.state
22+
.collectAsStateWithLifecycle()
23+
.value
1924
.painter
2025

26+
@SuppressLint("StateFlowValueCalledInComposition")
2127
@Composable
2228
fun CharSequence.remotetoPaiter(): Painter? =
2329
rememberAsyncImagePainter(
@@ -27,4 +33,6 @@ fun CharSequence.remotetoPaiter(): Painter? =
2733
.build()
2834
)
2935
.state
36+
.collectAsStateWithLifecycle()
37+
.value
3038
.painter

jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/images/NetworkImage.kt

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ import androidx.compose.ui.Modifier
1313
import androidx.compose.ui.graphics.DefaultAlpha
1414
import androidx.compose.ui.layout.ContentScale
1515
import androidx.compose.ui.platform.LocalContext
16-
import coil.compose.AsyncImage
17-
import coil.request.ImageRequest
18-
import coil.transform.Transformation
16+
import coil3.compose.AsyncImage
17+
import coil3.request.ImageRequest
18+
import coil3.request.allowHardware
19+
import coil3.request.crossfade
20+
import coil3.request.transformations
21+
import coil3.transform.Transformation
1922
import com.jeluchu.jchucomponents.ui.extensions.toPainter
2023
import com.jeluchu.jchucomponents.ui.R
2124

@@ -59,7 +62,6 @@ fun NetworkImage(
5962
.transformations(transformations)
6063
.crossfade(isCrossfade)
6164
.allowHardware(isAllowHardware)
62-
.error(error)
6365
.build(),
6466
alpha = alpha,
6567
placeholder = loading.toPainter(),

jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/composables/images/transformations/BlurTransformation.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.jeluchu.jchucomponents.ui.composables.images.transformations
22

33
import android.graphics.Bitmap
4-
import coil.size.Size
5-
import coil.transform.Transformation
4+
import coil3.size.Size
5+
import coil3.transform.Transformation
66
import kotlinx.coroutines.Dispatchers
77
import kotlinx.coroutines.withContext
88
import kotlin.math.abs
@@ -11,7 +11,7 @@ import kotlin.math.roundToInt
1111
class BlurTransformation(
1212
private val radius: Int = 25,
1313
private val scale: Float = 0.5f
14-
) : Transformation {
14+
) : Transformation() {
1515

1616
override val cacheKey: String = "${javaClass.name}-$radius"
1717

jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/dragndrop/ReorderableItem.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import androidx.compose.ui.unit.IntOffset
2323
import androidx.compose.ui.zIndex
2424
import com.jeluchu.jchucomponents.ui.dragndrop.states.ReorderableState
2525

26-
@OptIn(ExperimentalFoundationApi::class)
2726
@Composable
2827
fun LazyItemScope.ReorderableItem(
2928
reorderableState: ReorderableState<*>,
@@ -36,13 +35,12 @@ fun LazyItemScope.ReorderableItem(
3635
state = reorderableState,
3736
key = key,
3837
modifier = modifier,
39-
defaultDraggingModifier = Modifier.animateItemPlacement(),
38+
defaultDraggingModifier = Modifier.animateItem(),
4039
orientationLocked = orientationLocked,
4140
index = index,
4241
content = content
4342
)
4443

45-
@OptIn(ExperimentalFoundationApi::class)
4644
@Composable
4745
fun LazyGridItemScope.ReorderableItem(
4846
reorderableState: ReorderableState<*>,
@@ -54,7 +52,7 @@ fun LazyGridItemScope.ReorderableItem(
5452
state = reorderableState,
5553
key = key,
5654
modifier = modifier,
57-
defaultDraggingModifier = Modifier.animateItemPlacement(),
55+
defaultDraggingModifier = Modifier.animateItem(),
5856
orientationLocked = false,
5957
index = index,
6058
content = content

jchucomponents-ui/src/main/kotlin/com/jeluchu/jchucomponents/ui/extensions/coil/ImageExtensions.kt

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ package com.jeluchu.jchucomponents.ui.extensions.coil
22

33
import android.content.Context
44
import android.graphics.Bitmap
5-
import androidx.core.graphics.drawable.toBitmapOrNull
6-
import coil.imageLoader
7-
import coil.request.CachePolicy
8-
import coil.request.ErrorResult
9-
import coil.request.ImageRequest
10-
import coil.request.SuccessResult
5+
import coil3.imageLoader
6+
import coil3.request.CachePolicy
7+
import coil3.request.ErrorResult
8+
import coil3.request.ImageRequest
9+
import coil3.request.SuccessResult
10+
import coil3.request.allowHardware
11+
import coil3.toBitmap
1112

1213
suspend fun Context.getImageToBitmap(
1314
url: String,
1415
force: Boolean = false,
1516
isHardware: Boolean = false
16-
): Bitmap? {
17+
): Bitmap {
1718
val request = ImageRequest.Builder(this).data(url).apply {
1819
if (force) {
1920
memoryCachePolicy(CachePolicy.DISABLED)
@@ -24,6 +25,6 @@ suspend fun Context.getImageToBitmap(
2425

2526
return when (val result = imageLoader.execute(request)) {
2627
is ErrorResult -> throw result.throwable
27-
is SuccessResult -> result.drawable.toBitmapOrNull()
28+
is SuccessResult -> result.image.toBitmap()
2829
}
2930
}

0 commit comments

Comments
 (0)