Skip to content

Commit 25ba84d

Browse files
authored
Merge pull request #172 from vitorpamplona/update-coil
Updates Coil 3.0
2 parents 7f70e0a + 2ce9ae0 commit 25ba84d

File tree

12 files changed

+96
-56
lines changed

12 files changed

+96
-56
lines changed

.github/workflows/android.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@v2
1313
- uses: gradle/wrapper-validation-action@v1
14-
- name: set up JDK 17
14+
- name: set up JDK 21
1515
uses: actions/setup-java@v1
1616
with:
17-
java-version: 17
17+
java-version: 21
1818
- uses: actions/cache@v4
1919
with:
2020
path: ~/.gradle/caches

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- uses: actions/checkout@v2
1717
- uses: actions/setup-java@v1
1818
with:
19-
java-version: 17
19+
java-version: 21
2020
- uses: actions/setup-python@v2
2121
with:
2222
python-version: 3.x

android-sample/build.gradle.kts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
13
plugins {
24
id("com.android.application")
35
kotlin("android")
@@ -22,8 +24,11 @@ android {
2224
sourceCompatibility = JavaVersion.VERSION_11
2325
targetCompatibility = JavaVersion.VERSION_11
2426
}
25-
kotlinOptions {
26-
jvmTarget = "11"
27+
}
28+
29+
kotlin {
30+
compilerOptions {
31+
jvmTarget = JvmTarget.JVM_11
2732
}
2833
}
2934

buildSrc/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ plugins {
1010

1111
dependencies {
1212
// keep in sync with Dependencies.BuildPlugins.androidGradlePlugin
13-
implementation("com.android.tools.build:gradle:8.7.0")
13+
implementation("com.android.tools.build:gradle:8.13.0")
1414
// keep in sync with Dependencies.Kotlin.gradlePlugin
15-
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21")
15+
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.20")
1616
implementation(kotlin("script-runtime"))
1717
}

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
object BuildPlugins {
22
// keep in sync with buildSrc/build.gradle.kts
3-
val androidGradlePlugin = "com.android.tools.build:gradle:8.7.0"
3+
val androidGradlePlugin = "com.android.tools.build:gradle:8.13.0"
44
}
55

66
object AndroidX {
7-
val appcompat = "androidx.appcompat:appcompat:1.3.0"
7+
val appcompat = "androidx.appcompat:appcompat:1.7.1"
88
}
99

1010
object Network {
@@ -13,7 +13,7 @@ object Network {
1313

1414
object Kotlin {
1515
// keep in sync with buildSrc/build.gradle.kts
16-
val version = "2.0.21"
16+
val version = "2.2.20"
1717
val binaryCompatibilityValidatorPlugin = "org.jetbrains.kotlinx:binary-compatibility-validator:0.9.0"
1818
val gradlePlugin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$version"
1919

@@ -30,11 +30,12 @@ object Compose {
3030
val desktopVersion = "1.8.2"
3131
val activity = "androidx.activity:activity-compose:1.8.2"
3232
val toolingData = "androidx.compose.ui:ui-tooling-data:1.6.0"
33-
val coil = "io.coil-kt:coil-compose:2.5.0"
33+
val coil = "io.coil-kt.coil3:coil-compose:3.3.0"
34+
val coilHttp = "io.coil-kt.coil3:coil-network-okhttp:3.3.0"
3435
}
3536

3637
object Commonmark {
37-
private val version = "0.25.0"
38+
private val version = "0.26.0"
3839
val core = "org.commonmark:commonmark:$version"
3940
val tables = "org.commonmark:commonmark-ext-gfm-tables:$version"
4041
val strikethrough = "org.commonmark:commonmark-ext-gfm-strikethrough:$version"
@@ -43,6 +44,6 @@ object Commonmark {
4344

4445
object AndroidConfiguration {
4546
val minSdk = 23
46-
val targetSdk = 35
47+
val targetSdk = 36
4748
val compileSdk = targetSdk
4849
}

buildSrc/src/main/kotlin/richtext-android-library.gradle.kts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2+
13
plugins {
24
id("com.android.library")
35
kotlin("android")
46
}
57

68
kotlin {
79
explicitApi()
10+
compilerOptions {
11+
jvmTarget = JvmTarget.JVM_11
12+
}
813
}
914

1015
android {
@@ -19,9 +24,6 @@ android {
1924
sourceCompatibility = JavaVersion.VERSION_11
2025
targetCompatibility = JavaVersion.VERSION_11
2126
}
22-
kotlinOptions {
23-
jvmTarget = "11"
24-
}
2527

2628
buildFeatures {
2729
compose = true

buildSrc/src/main/kotlin/richtext-kmp-library.gradle.kts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import AndroidConfiguration.compileSdk
2+
import AndroidConfiguration.minSdk
3+
import AndroidConfiguration.targetSdk
4+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
5+
16
plugins {
27
id("com.android.library")
38
kotlin("multiplatform")
@@ -14,8 +19,8 @@ kotlin {
1419
jvm()
1520
androidTarget {
1621
publishLibraryVariants("release")
17-
compilations.all {
18-
kotlinOptions.jvmTarget = "11"
22+
compilerOptions {
23+
jvmTarget.set(JvmTarget.JVM_11)
1924
}
2025
}
2126
explicitApi()

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

richtext-markdown/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ kotlin {
2727
val androidMain by getting {
2828
dependencies {
2929
implementation(Compose.coil)
30+
implementation(Compose.coilHttp)
3031
}
3132
}
3233

richtext-markdown/src/androidMain/kotlin/com/halilibo/richtext/markdown/MarkdownImage.kt

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@ import android.annotation.SuppressLint
44
import android.util.Base64
55
import androidx.compose.foundation.Image
66
import androidx.compose.foundation.layout.BoxWithConstraints
7+
import androidx.compose.foundation.layout.BoxWithConstraintsScope
78
import androidx.compose.foundation.layout.size
89
import androidx.compose.runtime.Composable
9-
import androidx.compose.runtime.derivedStateOf
10+
import androidx.compose.runtime.collectAsState
1011
import androidx.compose.runtime.getValue
11-
import androidx.compose.runtime.remember
1212
import androidx.compose.ui.Alignment
1313
import androidx.compose.ui.Modifier
1414
import androidx.compose.ui.geometry.isSpecified
1515
import androidx.compose.ui.layout.ContentScale
1616
import androidx.compose.ui.platform.LocalContext
1717
import androidx.compose.ui.platform.LocalDensity
1818
import androidx.compose.ui.unit.dp
19-
import coil.compose.rememberAsyncImagePainter
20-
import coil.request.ImageRequest
21-
import coil.size.Size
19+
import coil3.compose.rememberAsyncImagePainter
20+
import coil3.request.ImageRequest
21+
import coil3.request.crossfade
22+
import coil3.size.Size
2223

2324
private val DEFAULT_IMAGE_SIZE = 64.dp
2425

@@ -46,39 +47,10 @@ internal actual fun MarkdownImage(
4647
.build()
4748
)
4849

49-
val density = LocalDensity.current
50-
5150
@SuppressLint("UnusedBoxWithConstraintsScope")
5251
BoxWithConstraints(modifier, contentAlignment = Alignment.Center) {
53-
val sizeModifier by remember(density, painter) {
54-
derivedStateOf {
55-
val painterIntrinsicSize = painter.state.painter?.intrinsicSize
56-
if (painterIntrinsicSize != null &&
57-
painterIntrinsicSize.isSpecified &&
58-
painterIntrinsicSize.width != Float.POSITIVE_INFINITY &&
59-
painterIntrinsicSize.height != Float.POSITIVE_INFINITY
60-
) {
61-
val width = painterIntrinsicSize.width
62-
val height = painterIntrinsicSize.height
63-
val scale = if (width > constraints.maxWidth) {
64-
constraints.maxWidth.toFloat() / width
65-
} else {
66-
1f
67-
}
68-
69-
with(density) {
70-
Modifier.size(
71-
(width * scale).toDp(),
72-
(height * scale).toDp()
73-
)
74-
}
75-
} else {
76-
// if size is not defined at all, Coil fails to render the image
77-
// here, we give a default size for images until they are loaded.
78-
Modifier.size(DEFAULT_IMAGE_SIZE)
79-
}
80-
}
81-
}
52+
val painterState by painter.state.collectAsState()
53+
val sizeModifier = renderInSize(painterState.painter?.intrinsicSize)
8254

8355
Image(
8456
painter = painter,
@@ -88,3 +60,37 @@ internal actual fun MarkdownImage(
8860
)
8961
}
9062
}
63+
64+
@Composable
65+
public fun BoxWithConstraintsScope.renderInSize(
66+
painterIntrinsicSize: androidx.compose.ui.geometry.Size?,
67+
): Modifier {
68+
val density = LocalDensity.current
69+
70+
val sizeModifier = if (painterIntrinsicSize != null &&
71+
painterIntrinsicSize.isSpecified &&
72+
painterIntrinsicSize.width != Float.POSITIVE_INFINITY &&
73+
painterIntrinsicSize.height != Float.POSITIVE_INFINITY
74+
) {
75+
val width = painterIntrinsicSize.width
76+
val height = painterIntrinsicSize.height
77+
val scale = if (width > constraints.maxWidth) {
78+
constraints.maxWidth.toFloat() / width
79+
} else {
80+
1f
81+
}
82+
83+
with(density) {
84+
Modifier.size(
85+
(width * scale).toDp(),
86+
(height * scale).toDp()
87+
)
88+
}
89+
} else {
90+
// if size is not defined at all, Coil fails to render the image
91+
// here, we give a default size for images until they are loaded.
92+
Modifier.size(DEFAULT_IMAGE_SIZE)
93+
}
94+
95+
return sizeModifier
96+
}

0 commit comments

Comments
 (0)