Created
October 16, 2021 11:22
-
-
Save ch8n/a02f4079a9e4cd1dbc3cc48e4f60d68c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun CaptureBitmap( | |
content: @Composable ()->Unit | |
) : () -> Bitmap // <---- this will return a callback which returns a bitmap | |
{ | |
val composeView = ComposeView(...) | |
//callback that convert view to bitmap | |
fun captureBitmap() = composeView.drawToBitmap() | |
AndroidView( | |
factory = { | |
composeView.apply { | |
setContent { | |
content.invoke() // <--- Content get places in between this code | |
} | |
} | |
} | |
) | |
return ::captureBitmap // <--- return functional reference of the callback | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment