Skip to content

Instantly share code, notes, and snippets.

@pengj
Created May 10, 2021 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pengj/3127a9bc8a15760761a440bc662bb947 to your computer and use it in GitHub Desktop.
Save pengj/3127a9bc8a15760761a440bc662bb947 to your computer and use it in GitHub Desktop.
@Composable
fun ImageButton(uri: Uri? = null,
imageClicked: (Uri) -> Unit) {
Box(modifier = Modifier.fillMaxSize()) {
uri?.let { imageUri ->
Image(
painter = rememberGlidePainter(
imageUri,
fadeIn = true
),
contentDescription = "Captured Image",
modifier = Modifier
.height(180.dp)
.width(180.dp)
.padding(32.dp)
.align(Alignment.TopStart)
.clickable {
imageClicked.invoke(imageUri)
}
)
val mimeType = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(imageUri.toFile().extension)
MediaScannerConnection.scanFile(
LocalContext.current,
arrayOf(imageUri.toFile().absolutePath),
arrayOf(mimeType)
) { _, uri ->
Log.d(TAG,"Image capture scanned into media store: $uri")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment