Is it possible to wrap/unwrap composables with Alt...
# compose
j
Is it possible to wrap/unwrap composables with Alt-Enter (same behaviour used in Flutter)?
1
a
Not yet, most of the things you would do this way are done with modifiers though. What specific things would you like to see?
j
Well is pretty usual having nested views. So wrap unwrap with alt enter is easier than deleting by hand. Is it planned?
a
can't plan without knowing what you'd like to wrap things with 🙂 we've talked about it and some folks have asked for it but I've never personally found features like that useful, so specific suggestions welcome
j
Any thing, for example I have a text and I would like to wrap with a row, after, I add some elements to the row. Later I want to wrap this row with a column and so on. This weekend I will play more with compose so maybe I can give you more specific examples but the last time I used it I would like to have the wrap/unwrap composable equivalent of Flutter. After developing with Flutter which is very similar to compose, I can't imagine create an UI without that feature, I think I probably use it 100 times every day as minimum.
c
I think this would be useful too. With Compose it is likely that you implement your UI inside-out. Start with the smallest unit, then wrap it in a bigger layout and so on.
a
The question in my mind is how the tool should specifically behave and how it should select what to wrap what with. Since compose uses lambda blocks as content you could get very general and mechanical; wrap the expression from the current line in a set of
{}
, indent as appropriate and place the cursor before the opening
{
starting autocomplete from functions that accept a
@Composable
trailing lambda (presuming the expression includes a
@Composable
call, otherwise widen the valid completions to any trailing lambda)
c
Hmm good question. I guess for starters it could offer to wrap with some general purpose containers (
Row
,
Column
,
ConstraintLayout
,
AdapterList
)
a
It could, but the intent of Compose is to make it very easy and useful to define your own containers, layouts and wrappers. Special casing the foundation layouts isn't necessarily sufficient, and would influence a lot of people's design thinking if they came to rely on that tool.
And I don't know about you, but I might find it very useful to use this same feature to wrap a starting expression in a
with(...) {
c
Fair enough. If I had a need to wrap an expression in a
with
I'd probably use IntelliJ's postfix completion feature. Probably worth considering postfix templates for compose then?
But I now realize that the question remains unanswered: What would you offer to wrap with, even using postfix? 🤔