I am planning to replace all the fragments in my project with composables. The only fragment remaining is the one with a WebView
in it. I need a way to get it's screenshot whenever user clicks report button
Box(Modifier.fillMaxSize()) {
Button(
onClick = this@ViewerFragment::onReportClick,
)
AndroidView(factory = { context ->
MyWebView(context).apply {
loadDataWithBaseURL(htmlString)
addJavascriptInterface(JavaScriptInterface(), "JsIf")
}
}
)
}
Previously; I used to pass the webview
from view binding
to a utility function for capturing the screenshot.
fun onReportClick() {
val screenshot = ImageUtil(requireContext()).getScreenshot(binding.myWvViewer)
.
.
}
Docs recommend "Constructing the view in the AndroidView viewBlock is the best practice. Do not hold or remember a direct view reference outside AndroidView." So what could be the best approach?