is it okay to return constant view in AndroidView ...
# compose
p
is it okay to return constant view in AndroidView factory?
Copy code
val btn = Button(context)
AndroidView(factory = { btn } )
I guess it could impact performance, when stuff is re-composed. Anything else?
c
You'll want to remember the
Button
, but that should work fine. We do something similar.
🍻 1
z
Why would you do this? Im just very curious
c
Otherwise you'll be creating a new view on every recomposition.
z
My bad, I was referring to why one would instantiate the view outside of
AndroidView
? I understand that might also be to re-use the view, but AndroidView does that as well doesnt it?
c
Ahhh, we had a use case where we needed the view before the `AndroidView`:
Copy code
val view = remember(context) { BlahBlahView(context) }

Box(
    modifier = modifier
        .nestedScroll(rememberViewInteropNestedScrollConnection(view))
) {
    AndroidView(
        factory = { view },
        modifier = Modifier.matchParentSize(),
    )
    
    content()
}
z
Ah, cool. Thanks for explaining! 🙏🏽