https://kotlinlang.org logo
#compose
Title
# compose
n

Nick

09/09/2020, 5:10 PM
Hi people, I'm hoping to use Google Sign-in in a compose app by using the
AndroidView
Composable, but I can't seem to get it working. Has anyone else had luck embedding an old-style view on the
alpha-02
build? It doesn't necessarily need to be Google Sign-in, it could be any other view. I've watched the alpha video where they embed the Google Maps view but that did not help me!
z

Zach Klippenstein (he/him) [MOD]

09/09/2020, 5:17 PM
What's not working for you? Can you share any code?
n

Nick

09/09/2020, 5:24 PM
Hi, the problem I have is that I'm not understanding the signature of the
AndroidView
Composable. I don't know what I am supposed to pass to the
viewBlock
parameter. Initially I thought I could pass an activity or a fragment, but having thought about it for a while, I think that I somehow need to be able to pass just the GSI button, which is of class
com.google.android.gms.common.SignInButton
. Any thoughts?
z

Zach Klippenstein (he/him) [MOD]

09/09/2020, 5:35 PM
It's the view constructor. Most often you can just pass a function reference (e.g.
::SignInButton
), but that's basically the same as passing a lambda:
{ context -> SignInButton(context) }
n

Nick

09/11/2020, 7:49 AM
<2 days later> Thanks for the help @Zach Klippenstein (he/him) [MOD], in the end, I just implemented the Google Sign-in as a separate Activity. The ability to mix and match old-style UI and Compose is pretty neat. I feel sure that in the future, Google will get around to creating a native Compose GSI component and I'll switch over at that point.
z

Zach Klippenstein (he/him) [MOD]

09/11/2020, 2:30 PM
Maybe, but I wouldn't count on it. They've said there are certain components they're never going to port because it isn't worth it. Idk if this is one of them but it's not a standard material component so I can't imagine it's very high priority. I'm curious though, why didn't you end up just using
AndroidView
?
n

Nick

09/11/2020, 4:14 PM
Re-using an existing activity from an earlier build made for quicker progress. I can always come back to it. User experience is basically the same...