Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed toolbar and status bar
Jetsurvey has had an issue since before this migration where the status
bar text/icons were too light in light mode. This fixes that my using
Accompanist, but I didn't enable edge-to-edge yet. I also missed that m3
has a custom TopAppBar to use when the text is center-aligned, so I
switched to that one.
  • Loading branch information
IanGClifton committed Aug 19, 2022
commit 04f641fda9753bb1400c9595e1c194cfd7a53747
1 change: 1 addition & 0 deletions Jetsurvey/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ dependencies {
debugImplementation Libs.AndroidX.Compose.tooling

implementation Libs.Accompanist.permissions
implementation Libs.Accompanist.systemUiController

implementation Libs.Coil.coilCompose

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ChevronLeft
import androidx.compose.material.icons.filled.Visibility
import androidx.compose.material.icons.filled.VisibilityOff
import androidx.compose.material3.CenterAlignedTopAppBar
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.SmallTopAppBar
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand All @@ -56,7 +56,6 @@ import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.compose.jetsurvey.R
Expand Down Expand Up @@ -96,11 +95,10 @@ fun SignInSignUpScreen(
@OptIn(ExperimentalMaterial3Api::class) // SmallTopAppBar is experimental in m3
@Composable
fun SignInSignUpTopAppBar(topAppBarText: String, onBackPressed: () -> Unit) {
SmallTopAppBar(
CenterAlignedTopAppBar(
title = {
Text(
text = topAppBarText,
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxSize()
.wrapContentSize(Alignment.Center)
Expand All @@ -110,7 +108,8 @@ fun SignInSignUpTopAppBar(topAppBarText: String, onBackPressed: () -> Unit) {
IconButton(onClick = onBackPressed) {
Icon(
imageVector = Icons.Filled.ChevronLeft,
contentDescription = stringResource(id = R.string.back)
contentDescription = stringResource(id = R.string.back),
tint = MaterialTheme.colorScheme.primary
)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.luminance
import com.google.accompanist.systemuicontroller.rememberSystemUiController

private val LightColors = lightColorScheme(
primary = md_theme_light_primary,
Expand Down Expand Up @@ -93,6 +97,18 @@ fun JetsurveyTheme(
DarkColors
}

val systemUiController = rememberSystemUiController()
DisposableEffect(systemUiController, useDarkTheme) {
systemUiController.setSystemBarsColor(
color = Color.Transparent,
darkIcons = !useDarkTheme
) {
md_theme_dark_surface
}

onDispose { }
}

MaterialTheme(
colorScheme = colors,
shapes = Shapes,
Expand All @@ -102,14 +118,4 @@ fun JetsurveyTheme(
}

@Composable
fun surfaceIsLight(): Boolean {
return when (val surface = MaterialTheme.colorScheme.surface) {
LightColors.surface -> true
DarkColors.surface -> false
else -> {
// If surface is ever set to some other color, it was manually overridden locally and
// the calling site should determine the light/dark value itself
throw java.lang.IllegalStateException("Surface does not match known value: $surface")
}
}
}
fun surfaceIsLight(): Boolean = MaterialTheme.colorScheme.surface.luminance() > 0.5f
19 changes: 0 additions & 19 deletions Jetsurvey/app/src/main/res/values-night/colors.xml

This file was deleted.

19 changes: 0 additions & 19 deletions Jetsurvey/app/src/main/res/values/colors.xml

This file was deleted.

2 changes: 1 addition & 1 deletion Jetsurvey/app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<resources>
<!-- Base application theme. -->
<style name="Theme.Jetsurvey" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:statusBarColor">@color/status_bar_color</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:windowBackground">?attr/colorSurface</item>
</style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ object Libs {
object Accompanist {
const val version = "0.25.1"
const val permissions = "com.google.accompanist:accompanist-permissions:$version"
const val systemUiController = "com.google.accompanist:accompanist-systemuicontroller:$version"
}

object Kotlin {
Expand Down