Convert XML WebView into @Composable

Viewed 1897

I would like to convert a WebView into a @Composable. I am looking for something similar to SwiftUI's UIRepresentable.

I saw there was a @GenerateView annotation but, 1. that did the opposite of what I wanted(converted a @Composable into xml) 2. @GenerateView seems to have been taken away(I am using Dev05).

2 Answers

I think that feature is not supported yet. But you can interop traditional views with jetpack compose.

@Composable
fun Browser(list: List<String>) {
    Column(modifier = Modifier.fillMaxSize()) { item ->
        AndroidView(
                modifier = Modifier.fillParentMaxWidth().height(50.dp),
                viewBlock = { context ->
                    WebView(context).apply {
                        layoutParams = ViewGroup.LayoutParams(
                                ViewGroup.LayoutParams.MATCH_PARENT,
                                ViewGroup.LayoutParams.MATCH_PARENT,
                        )
                    }
                })
    }
}
Related