Would anyone happen to know of a sample that imple...
# compose
m
Would anyone happen to know of a sample that implements Scaffold and a collapsible TopBar? Can't seem to find an example of it, and I'd prefer to keep my TopBar in the scaffolding similarly as done in the compose samples
1
s
This now kinda exists in material3 - look up LargeTopAppBar/MediumTopAppBar
m
Thanks for the tip, but doesn’t look like based on the docs that it’d support completely collapsing
s
I also don't think it's usable yet. I'm seeing two appbars on my side.
s
Works just fine for me - make sure to use all Material3 components (Text, Scaffold, etc) Also IIRC there is a scroll behaviour that can hide the app bar completely
s
so weird. what does your code look like?
s
Copied directly from docs 🤷🏻
Copy code
import androidx.compose.animation.rememberSplineBasedDecay
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.LargeTopAppBar
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.unit.dp
import com.google.accompanist.insets.statusBarsPadding

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HistoryRoot() {
  val decayAnimationSpec = rememberSplineBasedDecay<Float>()
  val scrollBehavior = remember(decayAnimationSpec) {
    TopAppBarDefaults.exitUntilCollapsedScrollBehavior(decayAnimationSpec)
  }
  Scaffold(
    modifier = Modifier
      .nestedScroll(scrollBehavior.nestedScrollConnection),
    topBar = {
      LargeTopAppBar(
        modifier = Modifier.statusBarsPadding(),
        title = {
          Text(
            text = "History",
            modifier = Modifier.padding(24.dp)
          )
        },
        scrollBehavior = scrollBehavior
      )
    }
  ) {
    LazyColumn(
      contentPadding = it,
      content = {
        items(100) {
          Text(
            text = "Hello $it",
            modifier = Modifier
              .fillParentMaxWidth()
              .padding(
                horizontal = 24.dp,
                vertical = 16.dp
              )
          )
        }
      }
    )
  }
}
s
Gotcha. My code practically looks the same but renders two appbars lol. I'll try it out again once it's stable.
s
Ah, I was getting the same behaviour when I used regular Text, it has to be material3.Text for some reason 🥲
s
haha nice!
o
The nested scroll connection used in
exitUntilCollapsed
has some weird issues with the fling when top bar is not fully collapsed. Do you guys experience the same issue?
s
I did but I am also using compose 1.0.x which doesn't support flings very nicely.
o
There is some change in fling behavior in 1.1.x? 🤔
s
🤗 1
👍 1