https://kotlinlang.org logo
r

romainguy

05/13/2019, 2:25 PM
@rivu.chakraborty You shouldn't rely on the XML syntax so much, it's going away. Use the regular function call syntax instead.
r

rivu.chakraborty

05/13/2019, 2:43 PM
@romainguy I agree and understand, but the issue is I'm getting this compiler error saying "Stateless function shouldn't be invoked" when trying to use the DSL style, I'm stuck with XML syntax until I find a workaround.
r

romainguy

05/13/2019, 2:45 PM
You're missing the import for composer
Please do not tell folks to use the XML syntax it's going to create more confusion :)
👍 3
r

rivu.chakraborty

05/13/2019, 2:46 PM
I've an import to
androidx.compose.composer
, I'll update the post right away, to replace the XML syntax with DSL @romainguy
t

themishkun

05/13/2019, 2:57 PM
You should set compiler flag
-P plugin:androidx.compose.plugins.kotlin:syntax=FCS
to get rid of this warning
Look at the AndroidXUiPlugin for more details
r

romainguy

05/13/2019, 2:59 PM
That too, thanks Mikhail
We need to make it the default
b

bloder

05/13/2019, 3:00 PM
@rivu.chakraborty Good article, I'm just missing the detailed explanation about why we need the usage of the
CraneWrapper
, probably we should use when we define a style or something like that but I don't know why (didn't have time to check this part of source code)
r

rivu.chakraborty

05/13/2019, 3:24 PM
Thanks @themishkun that worked like a charm, I'll add this as well in my blog, it'll no doubt help a lot of folks.
@bloder thanks. For the CraneWrapper, as me and @ragunathjawahar discussed last day, we guess that it happens as when encountering a more complex component than Text,
compose
expects a theme. I didn't mention it in the post as I'm not 100% sure about it yet, just wanted to give folks a heads-up that they need CraneWrapper and a theme to use any composable other than text.
r

romainguy

05/13/2019, 3:54 PM
CraneWrapper
is a
View
that sets up Compose underneath
✔️ 2
It’s how we hook up Jetpack Compose to the View hierarchy
r

ragunathjawahar

05/13/2019, 3:57 PM
@bloder the
CraneWrapper
uses the
AndroidCraneView
to host the compose tree. Besides that, it also grants access to the
Context
,
Density
,
FocusManager
and
TextInputService
implicitly to any of your composables (downstream) via their corresponding ambients.
r

romainguy

05/13/2019, 3:57 PM
In particular it sets up access to the context, to density, to the focus manager and to text input
Note that the name
Crane
will likely disappear soon
It was the internal code name of Compose, this is just a leftover
👍 1
r

ragunathjawahar

05/13/2019, 3:59 PM
For example, if you want access to the
Context
. You could use
val context = +ambient(ContextAmbient)
in one of your composables.
l

Leland Richardson [G]

05/13/2019, 4:04 PM
you can think of CraneWrapper as a composable that converts the hierarchy from views -> compose ui. Composables underneath it should target compose UI, composables outside of it should target views. Right now this isn’t enforced at the compiler level but will be at some point. If you’re just using compose to target views, it’s not needed at all right now. If you’re using compose UI, you should put it at the root of your hierarchy.
👍 2
b

bloder

05/13/2019, 4:13 PM
Ohh thank you for the explanations, an other question about it, following this concept isn't make sense wrapping our composables automatically in
setContent
like a default wrapping of
CraneWrapper
?
r

romainguy

05/13/2019, 4:15 PM
One of the many, many reasons why Jetpack Compose isn’t ready for production 🙂
b

bloder

05/13/2019, 4:17 PM
Nice, thank you! I'm pretty excited to use it, is Compose open to community contributions? I really would like to help if it's possible.
r

romainguy

05/13/2019, 4:20 PM
It’s one of the reasons we wanted to Open Source it 🙂
b

bloder

05/13/2019, 4:22 PM
is there a issue / feature list like a youtrack? I could not find 😕
t

themishkun

05/13/2019, 5:01 PM
@romainguy I’ve submitted a PR regarding that plugin checker defaults https://android-review.googlesource.com/c/platform/frameworks/support/+/960637