mirror of
https://github.com/jlengrand/compose-multiplatform.git
synced 2026-03-10 08:11:20 +00:00
ImageViewer, share image with description. (#3012)
This commit is contained in:
@@ -106,6 +106,9 @@ class AndroidImageStorage(
|
||||
|
||||
@OptIn(ExperimentalResourceApi::class)
|
||||
suspend fun getUri(context: Context, picture: PictureData): Uri = withContext(Dispatchers.IO) {
|
||||
if (!sharedImagesDir.exists()) {
|
||||
sharedImagesDir.mkdirs()
|
||||
}
|
||||
val tempFileToShare: File = sharedImagesDir.resolve("share_picture.jpg")
|
||||
when (picture) {
|
||||
is PictureData.Camera -> {
|
||||
@@ -113,6 +116,9 @@ class AndroidImageStorage(
|
||||
}
|
||||
|
||||
is PictureData.Resource -> {
|
||||
if (!tempFileToShare.exists()) {
|
||||
tempFileToShare.createNewFile()
|
||||
}
|
||||
tempFileToShare.writeBytes(resource(picture.resource).readBytes())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,10 @@ private fun getDependencies(
|
||||
Intent.EXTRA_STREAM,
|
||||
imageStorage.getUri(context.androidContext, picture)
|
||||
)
|
||||
putExtra(
|
||||
Intent.EXTRA_TEXT,
|
||||
picture.description
|
||||
)
|
||||
type = "image/jpeg"
|
||||
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||
}
|
||||
|
||||
@@ -57,7 +57,10 @@ fun getDependencies(ioScope: CoroutineScope, toastState: MutableState<ToastState
|
||||
val window = UIApplication.sharedApplication.windows.last() as? UIWindow
|
||||
val currentViewController = window?.rootViewController
|
||||
val activityViewController = UIActivityViewController(
|
||||
activityItems = listOf(UIImage(data = data)),
|
||||
activityItems = listOf(
|
||||
UIImage(data = data),
|
||||
picture.description
|
||||
),
|
||||
applicationActivities = null
|
||||
)
|
||||
currentViewController?.presentViewController(
|
||||
|
||||
Reference in New Issue
Block a user