<@U5J9D5H8Q> You shouldn't rely on the XML syntax ...
# compose
r
@rivu.chakraborty You shouldn't rely on the XML syntax so much, it's going away. Use the regular function call syntax instead.
r
@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
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
I've an import to
androidx.compose.composer
, I'll update the post right away, to replace the XML syntax with DSL @romainguy
t
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
That too, thanks Mikhail
We need to make it the default
b
@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
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
CraneWrapper
is a
View
that sets up Compose underneath
✔️ 2
It’s how we hook up Jetpack Compose to the View hierarchy
r
@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
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
For example, if you want access to the
Context
. You could use
val context = +ambient(ContextAmbient)
in one of your composables.
l
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
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
One of the many, many reasons why Jetpack Compose isn’t ready for production 🙂
b
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
It’s one of the reasons we wanted to Open Source it 🙂
b
is there a issue / feature list like a youtrack? I could not find 😕
t
@romainguy I’ve submitted a PR regarding that plugin checker defaults https://android-review.googlesource.com/c/platform/frameworks/support/+/960637