Skip to content

Commit

Permalink
Compose: color top app bar when scrolling.
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Jan 31, 2024
1 parent 9716fb5 commit e410318
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Devices
Expand Down Expand Up @@ -68,7 +72,8 @@ class AboutActivity : ComponentActivity() {
@Composable
fun SgTopAppBar(
titleStringRes: Int,
onBackPressed: () -> Unit
onBackPressed: () -> Unit,
scrollBehavior: TopAppBarScrollBehavior
) {
TopAppBar(
title = {
Expand All @@ -85,7 +90,8 @@ class AboutActivity : ComponentActivity() {
contentDescription = stringResource(id = R.string.navigate_back)
)
}
}
},
scrollBehavior = scrollBehavior
)
}

Expand All @@ -100,9 +106,12 @@ class AboutActivity : ComponentActivity() {
onOpenTmdbApiTerms: () -> Unit,
onOpenTraktTerms: () -> Unit
) {
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState())

Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
SgTopAppBar(R.string.prefs_category_about, onBackPressed)
SgTopAppBar(R.string.prefs_category_about, onBackPressed, scrollBehavior)
}
) { scaffoldPadding ->
BoxWithConstraints(
Expand Down

0 comments on commit e410318

Please sign in to comment.