Can someone explain to me what this does? ```priva...
# compose
b
Can someone explain to me what this does?
Copy code
private fun WebView.setRef(ref: (WebView) -> Unit) {
    ref(this)
}
Taken from ui/ui-android-view/src/main/java/androidx/ui/androidview/WebComponent.kt
l
Simply runs the
ref
function it accept as a parameter providing
this
as receiver of that function 🤔
b
mm I see. Unfamiliar with how that works. I'll look into that, thanks
z
I think the reason for this is that to “render” a legacy
View
in a composable, you invoke it as a function – you don’t instantiate it, so you never actually have a reference to the
View
object. This pattern gets you around that.
➕ 1
This message+thread has some more details about the general integration story right now: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1576264533012000?thread_ts=1576262311.008800&cid=CJLTWPH7S
l
yeah…. compose will use properties and setter functions on views and interpret them as parameters. The interesting bit is it will also use extension properties/setters if they are in scope. So the
WebView.setRef
function above gets interpreted as a
ref
parameter in the composable webview call. It’s a bit weird, which is why we haven’t talked a ton about it yet, and some of it still might change
😮 1
b
gotcha, thanks for the help
z
Oh, that extension property support is super useful.