Miguel Kano

01/07/2023, 10:39 PM
In the fragment world, we could have a shared top bar where each fragment could specify what gets displayed for the action items and receive the click events. In compose, the recommended approach seems to be to define the top bar outside the NavHost and use APIs such as
to mutate the top bar based on the current screen. This means the root Scaffold owns the declaration of the top bar. It works fine for simple cases like just toggling the visibility of the top bar or controlling the bottom bar, but I find it not very practical in the following aspects. I've searched around on this slack, but couldn't find an answer that feels satisfying.
Copy code
    topBar = {
        if (currentScreen is ShowTopBar) {
                actions = {
) {
    NavHost {...}
1: How would the currently displayed composable screen receive the click event on the action items? Pushing the event down is discouraged. I found this post from Ian, but I don't get it 2: If which action items should display depends on the logic/data fetched from the current screen, how should that be communicated to the root Scaffold? 3: In reality with large apps, I would want to define/encapsulate such logic and click event handling closer to the actual feature rather than defining all variations of them at the root level.
@Ian Lake Any thoughts? I would love your feedback.

Christopher Mederos

06/30/2023, 5:25 AM
@Miguel Kano - I'm working through the same exact issues now. I'm curious if you ever found an answer?