Skip to content

Commit f2d1f97

Browse files
committed
compose: Theme: Apply right background color from Material3 view library
Material3 view based lib already uses it, but compose stable one not Using version 1.2.0-rc01 breaks sliders, thx Google
1 parent 289f132 commit f2d1f97

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ dependencies {
6868
implementation "androidx.compose.ui:ui-tooling-preview"
6969
debugImplementation "androidx.compose.ui:ui-tooling"
7070
debugImplementation "androidx.compose.ui:ui-test-manifest"
71+
implementation 'androidx.compose.material3:material3'
7172

72-
implementation 'androidx.compose.material3:material3:1.1.2'
7373
testImplementation 'junit:junit:4.13.2'
7474
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
7575
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

app/src/main/java/com/sanyapilot/yandexstation_controller/device/settings/SettingsFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class SettingsFragment : Fragment() {
111111
return ComposeView(requireContext()).apply {
112112
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
113113
setContent {
114-
AppTheme {
114+
AppTheme(context = this@SettingsFragment.context) {
115115
Surface {
116116
SettingsLayout(viewModel, deviceConfig)
117117
}

app/src/main/java/com/sanyapilot/yandexstation_controller/ui/theme/Theme.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package com.sanyapilot.yandexstation_controller.ui.theme
22

3+
import android.content.Context
34
import android.os.Build
45
import androidx.compose.foundation.isSystemInDarkTheme
56
import androidx.compose.material3.MaterialTheme
6-
import androidx.compose.material3.lightColorScheme
77
import androidx.compose.material3.darkColorScheme
88
import androidx.compose.material3.dynamicDarkColorScheme
99
import androidx.compose.material3.dynamicLightColorScheme
10+
import androidx.compose.material3.lightColorScheme
1011
import androidx.compose.runtime.Composable
12+
import androidx.compose.ui.graphics.Color
1113
import androidx.compose.ui.platform.LocalContext
14+
import com.google.android.material.color.MaterialColors
1215

1316

1417
private val LightColors = lightColorScheme(
@@ -51,17 +54,26 @@ private val DarkColors = darkColorScheme(
5154
@Composable
5255
fun AppTheme(
5356
useDarkTheme: Boolean = isSystemInDarkTheme(),
57+
context: Context? = null,
5458
content: @Composable () -> Unit
5559
) {
5660
// Dynamic color is available on Android 12+
5761
val dynamicColor = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
58-
val colors = when {
62+
var colors = when {
5963
dynamicColor && useDarkTheme -> dynamicDarkColorScheme(LocalContext.current)
6064
dynamicColor && !useDarkTheme -> dynamicLightColorScheme(LocalContext.current)
6165
useDarkTheme -> DarkColors
6266
else -> LightColors
6367
}
6468

69+
// Applies right surface color
70+
// Material3 view based lib already uses it, but compose stable one not
71+
// Using version 1.2.0-rc01 breaks sliders, thx Google
72+
if (dynamicColor && context != null) {
73+
val newSurfaceColor = MaterialColors.getColor(context, com.google.android.material.R.attr.colorSurface, "")
74+
colors = colors.copy(surface = Color(newSurfaceColor), background = Color(newSurfaceColor))
75+
}
76+
6577
MaterialTheme(
6678
colorScheme = colors,
6779
content = content

0 commit comments

Comments
 (0)