Hello, eveyone! I’m new to declarative UI and I h...
# compose
e
Hello, eveyone! I’m new to declarative UI and I have a question. 😅 Is there a recommended way in compose to handle complex interactions in a screen? Today my code is something like this and may increase in the future. My first idea is to encapsulate all the high-order functions in a
TaskDetailActions
and pass the object instead of all the params. Is there a better/more recommended solution? Thanks a lot in advance! 😊
1
Basically I’m doing this to avoid passing the
ViewModels
to the components below.
a
You can try to pass an arbitrary composable content
content: @Composable () -> Unit
as mentioned in this

video

(9:06) by Leland.
🙌 1
l
I've found that once you start taking Previews seriously, the pattern is somewhat emergent. The screenshot you've shown is pretty typical in my projects.
e
Well, in my understand I use this type of composable when I want to delegate the composition for another function, right?
The functions in the given TaskDetailRouter are high-order functions that delegate some ViewModel operation for the composable above without passing the ViewModel. They are not related to “how to compose the screen”.
t
yeah, having individual lambdas for every event/action quickly becomes unscalable. creating a sealed class such as your example of
TaskDetailActions
for the context of your component would be a better replacement for individual event lambdas
👍 1
also, depending on the relationship between the two states you’re passing, you could create a higher level state for your component, so you might end up with just:
Copy code
fun TaskDetailRouter(state: TaskDetailRouterState, onAction: (TaskDetailRouterAction) -> Unit) { ... }
👍 1