Skip to content

Commit 133dfaa

Browse files
committed
Added a do example for GoodButton
1 parent fcf06d9 commit 133dfaa

File tree

1 file changed

+29
-0
lines changed
  • compose/snippets/src/main/java/com/example/compose/snippets/designsystems/styles

1 file changed

+29
-0
lines changed

compose/snippets/src/main/java/com/example/compose/snippets/designsystems/styles/DosDonts.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818

1919
package com.example.compose.snippets.designsystems.styles
2020

21+
import androidx.compose.foundation.interaction.MutableInteractionSource
22+
import androidx.compose.foundation.layout.Box
2123
import androidx.compose.foundation.style.ExperimentalFoundationStyleApi
24+
import androidx.compose.foundation.style.MutableStyleState
2225
import androidx.compose.foundation.style.Style
26+
import androidx.compose.foundation.style.styleable
2327
import androidx.compose.runtime.Composable
28+
import androidx.compose.runtime.remember
2429
import androidx.compose.ui.Modifier
2530
import androidx.compose.ui.graphics.Color
2631

@@ -77,3 +82,27 @@ fun BadButton(
7782
) {
7883
}
7984
// [END android_compose_styles_donts_default_style]
85+
86+
// [START android_compose_styles_do_default_style]
87+
@Composable
88+
fun GoodButton(
89+
modifier: Modifier = Modifier,
90+
// ✅ Do: always pass it as a Style, do not pass other defaults
91+
style: Style = Style
92+
) {
93+
// [START_EXCLUDE]
94+
// this is a snippet of the BaseButton - see the full snippet in /components/Button.kt
95+
val effectiveInteractionSource = remember {
96+
MutableInteractionSource()
97+
}
98+
val styleState = remember(effectiveInteractionSource) {
99+
MutableStyleState(effectiveInteractionSource)
100+
}
101+
// [END_EXCLUDE]
102+
val defaultStyle = Style { background(Color.Red) }
103+
// ✅ Do Combine defaults inside with incoming parameter
104+
Box(modifier = modifier.styleable(styleState, defaultStyle, style)) {
105+
// your logic
106+
}
107+
}
108+
// [END android_compose_styles_do_default_style]

0 commit comments

Comments
 (0)