Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Show image under status bar in plant details screen (#888)
Browse files Browse the repository at this point in the history
* feat: add accompanist dependency

* feat: add accompanist dependency

* feat: make systemBarsColor transparent

* feat: remove systemBarPadding modifiers

* feat: add more specific name for dependency and delete unsplash key

* feat: delete the commented code
  • Loading branch information
qamarelsafadi authored Jul 5, 2023
1 parent b50b064 commit dff09b3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ dependencies {
implementation(libs.androidx.compose.runtime.livedata)
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.glide)
implementation(libs.accompanist.systemuicontroller)
debugImplementation(libs.androidx.compose.ui.tooling)

// Testing dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Share
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
Expand Down Expand Up @@ -200,7 +201,6 @@ fun PlantDetails(
Box(
modifier
.fillMaxSize()
.systemBarsPadding()
// attach as a parent to the nested scroll system
.nestedScroll(nestedScrollConnection)
) {
Expand Down Expand Up @@ -409,7 +409,9 @@ private fun PlantDetailsToolbar(
) {
Surface {
TopAppBar(
modifier = modifier.statusBarsPadding().background(color = MaterialTheme.colorScheme.surface),
modifier = modifier
.statusBarsPadding()
.background(color = MaterialTheme.colorScheme.surface),
title = {
Row {
IconButton(
Expand Down
19 changes: 15 additions & 4 deletions app/src/main/java/com/google/samples/apps/sunflower/ui/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat
import com.google.accompanist.systemuicontroller.rememberSystemUiController

private val LightColors = lightColorScheme(
primary = sunflower_green_500,
Expand Down Expand Up @@ -69,10 +72,18 @@ fun SunflowerTheme(
}
val view = LocalView.current
if (!view.isInEditMode) {
SideEffect {
val window = (view.context as Activity).window
window.statusBarColor = colorScheme.primary.toArgb()
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
val systemUiController = rememberSystemUiController()
val useDarkIcons = !isSystemInDarkTheme()
val window = (view.context as Activity).window
WindowCompat.setDecorFitsSystemWindows(window, false)
DisposableEffect(systemUiController, useDarkIcons) {
// Update all of the system bar colors to be transparent, and use
// dark icons if we're in light theme
systemUiController.setSystemBarsColor(
color = Color.Transparent,
darkIcons = useDarkIcons
)
onDispose {}
}
}

Expand Down
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
# The setting is particularly useful for tweaking memory settings.
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ tracing = "1.1.0"
uiAutomator = "2.2.0"
viewModelCompose = "2.5.1"
work = "2.7.1"
systemuicontroller = "0.30.1"

[libraries]
accessibility-test-framework = { module = "com.google.android.apps.common.testing.accessibility.framework:accessibility-test-framework", version.ref = "accessibilityTestFramework" }
Expand Down Expand Up @@ -118,6 +119,7 @@ kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-c
kotlinx-coroutines-guava = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-guava", version.ref = "coroutines" }
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
material = { module = "com.google.android.material:material", version.ref = "material" }
accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "systemuicontroller" }
okhttp3-logging-interceptor = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okhttpLogging" }
retrofit2 = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
retrofit2-converter-gson = { module = "com.squareup.retrofit2:converter-gson", version.ref = "retrofit" }

0 comments on commit dff09b3

Please sign in to comment.