Is there a way to write a `@Composable fun` that i...
# compose
a
Is there a way to write a
@Composable fun
that is effectively inlined (and without a group) ? I have a UI with a flat hierarchy and would like to factorise some of the logic in different functions, knowing that exactly one of these will be called no matter what the input parameters are. The pattern I’d like to achieve is similar to this Gist : https://gist.github.com/alexandrepiveteau/47a18b29a6bd9cc2fcd2d347bc8f4a44. While looking into this, I’ve stumbled on
@ComposableContract(readonly = true)
, which “does not generate a group around the body of the function it annotates”, and I feel like is kind of what I’d need. However, the documentation clearly states that it is “not safe unless […] composer only executes read operations”. What’s exactly a “write” operation for a composer ? And is there a better way to achieve what I’m trying to do than using
@ComposableContract(readonly = true)
?
(to provide a bit of context on my use-case, I’m working on this

https://youtu.be/whHCbxdHjIs

for a college project. I’m rendering the different “sticky stacks” with a dedicated
@Composable fun
, but would like to enable drag and drop of individual stickies between columns, with continuous animations. Ideally, I’d still like to factorise some of the code (for instance the stack positioning logic) in dedicated functions, while simultaneously keeping all the stickies at the same “level” in my composable hierarchy. The WIP source code is at https://github.com/heig-IHM/stickies)
z
Why do you want to avoid groups?
c
Your description implies that you believe removing the group would enable functionality that include the group does not. What behavior do you believe the group is preventing? In general, groups just track the execution of the function allowing the composer to determine which nodes were provided by the previous execution that need to be removed or moved and which nodes are new to the composition and need to be inserted. In general, a group is required whenever the code might branch. The fact that you code contains an
if
statement at all indicates that, even if the group was removed from the call, at least one group is necessary.