Skip to content

Commit

Permalink
🔒️ In filekit-coil and Apple targets, use security scope when display…
Browse files Browse the repository at this point in the history
…ing the image
  • Loading branch information
vinceglb committed Dec 30, 2024
1 parent 3c92cf3 commit 0dba3e0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -10,3 +11,6 @@ public actual val PlatformFile.coilModel: Any
is AndroidFile.UriWrapper -> it.uri
}
}

@Composable
internal actual fun AsyncImagePlatformEffects(file: PlatformFile?) {}
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
Original file line number Diff line number Diff line change
@@ -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?) {}
Original file line number Diff line number Diff line change
Expand Up @@ -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?)

0 comments on commit 0dba3e0

Please sign in to comment.