Skip to content

Commit 6eedaf3

Browse files
authored
Merge branch 'main' into latest
2 parents 7045d7d + 5bbe640 commit 6eedaf3

File tree

2 files changed

+41
-47
lines changed

2 files changed

+41
-47
lines changed

compose/snippets/src/main/java/com/example/compose/snippets/designsystems/CustomDesignSystem.kt

+12-26
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,10 @@ import androidx.compose.ui.unit.Dp
3939
import androidx.compose.ui.unit.dp
4040
import androidx.compose.ui.unit.sp
4141

42-
/*
43-
* Copyright 2022 The Android Open Source Project
44-
*
45-
* Licensed under the Apache License, Version 2.0 (the "License");
46-
* you may not use this file except in compliance with the License.
47-
* You may obtain a copy of the License at
48-
*
49-
* http://www.apache.org/licenses/LICENSE-2.0
50-
*
51-
* Unless required by applicable law or agreed to in writing, software
52-
* distributed under the License is distributed on an "AS IS" BASIS,
53-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
54-
* See the License for the specific language governing permissions and
55-
* limitations under the License.
56-
*/
5742
private object CustomDesignSystemExtend {
5843
// [START android_compose_designsystems_custom_extend]
59-
// Use with MaterialTheme.colors.snackbarAction
6044

45+
// Use with MaterialTheme.colorScheme.snackbarAction
6146
val ColorScheme.snackbarAction: Color
6247
@Composable
6348
get() = if (isSystemInDarkTheme()) Red300 else Red700
@@ -79,14 +64,14 @@ private object CustomDesignSystemExtendTheme {
7964
// [START android_compose_designsystems_custom_extend_theme]
8065
@Immutable
8166
data class ExtendedColors(
82-
val tertiary: Color,
83-
val onTertiary: Color
67+
val caution: Color,
68+
val onCaution: Color
8469
)
8570

8671
val LocalExtendedColors = staticCompositionLocalOf {
8772
ExtendedColors(
88-
tertiary = Color.Unspecified,
89-
onTertiary = Color.Unspecified
73+
caution = Color.Unspecified,
74+
onCaution = Color.Unspecified
9075
)
9176
}
9277

@@ -96,8 +81,8 @@ private object CustomDesignSystemExtendTheme {
9681
content: @Composable () -> Unit
9782
) {
9883
val extendedColors = ExtendedColors(
99-
tertiary = Color(0xFFA8EFF0),
100-
onTertiary = Color(0xFF002021)
84+
caution = Color(0xFFFFCC02),
85+
onCaution = Color(0xFF2C2D30)
10186
)
10287
CompositionLocalProvider(LocalExtendedColors provides extendedColors) {
10388
MaterialTheme(
@@ -107,7 +92,7 @@ private object CustomDesignSystemExtendTheme {
10792
}
10893
}
10994

110-
// Use with eg. ExtendedTheme.colors.tertiary
95+
// Use with eg. ExtendedTheme.colors.caution
11196
object ExtendedTheme {
11297
val colors: ExtendedColors
11398
@Composable
@@ -124,8 +109,8 @@ private object CustomDesignSystemExtendTheme {
124109
) {
125110
Button(
126111
colors = ButtonDefaults.buttonColors(
127-
containerColor = ExtendedTheme.colors.tertiary,
128-
contentColor = ExtendedTheme.colors.onTertiary
112+
containerColor = ExtendedTheme.colors.caution,
113+
contentColor = ExtendedTheme.colors.onCaution
129114
/* Other colors use values from MaterialTheme */
130115
),
131116
onClick = onClick,
@@ -341,7 +326,8 @@ object FullyCustomDesignSystem {
341326
.copy(alpha = 0.12f)
342327
.compositeOver(CustomTheme.colors.component),
343328
disabledContentColor = CustomTheme.colors.content
344-
.copy(alpha = 0.5f)
329+
.copy(alpha = 0.38f)
330+
345331
),
346332
shape = ButtonShape,
347333
elevation = ButtonDefaults.elevatedButtonElevation(

compose/snippets/src/main/java/com/example/compose/snippets/state/CompositionLocalSnippets.kt

+29-21
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ import androidx.activity.ComponentActivity
2121
import androidx.activity.compose.setContent
2222
import androidx.compose.foundation.isSystemInDarkTheme
2323
import androidx.compose.foundation.layout.Column
24-
import androidx.compose.material.Button
25-
import androidx.compose.material.Card
26-
import androidx.compose.material.Colors
27-
import androidx.compose.material.ContentAlpha
28-
import androidx.compose.material.LocalContentAlpha
29-
import androidx.compose.material.MaterialTheme
30-
import androidx.compose.material.Text
31-
import androidx.compose.material.lightColors
24+
import androidx.compose.material3.Button
25+
import androidx.compose.material3.ColorScheme
26+
import androidx.compose.material3.LocalContentColor
27+
import androidx.compose.material3.MaterialTheme
28+
import androidx.compose.material3.Surface
29+
import androidx.compose.material3.Text
30+
import androidx.compose.material3.lightColorScheme
3231
import androidx.compose.runtime.Composable
3332
import androidx.compose.runtime.CompositionLocalProvider
3433
import androidx.compose.runtime.compositionLocalOf
@@ -67,7 +66,7 @@ object CompositionLocalSnippets2 {
6766
fun MyApp() {
6867
// Provides a Theme whose values are propagated down its `content`
6968
MaterialTheme {
70-
// New values for colors, typography, and shapes are available
69+
// New values for colorScheme, typography, and shapes are available
7170
// in MaterialTheme's content lambda.
7271

7372
// ... content here ...
@@ -81,7 +80,7 @@ object CompositionLocalSnippets2 {
8180
text = labelText,
8281
// `primary` is obtained from MaterialTheme's
8382
// LocalColors CompositionLocal
84-
color = MaterialTheme.colors.primary
83+
color = MaterialTheme.colorScheme.primary
8584
)
8685
}
8786
// [END android_compose_state_compositionlocal2]
@@ -91,14 +90,19 @@ object CompositionLocalSnippets3 {
9190
// [START android_compose_state_compositionlocal3]
9291
@Composable
9392
fun CompositionLocalExample() {
94-
MaterialTheme { // MaterialTheme sets ContentAlpha.high as default
95-
Column {
96-
Text("Uses MaterialTheme's provided alpha")
97-
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
98-
Text("Medium value provided for LocalContentAlpha")
99-
Text("This Text also uses the medium value")
100-
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.disabled) {
101-
DescendantExample()
93+
MaterialTheme {
94+
// Surface provides contentColorFor(MaterialTheme.colorScheme.surface) by default
95+
// This is to automatically make text and other content contrast to the background
96+
// correctly.
97+
Surface {
98+
Column {
99+
Text("Uses Surface's provided content color")
100+
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.primary) {
101+
Text("Primary color provided by LocalContentColor")
102+
Text("This Text also uses primary as textColor")
103+
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.error) {
104+
DescendantExample()
105+
}
102106
}
103107
}
104108
}
@@ -108,7 +112,7 @@ object CompositionLocalSnippets3 {
108112
@Composable
109113
fun DescendantExample() {
110114
// CompositionLocalProviders also work across composable functions
111-
Text("This Text uses the disabled alpha now")
115+
Text("This Text uses the error color now")
112116
}
113117
// [END android_compose_state_compositionlocal3]
114118
}
@@ -169,11 +173,15 @@ object CompositionLocalSnippets5_6_7 {
169173
fun SomeComposable() {
170174
// Access the globally defined LocalElevations variable to get the
171175
// current Elevations in this part of the Composition
172-
Card(elevation = LocalElevations.current.card) {
176+
MyCard(elevation = LocalElevations.current.card) {
173177
// Content
174178
}
175179
}
176180
// [END android_compose_state_compositionlocal7]
181+
182+
@Composable
183+
fun MyCard(elevation: Dp, content: @Composable () -> Unit) {
184+
}
177185
}
178186

179187
object CompositionLocalSnippets8 {
@@ -267,7 +275,7 @@ object CompositionLocalSnippets11 {
267275
/***
268276
* Fakes
269277
*/
270-
fun colors(): Colors = lightColors()
278+
fun colors(): ColorScheme = lightColorScheme()
271279

272280
data class DataToDisplay(val title: String)
273281
class MyViewModel : ViewModel() {

0 commit comments

Comments
 (0)