https://kotlinlang.org logo
Title
a

allan.conda

08/24/2022, 7:40 AM
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

Yashwant Gowla

08/24/2022, 7:44 AM
f

Filip Wiesner

08/24/2022, 9:16 AM
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

Yashwant Gowla

08/24/2022, 9:19 AM
@Filip Wiesner 👍
f

Filip Wiesner

08/24/2022, 9:21 AM
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

Ben Trengrove [G]

08/24/2022, 9:09 PM
Hoist a state holder that has a function in it to scroll to the top. For example how LazyList does it
a

allan.conda

08/25/2022, 5:10 AM
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.