diff --git a/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/service/ImageService.android.kt b/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/service/ImageService.android.kt index 4f238e9..97a2010 100644 --- a/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/service/ImageService.android.kt +++ b/composeApp/src/androidMain/kotlin/net/codinux/banking/ui/service/ImageService.android.kt @@ -8,5 +8,5 @@ import java.net.URL actual fun createImageBitmap(imageBytes: ByteArray): ImageBitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.size).asImageBitmap() -actual fun fetchBytesFromUrl(url: String): ByteArray = +actual suspend fun fetchBytesFromUrl(url: String): ByteArray = URL(url).openStream().buffered().use { it.readBytes() } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/ImageService.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/ImageService.kt index 87ee1b4..1d2b87a 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/ImageService.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/service/ImageService.kt @@ -4,4 +4,4 @@ import androidx.compose.ui.graphics.ImageBitmap expect fun createImageBitmap(imageBytes: ByteArray): ImageBitmap -expect fun fetchBytesFromUrl(url: String): ByteArray \ No newline at end of file +expect suspend fun fetchBytesFromUrl(url: String): ByteArray \ No newline at end of file diff --git a/composeApp/src/desktopMain/kotlin/net/codinux/banking/ui/service/ImageService.desktop.kt b/composeApp/src/desktopMain/kotlin/net/codinux/banking/ui/service/ImageService.desktop.kt index 227fa10..3b66d18 100644 --- a/composeApp/src/desktopMain/kotlin/net/codinux/banking/ui/service/ImageService.desktop.kt +++ b/composeApp/src/desktopMain/kotlin/net/codinux/banking/ui/service/ImageService.desktop.kt @@ -8,5 +8,5 @@ import java.net.URL actual fun createImageBitmap(imageBytes: ByteArray): ImageBitmap = Image.makeFromEncoded(imageBytes).toComposeImageBitmap() -actual fun fetchBytesFromUrl(url: String): ByteArray = +actual suspend fun fetchBytesFromUrl(url: String): ByteArray = URL(url).openStream().buffered().use { it.readAllBytes() } \ No newline at end of file diff --git a/composeApp/src/jsMain/kotlin/net/codinux/banking/ui/service/ImageService.js.kt b/composeApp/src/jsMain/kotlin/net/codinux/banking/ui/service/ImageService.js.kt index 2ab4070..a625d79 100644 --- a/composeApp/src/jsMain/kotlin/net/codinux/banking/ui/service/ImageService.js.kt +++ b/composeApp/src/jsMain/kotlin/net/codinux/banking/ui/service/ImageService.js.kt @@ -2,9 +2,18 @@ package net.codinux.banking.ui.service import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.toComposeImageBitmap +import kotlinx.browser.window +import kotlinx.coroutines.await import org.jetbrains.skia.Image +import org.khronos.webgl.Int8Array actual fun createImageBitmap(imageBytes: ByteArray): ImageBitmap = Image.makeFromEncoded(imageBytes).toComposeImageBitmap() -actual fun fetchBytesFromUrl(url: String): ByteArray = ByteArray(0) \ No newline at end of file +actual suspend fun fetchBytesFromUrl(url: String): ByteArray { + val response = window.fetch(url).await() + val arrayBuffer = response.arrayBuffer().await() + + val byteArray = Int8Array(arrayBuffer) + return byteArray.unsafeCast() +} \ No newline at end of file