Skip to content

Instantly share code, notes, and snippets.

@akwasiio
Created April 14, 2022 15:13
Show Gist options
  • Save akwasiio/e652767c1dc17105ef98ef073fb8ec9d to your computer and use it in GitHub Desktop.
Save akwasiio/e652767c1dc17105ef98ef073fb8ec9d to your computer and use it in GitHub Desktop.
@SuppressLint("ViewConstructor")
class AndroidComposeView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
// add extra params here
) : AbstractComposeView(context, attrs, defStyleAttr) {
@Composable
override fun Content() {
ComposableFunctionYouWantToConvert()
}
}
@Composable
fun MainScreen() {
var androidView by remember { mutableStateOf<AndroidComposeView?>(null) }
Column(modifier = Modifier.fillMaxSize()) {
AndroidView( factory = {
AndroidComposeView(context = it).apply {
post { androidView = this }
}
}
)
Button(onClick ={
val bitmap = androidView.toBitmap()
// share bitmap as pdf
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment