Is it possible to make a component that would rece...
# compose
o
Is it possible to make a component that would receive a simple
content: @Composable () -> Unit
but then will wrap each child into another component?
j
Hmm probably not unless you control the Applier or write a compiler plugin to rewrite the compose compiler statements
z
Depending on what you are trying to do with the wrappers, you could maybe get something to work with a SubcomposeLayout - but that would still only work for children emitted directly from
content
o
Though I’ve solved my task with a bit of DSL (and it appears even better than what I originally envisioned – less magic!), I’m still interested in theoretical stuff here…
z
Could you share a few more details, maybe some code?
o
Well, I basically want to turn this:
Copy code
Container {
   Component {}
   Component {}
}
into this (in runtime):
Copy code
Container {
   ContainerWrapper { Component{} }
   ContainerWrapper { Component{} }
}
by just doing something in the
Container
component.
a
I'd prefer to configure children via params (state) or LocalComposition as well as MaterialTheme does it.
o
In my hypothetical situation children are not (and should not) aware of what Container wants to do with them 🙂
a
which part of
Component {}
would the wrapper wrap, and why?
🤷‍♂️ 1
the options/answers to that question that we came up with all broke some deep behavior or encapsulation expectations in one place or another
👌 1