Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert XML WebView into @Composable

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).

like image 398
K-2SO Avatar asked Dec 06 '25 05:12

K-2SO


1 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,
                        )
                    }
                })
    }
}
like image 200
Jeeva Avatar answered Dec 07 '25 21:12

Jeeva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!