Browse Source

ImageViewer, share image with description. (#3012)

pull/3020/head
dima.avdeev 2 years ago committed by GitHub
parent
commit
bb950bc91a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/storage/AndroidImageStorage.kt
  2. 4
      examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/view/ImageViewer.android.kt
  3. 5
      examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/ImageViewer.ios.kt

6
examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/storage/AndroidImageStorage.kt

@ -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())
}
}

4
examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/view/ImageViewer.android.kt

@ -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
}

5
examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/ImageViewer.ios.kt

@ -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(

Loading…
Cancel
Save