y

    yschimke

    6 months ago
    I've got a question about using Scaffold with Navigation. I'm switching my PositionIndicator scroll state whenever the navigation NavBackStackEntry changes. The default for this doesn't appear to work, I'm guessing because my scroll type is always ScalingLazyListState state, while other tests change between different scroll types. I've worked around it by wrapping it with
    key(currentBackStackEntry?.destination?.route)
    but surprised I needed to. Is this expected? Am I doing something wrong with when I'm accessing a state field? Or is it a bug in PositionIndicator?
    A simplified version of the code
    positionIndicator = {
                val scalingLazyListState = viewModel?.scrollableState as ScalingLazyListState?
    
                if (scalingLazyListState != null) {
                    key(currentBackStackEntry?.destination?.route) {
                        MyPositionIndicator(scalingLazyListState)
                    }
                }
            },
    I think it's the same for TimeText.
    John Nichol

    John Nichol

    6 months ago
    @Sergio Sancho @Steve Bower [G]
    Sergio Sancho

    Sergio Sancho

    6 months ago
    What does viewModel?.scrollableState have? It holds the state for different components depending on what's on screen?
    y

    yschimke

    6 months ago
    Yep, exactly. Since you have 1 scaffold screen + X navigation destinations, the position indicator and the timetext need to react to the current navigation destination.
    It's essentially a newer iteration of this from the ComposeAdvanced sample https://github.com/android/wear-os-samples/commit/df0988596aa2e90424622819d1886e8012ec007c
    We are trying to confirm a theory, so will update here when done.
    One other noticeable glitch, because I react to the screen changing, it is noticeable that these elements in the Scaffold coming after the rest of the screen has drawn. Not sure if I should expect this, or try to find a way to make it happen sooner? Maybe I can hook into navigation events, rather than reacting to to
    navController.currentBackStackEntryAsState()
    .
    Steve Bower [G]

    Steve Bower [G]

    6 months ago
    Is it the PositionIndicator that's redrawn after a delay? Could that be part of an animation (because it's usually fading in/out)?
    Sergio Sancho

    Sergio Sancho

    6 months ago
    Update: We found a bug in the PositionIndicator not updating when reusing it with a different state object (it kept a reference to the old one). Fix in progress.
    y

    yschimke

    6 months ago
    @Steve Bower [G] No the time text. I'll make a video and post it. I've also seen the position indicator bleed onto the next screen for a split second. So I definitely think it's a timing issue with the approach I've used.
    You can see the delay when I return to the inbox from the task screen.
    I will make a clean sample in a sample project, so don't worry about it yet. But I did want to flag it in case it's either a) simple for me to fix, b) something to consider with the Scaffold approach/design with TimeText, PositionIndicator, Vignette separated from the navigation destination screens. Maybe I shouldn't be waiting for
    currentBackStackEntryAsState
    to change?