Skip to content

Instantly share code, notes, and snippets.

@chiragthummar
Created January 4, 2024 06:11
Show Gist options
  • Save chiragthummar/4984ba0ce291cf3873a6454c96638948 to your computer and use it in GitHub Desktop.
Save chiragthummar/4984ba0ce291cf3873a6454c96638948 to your computer and use it in GitHub Desktop.
import android.webkit.WebView
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView
@Composable
fun WebViewCommunication(modifier: Modifier = Modifier) {
Column(modifier = Modifier.fillMaxSize()){
AndroidView(factory = {context ->
WebView(context).apply {
settings.javaScriptEnabled = true
settings.loadWithOverviewMode = true
settings.useWideViewPort = true
settings.setSupportZoom(true)
addJavascriptInterface(JavaScriptInterface(context),"AndroidFunction")
loadUrl("file:///android_asset/my.html")
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment