How can the parent composable communicate events to the child composable? For example, I want to scr...
a
How can the parent composable communicate events to the child composable? For example, I want to scroll-to-top the start destination when the bottom bar is tapped.
y
f
Ideally the events should go only up and state go down in the view hierarchy. Try reading specifically the State hoisting chapter in the documentation YG6008 linked.
y
@Filip Wiesner 👍
f
But if have to do it like this, then you can always pass something like listener callback or some other thing that the child will listen to 🤷 But I would advice against doing that. Or if you have a ViewModel that you pass to this child, you could pipe the event through it.
b
Hoist a state holder that has a function in it to scroll to the top. For example how LazyList does it
a
Hoist a state holder that has a function in it to scroll to the top. For example how LazyList does it
Ah, that’s what I thought too, just a bit weird to hoist the lazyListState up to the root 😄. I have a feeling it would break the list state somehow too, but I could try a hoist separate state just for scrolling up. Currently we provide a Scroll event flow in a repository, but I don’t like that we have scroll events at that layer.
735 Views