From ef7af2085396f980be836bae07e916707f2bf35f Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Sun, 4 Sep 2022 15:35:50 +0100 Subject: [PATCH] applying dynamic colour scheme and fixing appbar/navbar quirks --- .../app/dapk/st/design/components/Theme.kt | 3 +++ .../app/dapk/st/design/components/Toolbar.kt | 23 +++++-------------- .../kotlin/app/dapk/st/home/HomeScreen.kt | 4 ++-- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/design-library/src/main/kotlin/app/dapk/st/design/components/Theme.kt b/design-library/src/main/kotlin/app/dapk/st/design/components/Theme.kt index 0554042..6fa88d3 100644 --- a/design-library/src/main/kotlin/app/dapk/st/design/components/Theme.kt +++ b/design-library/src/main/kotlin/app/dapk/st/design/components/Theme.kt @@ -3,8 +3,10 @@ package app.dapk.st.design.components import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.material3.MaterialTheme import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme import androidx.compose.runtime.* import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext import com.google.accompanist.systemuicontroller.rememberSystemUiController import kotlin.math.absoluteValue @@ -56,6 +58,7 @@ fun SmallTalkTheme(content: @Composable () -> Unit) { val systemUiController = rememberSystemUiController() val systemInDarkTheme = isSystemInDarkTheme() MaterialTheme( + colorScheme = dynamicDarkColorScheme(LocalContext.current) // colorScheme = if (systemInDarkTheme) DARK_COLOURS else LIGHT_COLOURS, ) { val backgroundColor = MaterialTheme.colorScheme.background diff --git a/design-library/src/main/kotlin/app/dapk/st/design/components/Toolbar.kt b/design-library/src/main/kotlin/app/dapk/st/design/components/Toolbar.kt index 706a4cb..0698301 100644 --- a/design-library/src/main/kotlin/app/dapk/st/design/components/Toolbar.kt +++ b/design-library/src/main/kotlin/app/dapk/st/design/components/Toolbar.kt @@ -2,11 +2,10 @@ package app.dapk.st.design.components import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.offset -import androidx.compose.material3.* import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBack +import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -23,32 +22,22 @@ fun Toolbar( actions: @Composable RowScope.() -> Unit = {} ) { val navigationIcon = foo(onNavigate) - SmallTopAppBar( - modifier = Modifier.height(72.dp).run { - if (offset == null) { - this - } else { - this.offset(offset) - } - }, + modifier = offset?.let { Modifier.offset(it) } ?: Modifier, colors = TopAppBarDefaults.smallTopAppBarColors( containerColor = MaterialTheme.colorScheme.background ), - navigationIcon = navigationIcon ?: {}, - title = title?.let { - { Text(it, maxLines = 2) } - } ?: {}, + navigationIcon = navigationIcon, + title = title?.let { { Text(it, maxLines = 2) } } ?: {}, actions = actions, ) Divider(modifier = Modifier.fillMaxWidth(), color = Color.Black.copy(alpha = 0.2f), thickness = 0.5.dp) } - -private fun foo(onNavigate: (() -> Unit)?): (@Composable () -> Unit)? { +private fun foo(onNavigate: (() -> Unit)?): (@Composable () -> Unit) { return onNavigate?.let { { NavigationIcon(it) } - } + } ?: {} } @Composable diff --git a/features/home/src/main/kotlin/app/dapk/st/home/HomeScreen.kt b/features/home/src/main/kotlin/app/dapk/st/home/HomeScreen.kt index 5786d21..9faf065 100644 --- a/features/home/src/main/kotlin/app/dapk/st/home/HomeScreen.kt +++ b/features/home/src/main/kotlin/app/dapk/st/home/HomeScreen.kt @@ -26,7 +26,6 @@ fun HomeScreen(homeViewModel: HomeViewModel) { homeViewModel.start() } - when (val state = homeViewModel.state) { Loading -> CenteredLoading() is SignedIn -> { @@ -76,8 +75,9 @@ private fun BottomBar(state: SignedIn, homeViewModel: HomeViewModel) { }, ) Profile -> NavigationBarItem( + icon = { - Box(modifier = Modifier.fillMaxHeight()) { + Box { CircleishAvatar(state.me.avatarUrl?.value, state.me.displayName ?: state.me.userId.value, size = 25.dp) } },