From 312fd5f90f59cf257e7a6bc9675cb15067c36853 Mon Sep 17 00:00:00 2001 From: Ash Davies <1892070+ashdavies@users.noreply.github.com> Date: Sat, 17 Feb 2024 19:13:04 +0100 Subject: [PATCH] Apply runtime configurations with type checking for images --- .../io/ashdavies/playground/LauncherScreen.kt | 17 +++++++++++++---- app-launcher/desktop/build.gradle.kts | 6 ++++++ gradle/libs.versions.toml | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app-launcher/common/src/commonMain/kotlin/io/ashdavies/playground/LauncherScreen.kt b/app-launcher/common/src/commonMain/kotlin/io/ashdavies/playground/LauncherScreen.kt index a38814b4c..18786dcc3 100644 --- a/app-launcher/common/src/commonMain/kotlin/io/ashdavies/playground/LauncherScreen.kt +++ b/app-launcher/common/src/commonMain/kotlin/io/ashdavies/playground/LauncherScreen.kt @@ -22,9 +22,12 @@ import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.ImageBitmap +import androidx.compose.ui.graphics.painter.BitmapPainter import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.unit.dp import coil3.compose.rememberAsyncImagePainter @@ -103,10 +106,16 @@ private fun LauncherItem( ) { Card(modifier = modifier.clickable(onClick = onClick)) { Column { - val imagePainter = rememberAsyncImagePainter( - model = item.imageModel, - contentScale = ContentScale.Crop, - ) + val imagePainter = when (val imageModel = item.imageModel) { + is ImageBitmap -> remember(imageModel) { + BitmapPainter(imageModel) + } + + else -> rememberAsyncImagePainter( + model = item.imageModel, + contentScale = ContentScale.Crop, + ) + } Image( painter = imagePainter, diff --git a/app-launcher/desktop/build.gradle.kts b/app-launcher/desktop/build.gradle.kts index a20b3cc15..4caf007d9 100644 --- a/app-launcher/desktop/build.gradle.kts +++ b/app-launcher/desktop/build.gradle.kts @@ -30,6 +30,12 @@ kotlin { implementation(libs.ktor.client.core) implementation(libs.slack.circuit.foundation) } + + jvmMain.dependencies { + runtimeOnly(compose.desktop.currentOs) + runtimeOnly(libs.kotlinx.coroutines.swing) + runtimeOnly(libs.slf4j.simple) + } } compose.desktop { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 004633c5e..3e0bd7bc1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -71,6 +71,7 @@ kotlinx-collections-immutable = "org.jetbrains.kotlinx:kotlinx-collections-immut kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } kotlinx-coroutines-play-services = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-play-services", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-swing", version.ref = "kotlinx-coroutines" } kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" } kotlinx-datetime = "org.jetbrains.kotlinx:kotlinx-datetime:0.5.0"