Created
April 14, 2022 15:13
-
-
Save akwasiio/e652767c1dc17105ef98ef073fb8ec9d 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
@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() | |
} | |
} |
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 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