diff --git a/filekit-coil/src/androidMain/kotlin/io/github/vinceglb/filekit/coil/FileKitCoil.android.kt b/filekit-coil/src/androidMain/kotlin/io/github/vinceglb/filekit/coil/FileKitCoil.android.kt index 32d2e9a..b22cec7 100644 --- a/filekit-coil/src/androidMain/kotlin/io/github/vinceglb/filekit/coil/FileKitCoil.android.kt +++ b/filekit-coil/src/androidMain/kotlin/io/github/vinceglb/filekit/coil/FileKitCoil.android.kt @@ -1,5 +1,6 @@ package io.github.vinceglb.filekit.coil +import androidx.compose.runtime.Composable import io.github.vinceglb.filekit.AndroidFile import io.github.vinceglb.filekit.PlatformFile @@ -10,3 +11,6 @@ public actual val PlatformFile.coilModel: Any is AndroidFile.UriWrapper -> it.uri } } + +@Composable +internal actual fun AsyncImagePlatformEffects(file: PlatformFile?) {} diff --git a/filekit-coil/src/appleMain/kotlin/io/github/vinceglb/filekit/coil/FileKitCoil.apple.kt b/filekit-coil/src/appleMain/kotlin/io/github/vinceglb/filekit/coil/FileKitCoil.apple.kt index b90fa0a..b02604a 100644 --- a/filekit-coil/src/appleMain/kotlin/io/github/vinceglb/filekit/coil/FileKitCoil.apple.kt +++ b/filekit-coil/src/appleMain/kotlin/io/github/vinceglb/filekit/coil/FileKitCoil.apple.kt @@ -1,6 +1,19 @@ package io.github.vinceglb.filekit.coil +import androidx.compose.runtime.Composable +import androidx.compose.runtime.DisposableEffect import io.github.vinceglb.filekit.PlatformFile public actual val PlatformFile.coilModel: Any get() = nsUrl + +@Composable +internal actual fun AsyncImagePlatformEffects(file: PlatformFile?) { + DisposableEffect(file) { + file?.nsUrl?.startAccessingSecurityScopedResource() + + onDispose { + file?.nsUrl?.stopAccessingSecurityScopedResource() + } + } +} diff --git a/filekit-coil/src/jvmMain/kotlin/io/github/vinceglb/filekit/coil/FileKitCoil.jvm.kt b/filekit-coil/src/jvmMain/kotlin/io/github/vinceglb/filekit/coil/FileKitCoil.jvm.kt index 25d0cdc..1ee3958 100644 --- a/filekit-coil/src/jvmMain/kotlin/io/github/vinceglb/filekit/coil/FileKitCoil.jvm.kt +++ b/filekit-coil/src/jvmMain/kotlin/io/github/vinceglb/filekit/coil/FileKitCoil.jvm.kt @@ -1,6 +1,10 @@ package io.github.vinceglb.filekit.coil +import androidx.compose.runtime.Composable import io.github.vinceglb.filekit.PlatformFile public actual val PlatformFile.coilModel: Any get() = file + +@Composable +internal actual fun AsyncImagePlatformEffects(file: PlatformFile?) {} diff --git a/filekit-coil/src/nonWebMain/kotlin/io/github/vinceglb/filekit/coil/FileKitCoil.nonWeb.kt b/filekit-coil/src/nonWebMain/kotlin/io/github/vinceglb/filekit/coil/FileKitCoil.nonWeb.kt index 0fb5d97..83f87ba 100644 --- a/filekit-coil/src/nonWebMain/kotlin/io/github/vinceglb/filekit/coil/FileKitCoil.nonWeb.kt +++ b/filekit-coil/src/nonWebMain/kotlin/io/github/vinceglb/filekit/coil/FileKitCoil.nonWeb.kt @@ -30,17 +30,24 @@ public actual fun AsyncImage( colorFilter: ColorFilter?, filterQuality: FilterQuality, clipToBounds: Boolean -): Unit = coil3.compose.AsyncImage( - model = file?.coilModel, - contentDescription = contentDescription, - imageLoader = SingletonImageLoader.get(LocalPlatformContext.current), - modifier = modifier, - transform = transform, - onState = onState, - alignment = alignment, - contentScale = contentScale, - alpha = alpha, - colorFilter = colorFilter, - filterQuality = filterQuality, - clipToBounds = clipToBounds, -) +) { + AsyncImagePlatformEffects(file) + + coil3.compose.AsyncImage( + model = file?.coilModel, + contentDescription = contentDescription, + imageLoader = SingletonImageLoader.get(LocalPlatformContext.current), + modifier = modifier, + transform = transform, + onState = onState, + alignment = alignment, + contentScale = contentScale, + alpha = alpha, + colorFilter = colorFilter, + filterQuality = filterQuality, + clipToBounds = clipToBounds, + ) +} + +@Composable +internal expect fun AsyncImagePlatformEffects(file: PlatformFile?)