Skip to content

Commit e386f97

Browse files
committedFeb 3, 2020
Monthly button refactoring
- Removes string overload for Button - Replaces ButtonStyle with distinct functions, the following is the migration strategy: ContainedButtonStyle -> Button OutlinedButtonStyle -> OutlinedButton TextButtonStyle -> TextButton Custom ButtonStyle -> Any / which ever is most semantically related Now that each function takes the same parameters, and there are no overloads, there is no more large separation between layers - extra customization is just a matter of supplying more parameters, instead of needing to find overloads / copy and paste parameters from high level styles into the base ButtonStyle. Also adds sample for Modifiers so the samples won't break when API changes like this are made. Bug: b/146478620 Bug: b/146482131 Bug: b/146346551 Test: ButtonTest Change-Id: If63ab32bd3f12050a2d2f4b8c0cb044bc7144a6b Relnote: "Replaced ButtonStyle with distinct functions and removed text (string) overload. See updated samples for usage information."
1 parent 03aa199 commit e386f97

File tree

29 files changed

+401
-449
lines changed

29 files changed

+401
-449
lines changed
 

‎compose/compose-runtime/integration-tests/samples/src/main/java/androidx/compose/samples/EffectSamples.kt‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ fun SimpleStateSample() {
5959
val count = state { 0 }
6060

6161
Text(text = "You clicked ${count.value} times")
62-
Button(text = "Click me", onClick = { count.value++ })
62+
Button(onClick = { count.value++ }) {
63+
Text("Click me")
64+
}
6365
}
6466

6567
@Sampled
@@ -68,7 +70,9 @@ fun DestructuredStateSample() {
6870
val (count, setCount) = state { 0 }
6971

7072
Text(text = "You clicked $count times")
71-
Button(text = "Click me", onClick = { setCount(count + 1) })
73+
Button(onClick = { setCount(count + 1) }) {
74+
Text("Click me")
75+
}
7276
}
7377

7478
// TODO: operator assignment for local delegated properties is currently not supported
@@ -80,7 +84,9 @@ fun DelegatedStateSample() {
8084
var count by state { 0 }
8185

8286
Text(text = "You clicked $count times")
83-
Button(text = "Click me", onClick = { count = count + 1 })
87+
Button(onClick = { count = count + 1 }) {
88+
Text("Click me")
89+
}
8490
}
8591

8692
private class Subscription {

‎compose/compose-runtime/integration-tests/samples/src/main/java/androidx/compose/samples/ModelSamples.kt‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import androidx.annotation.Sampled
2020
import androidx.compose.Composable
2121
import androidx.compose.Model
2222
import androidx.compose.remember
23+
import androidx.ui.core.Text
2324
import androidx.ui.core.TextField
2425
import androidx.ui.material.Button
2526

@@ -43,6 +44,8 @@ fun modelSample() {
4344
value = model.password,
4445
onValueChange = { model.password = it }
4546
)
46-
Button(text = "Login", onClick = { model.login() })
47+
Button(onClick = { model.login() }) {
48+
Text("Login")
49+
}
4750
}
4851
}

‎compose/compose-runtime/integration-tests/samples/src/main/java/androidx/compose/samples/RecomposeSamples.kt‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import androidx.annotation.Sampled
2020
import androidx.compose.Composable
2121
import androidx.compose.Recompose
2222
import androidx.compose.remember
23+
import androidx.ui.core.Text
2324
import androidx.ui.core.TextField
2425
import androidx.ui.material.Button
2526

@@ -49,7 +50,9 @@ fun recomposeSample() {
4950
recompose()
5051
}
5152
)
52-
Button(text = "Login", onClick = { model.login() })
53+
Button(onClick = { model.login() }) {
54+
Text("Login")
55+
}
5356
}
5457
}
5558
}

‎ui/ui-android-view/integration-tests/android-view-demos/src/main/java/androidx/ui/androidview/demos/ViewInCompose.kt‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,18 @@ class ViewInCompose : Activity() {
7272
FrameLayout {
7373
ColoredSquareView(size = 200, color = Color.Cyan, ref = squareRef)
7474
}
75-
Button(
76-
text = "Increase size of Android view",
77-
onClick = { squareRef.value!!.size += 50 }
78-
)
75+
Button(onClick = { squareRef.value!!.size += 50 }) {
76+
Text("Increase size of Android view")
77+
}
7978
val colorIndex = state { 0 }
80-
Button(text = "Change color of Android view", onClick = {
79+
Button(onClick = {
8180
colorIndex.value = (colorIndex.value + 1) % 4
8281
squareRef.value!!.color = arrayOf(
8382
Color.Blue, Color.LightGray, Color.Yellow, Color.Cyan
8483
)[colorIndex.value]
85-
})
84+
}) {
85+
Text("Change color of Android view")
86+
}
8687

8788
// Inflate AndroidView from XML and change it in callback post inflation.
8889
AndroidView(R.layout.test_layout) { view ->

‎ui/ui-core/integration-tests/samples/build.gradle‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ dependencies {
3434

3535
implementation project(":compose:compose-runtime")
3636
implementation project(":ui:ui-core")
37-
implementation project(":ui:ui-framework")
37+
implementation project(":ui:ui-layout")
38+
implementation project(":ui:ui-material")
3839
}
3940

4041
android {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2019 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
@file:Suppress("unused")
18+
19+
package androidx.ui.core.samples
20+
21+
import androidx.annotation.Sampled
22+
import androidx.compose.Composable
23+
import androidx.ui.core.Modifier
24+
import androidx.ui.core.Text
25+
import androidx.ui.layout.Column
26+
import androidx.ui.layout.LayoutPadding
27+
import androidx.ui.layout.Row
28+
import androidx.ui.material.Button
29+
import androidx.ui.unit.dp
30+
31+
@Sampled
32+
@Composable
33+
fun ModifierParameterSample() {
34+
@Composable
35+
fun PaddedColumn(modifier: Modifier = Modifier.None) {
36+
Column(modifier + LayoutPadding(10.dp)) {
37+
// ...
38+
}
39+
}
40+
}
41+
42+
@Sampled
43+
@Composable
44+
fun SubcomponentModifierSample() {
45+
@Composable
46+
fun ButtonBar(
47+
onOk: () -> Unit,
48+
onCancel: () -> Unit,
49+
modifier: Modifier = Modifier.None,
50+
buttonModifier: Modifier = Modifier.None
51+
) {
52+
Row(modifier) {
53+
Button(buttonModifier, onClick = onCancel) {
54+
Text("Cancel")
55+
}
56+
Button(buttonModifier, onClick = onOk) {
57+
Text("Ok")
58+
}
59+
}
60+
}
61+
}
62+
63+
private val defaultFooModifier = Modifier.None

‎ui/ui-core/src/main/java/androidx/ui/core/Modifier.kt‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ import androidx.compose.Stable
3838
* parameter's value in the composable function's implementation, keeping [Modifier.None] as the
3939
* default parameter value. For example:
4040
*
41-
* @Composable fun Foo(modifier: Modifier = Modifier.None) {
42-
* Column(modifier + defaultFooModifier) {
43-
* // ...
44-
* }
45-
* }
41+
* @sample androidx.ui.core.samples.ModifierParameterSample
4642
*
4743
* The pattern above allows default modifiers to still be applied as part of the chain
4844
* if a caller also supplies unrelated modifiers.
@@ -52,17 +48,7 @@ import androidx.compose.Stable
5248
* and behavior. Subcomponent modifiers should be grouped together and follow the parent
5349
* composable's modifier. For example:
5450
*
55-
* @Composable fun ButtonBar(
56-
* onOk: () -> Unit,
57-
* onCancel: () -> Unit,
58-
* modifier: Modifier = Modifier.None,
59-
* buttonModifier: Modifier = Modifier.None
60-
* ) {
61-
* Row(modifier) {
62-
* Button("Cancel", buttonModifier, onClick = onCancel)
63-
* Button("Ok", buttonModifier, onClick = onOk)
64-
* }
65-
* }
51+
* @sample androidx.ui.core.samples.SubcomponentModifierSample
6652
*/
6753
@Stable
6854
interface Modifier {

‎ui/ui-framework/integration-tests/framework-demos/src/main/java/androidx/ui/framework/demos/SemanticsL1.kt‎

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ private fun InvokeActionsByType(actions: Set<SemanticAction<out Any?>> = setOf()
194194
actions.firstOrNull { it.types.contains(AccessibilityAction.Secondary) }
195195
Text(text = "Accessibility Actions By Type", style = MaterialTheme.typography().h6)
196196
Row(LayoutWidth.Fill, arrangement = Arrangement.SpaceEvenly) {
197-
Button(
198-
text = "Primary",
199-
onClick = { primary?.invoke(ActionCaller.Accessibility) })
200-
Button(text = "Secondary", onClick = {
201-
secondary?.invoke(ActionCaller.Accessibility)
202-
})
197+
Button(onClick = { primary?.invoke(ActionCaller.Accessibility) }) {
198+
Text("Primary")
199+
}
200+
Button(onClick = { secondary?.invoke(ActionCaller.Accessibility) }) {
201+
Text("Secondary")
202+
}
203203
}
204204
}
205205

@@ -213,9 +213,9 @@ private fun InvokeActionsByPhrase(actions: Set<SemanticAction<out Any?>> = setOf
213213
style = MaterialTheme.typography().h6)
214214
Row(LayoutWidth.Fill, arrangement = Arrangement.SpaceEvenly) {
215215
actions.forEach {
216-
Button(
217-
text = it.phrase,
218-
onClick = { it.invoke(ActionCaller.Accessibility) })
216+
Button(onClick = { it.invoke(ActionCaller.Accessibility) }) {
217+
Text(it.phrase)
218+
}
219219
}
220220
}
221221
}
@@ -229,12 +229,12 @@ private fun InvokeActionsByAssistantAction(actions: Set<SemanticAction<out Any?>
229229
val negative = actions.firstOrNull { it.types.contains(PolarityAction.Negative) }
230230
Text(text = "Assistant Actions", style = MaterialTheme.typography().h6)
231231
Row(LayoutWidth.Fill, arrangement = Arrangement.SpaceEvenly) {
232-
Button(
233-
text = "Negative",
234-
onClick = { negative?.invoke(ActionCaller.Assistant) })
235-
Button(
236-
text = "Positive",
237-
onClick = { positive?.invoke(ActionCaller.Assistant) })
232+
Button(onClick = { negative?.invoke(ActionCaller.Assistant) }) {
233+
Text("Negative")
234+
}
235+
Button(onClick = { positive?.invoke(ActionCaller.Assistant) }) {
236+
Text("Positive")
237+
}
238238
}
239239
}
240240

@@ -253,12 +253,12 @@ private fun InvokeActionsByParameters(actions: Set<SemanticAction<out Any?>> = s
253253
actions.firstOrNull { it.defaultParam is Unit } as SemanticAction<Unit>?
254254
Text(text = "Actions using Parameters", style = MaterialTheme.typography().h6)
255255
Row(LayoutWidth.Fill, arrangement = Arrangement.SpaceEvenly) {
256-
Button(
257-
text = "IntAction",
258-
onClick = { pxPositionAction?.invoke(param = PxPosition(1.px, 1.px)) })
259-
Button(
260-
text = "VoidAction",
261-
onClick = { unitAction?.invoke(param = Unit) })
256+
Button(onClick = { pxPositionAction?.invoke(param = PxPosition(1.px, 1.px)) }) {
257+
Text("IntAction")
258+
}
259+
Button(onClick = { unitAction?.invoke(param = Unit) }) {
260+
Text("VoidAction")
261+
}
262262
}
263263
}
264264

@@ -277,12 +277,14 @@ private fun Collapsable(children: @Composable() () -> Unit) {
277277
val collapsedState = state { CollapseMode.Collapsed }
278278

279279
Row(LayoutWidth.Fill, arrangement = Arrangement.SpaceEvenly) {
280-
Button(text = "Show/Hide Actions", onClick = {
280+
Button(onClick = {
281281
collapsedState.value = when (collapsedState.value) {
282282
CollapseMode.Collapsed -> CollapseMode.Visible
283283
CollapseMode.Visible -> CollapseMode.Collapsed
284284
}
285-
})
285+
}) {
286+
Text("Show/Hide Actions")
287+
}
286288
}
287289

288290
if (collapsedState.value == CollapseMode.Visible) {

‎ui/ui-material/api/0.1.0-dev05.txt‎

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,9 @@ package androidx.ui.material {
3333
}
3434

3535
public final class ButtonKt {
36-
method public static void Button(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.material.ButtonStyle style = ContainedButtonStyle(), kotlin.jvm.functions.Function0<kotlin.Unit> children);
37-
method public static void Button(String text, androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.material.ButtonStyle style = ContainedButtonStyle());
38-
method public static androidx.ui.material.ButtonStyle ContainedButtonStyle(androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().primary, androidx.ui.graphics.Color contentColor = contentColorFor(backgroundColor), androidx.ui.graphics.Shape shape = button, androidx.ui.unit.Dp elevation = 2.dp);
39-
method public static androidx.ui.material.ButtonStyle OutlinedButtonStyle(androidx.ui.foundation.Border border = Border(1.dp, MaterialTheme.colors().onSurface.copy(OutlinedStrokeOpacity)), androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().surface, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.unit.Dp elevation = 0.dp);
40-
method public static androidx.ui.material.ButtonStyle TextButtonStyle(androidx.ui.graphics.Shape shape = button, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary);
41-
}
42-
43-
public final class ButtonStyle {
44-
ctor public ButtonStyle(androidx.ui.graphics.Color backgroundColor, androidx.ui.graphics.Color contentColor, androidx.ui.graphics.Shape shape, androidx.ui.foundation.Border? border, androidx.ui.unit.Dp elevation, androidx.ui.layout.EdgeInsets paddings);
45-
method public androidx.ui.graphics.Color component1();
46-
method public androidx.ui.graphics.Color component2();
47-
method public androidx.ui.graphics.Shape component3();
48-
method public androidx.ui.foundation.Border? component4();
49-
method public androidx.ui.unit.Dp component5();
50-
method public androidx.ui.layout.EdgeInsets component6();
51-
method public androidx.ui.material.ButtonStyle copy(androidx.ui.graphics.Color backgroundColor, androidx.ui.graphics.Color contentColor, androidx.ui.graphics.Shape shape, androidx.ui.foundation.Border? border, androidx.ui.unit.Dp elevation, androidx.ui.layout.EdgeInsets paddings);
52-
method public androidx.ui.graphics.Color getBackgroundColor();
53-
method public androidx.ui.foundation.Border? getBorder();
54-
method public androidx.ui.graphics.Color getContentColor();
55-
method public androidx.ui.unit.Dp getElevation();
56-
method public androidx.ui.layout.EdgeInsets getPaddings();
57-
method public androidx.ui.graphics.Shape getShape();
36+
method public static void Button(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().primary, androidx.ui.graphics.Color contentColor = contentColorFor(backgroundColor), androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = null, androidx.ui.unit.Dp elevation = 2.dp, androidx.ui.layout.EdgeInsets paddings = ButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
37+
method public static inline void OutlinedButton(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().surface, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = Border(1.dp, MaterialTheme.colors().onSurface.copy(OutlinedStrokeOpacity)), androidx.ui.unit.Dp elevation = 0.dp, androidx.ui.layout.EdgeInsets paddings = ButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
38+
method public static inline void TextButton(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = Color.Transparent, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = null, androidx.ui.unit.Dp elevation = 0.dp, androidx.ui.layout.EdgeInsets paddings = TextButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
5839
}
5940

6041
public final class CheckboxKt {

‎ui/ui-material/api/current.txt‎

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,9 @@ package androidx.ui.material {
3333
}
3434

3535
public final class ButtonKt {
36-
method public static void Button(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.material.ButtonStyle style = ContainedButtonStyle(), kotlin.jvm.functions.Function0<kotlin.Unit> children);
37-
method public static void Button(String text, androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.material.ButtonStyle style = ContainedButtonStyle());
38-
method public static androidx.ui.material.ButtonStyle ContainedButtonStyle(androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().primary, androidx.ui.graphics.Color contentColor = contentColorFor(backgroundColor), androidx.ui.graphics.Shape shape = button, androidx.ui.unit.Dp elevation = 2.dp);
39-
method public static androidx.ui.material.ButtonStyle OutlinedButtonStyle(androidx.ui.foundation.Border border = Border(1.dp, MaterialTheme.colors().onSurface.copy(OutlinedStrokeOpacity)), androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().surface, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.unit.Dp elevation = 0.dp);
40-
method public static androidx.ui.material.ButtonStyle TextButtonStyle(androidx.ui.graphics.Shape shape = button, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary);
41-
}
42-
43-
public final class ButtonStyle {
44-
ctor public ButtonStyle(androidx.ui.graphics.Color backgroundColor, androidx.ui.graphics.Color contentColor, androidx.ui.graphics.Shape shape, androidx.ui.foundation.Border? border, androidx.ui.unit.Dp elevation, androidx.ui.layout.EdgeInsets paddings);
45-
method public androidx.ui.graphics.Color component1();
46-
method public androidx.ui.graphics.Color component2();
47-
method public androidx.ui.graphics.Shape component3();
48-
method public androidx.ui.foundation.Border? component4();
49-
method public androidx.ui.unit.Dp component5();
50-
method public androidx.ui.layout.EdgeInsets component6();
51-
method public androidx.ui.material.ButtonStyle copy(androidx.ui.graphics.Color backgroundColor, androidx.ui.graphics.Color contentColor, androidx.ui.graphics.Shape shape, androidx.ui.foundation.Border? border, androidx.ui.unit.Dp elevation, androidx.ui.layout.EdgeInsets paddings);
52-
method public androidx.ui.graphics.Color getBackgroundColor();
53-
method public androidx.ui.foundation.Border? getBorder();
54-
method public androidx.ui.graphics.Color getContentColor();
55-
method public androidx.ui.unit.Dp getElevation();
56-
method public androidx.ui.layout.EdgeInsets getPaddings();
57-
method public androidx.ui.graphics.Shape getShape();
36+
method public static void Button(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().primary, androidx.ui.graphics.Color contentColor = contentColorFor(backgroundColor), androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = null, androidx.ui.unit.Dp elevation = 2.dp, androidx.ui.layout.EdgeInsets paddings = ButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
37+
method public static inline void OutlinedButton(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().surface, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = Border(1.dp, MaterialTheme.colors().onSurface.copy(OutlinedStrokeOpacity)), androidx.ui.unit.Dp elevation = 0.dp, androidx.ui.layout.EdgeInsets paddings = ButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
38+
method public static inline void TextButton(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = Color.Transparent, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = null, androidx.ui.unit.Dp elevation = 0.dp, androidx.ui.layout.EdgeInsets paddings = TextButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
5839
}
5940

6041
public final class CheckboxKt {

‎ui/ui-material/api/public_plus_experimental_0.1.0-dev05.txt‎

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,9 @@ package androidx.ui.material {
3333
}
3434

3535
public final class ButtonKt {
36-
method public static void Button(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.material.ButtonStyle style = ContainedButtonStyle(), kotlin.jvm.functions.Function0<kotlin.Unit> children);
37-
method public static void Button(String text, androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.material.ButtonStyle style = ContainedButtonStyle());
38-
method public static androidx.ui.material.ButtonStyle ContainedButtonStyle(androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().primary, androidx.ui.graphics.Color contentColor = contentColorFor(backgroundColor), androidx.ui.graphics.Shape shape = button, androidx.ui.unit.Dp elevation = 2.dp);
39-
method public static androidx.ui.material.ButtonStyle OutlinedButtonStyle(androidx.ui.foundation.Border border = Border(1.dp, MaterialTheme.colors().onSurface.copy(OutlinedStrokeOpacity)), androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().surface, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.unit.Dp elevation = 0.dp);
40-
method public static androidx.ui.material.ButtonStyle TextButtonStyle(androidx.ui.graphics.Shape shape = button, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary);
41-
}
42-
43-
public final class ButtonStyle {
44-
ctor public ButtonStyle(androidx.ui.graphics.Color backgroundColor, androidx.ui.graphics.Color contentColor, androidx.ui.graphics.Shape shape, androidx.ui.foundation.Border? border, androidx.ui.unit.Dp elevation, androidx.ui.layout.EdgeInsets paddings);
45-
method public androidx.ui.graphics.Color component1();
46-
method public androidx.ui.graphics.Color component2();
47-
method public androidx.ui.graphics.Shape component3();
48-
method public androidx.ui.foundation.Border? component4();
49-
method public androidx.ui.unit.Dp component5();
50-
method public androidx.ui.layout.EdgeInsets component6();
51-
method public androidx.ui.material.ButtonStyle copy(androidx.ui.graphics.Color backgroundColor, androidx.ui.graphics.Color contentColor, androidx.ui.graphics.Shape shape, androidx.ui.foundation.Border? border, androidx.ui.unit.Dp elevation, androidx.ui.layout.EdgeInsets paddings);
52-
method public androidx.ui.graphics.Color getBackgroundColor();
53-
method public androidx.ui.foundation.Border? getBorder();
54-
method public androidx.ui.graphics.Color getContentColor();
55-
method public androidx.ui.unit.Dp getElevation();
56-
method public androidx.ui.layout.EdgeInsets getPaddings();
57-
method public androidx.ui.graphics.Shape getShape();
36+
method public static void Button(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().primary, androidx.ui.graphics.Color contentColor = contentColorFor(backgroundColor), androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = null, androidx.ui.unit.Dp elevation = 2.dp, androidx.ui.layout.EdgeInsets paddings = ButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
37+
method public static inline void OutlinedButton(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().surface, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = Border(1.dp, MaterialTheme.colors().onSurface.copy(OutlinedStrokeOpacity)), androidx.ui.unit.Dp elevation = 0.dp, androidx.ui.layout.EdgeInsets paddings = ButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
38+
method public static inline void TextButton(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = Color.Transparent, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = null, androidx.ui.unit.Dp elevation = 0.dp, androidx.ui.layout.EdgeInsets paddings = TextButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
5839
}
5940

6041
public final class CheckboxKt {

‎ui/ui-material/api/public_plus_experimental_current.txt‎

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,9 @@ package androidx.ui.material {
3333
}
3434

3535
public final class ButtonKt {
36-
method public static void Button(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.material.ButtonStyle style = ContainedButtonStyle(), kotlin.jvm.functions.Function0<kotlin.Unit> children);
37-
method public static void Button(String text, androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.material.ButtonStyle style = ContainedButtonStyle());
38-
method public static androidx.ui.material.ButtonStyle ContainedButtonStyle(androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().primary, androidx.ui.graphics.Color contentColor = contentColorFor(backgroundColor), androidx.ui.graphics.Shape shape = button, androidx.ui.unit.Dp elevation = 2.dp);
39-
method public static androidx.ui.material.ButtonStyle OutlinedButtonStyle(androidx.ui.foundation.Border border = Border(1.dp, MaterialTheme.colors().onSurface.copy(OutlinedStrokeOpacity)), androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().surface, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.unit.Dp elevation = 0.dp);
40-
method public static androidx.ui.material.ButtonStyle TextButtonStyle(androidx.ui.graphics.Shape shape = button, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary);
41-
}
42-
43-
public final class ButtonStyle {
44-
ctor public ButtonStyle(androidx.ui.graphics.Color backgroundColor, androidx.ui.graphics.Color contentColor, androidx.ui.graphics.Shape shape, androidx.ui.foundation.Border? border, androidx.ui.unit.Dp elevation, androidx.ui.layout.EdgeInsets paddings);
45-
method public androidx.ui.graphics.Color component1();
46-
method public androidx.ui.graphics.Color component2();
47-
method public androidx.ui.graphics.Shape component3();
48-
method public androidx.ui.foundation.Border? component4();
49-
method public androidx.ui.unit.Dp component5();
50-
method public androidx.ui.layout.EdgeInsets component6();
51-
method public androidx.ui.material.ButtonStyle copy(androidx.ui.graphics.Color backgroundColor, androidx.ui.graphics.Color contentColor, androidx.ui.graphics.Shape shape, androidx.ui.foundation.Border? border, androidx.ui.unit.Dp elevation, androidx.ui.layout.EdgeInsets paddings);
52-
method public androidx.ui.graphics.Color getBackgroundColor();
53-
method public androidx.ui.foundation.Border? getBorder();
54-
method public androidx.ui.graphics.Color getContentColor();
55-
method public androidx.ui.unit.Dp getElevation();
56-
method public androidx.ui.layout.EdgeInsets getPaddings();
57-
method public androidx.ui.graphics.Shape getShape();
36+
method public static void Button(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().primary, androidx.ui.graphics.Color contentColor = contentColorFor(backgroundColor), androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = null, androidx.ui.unit.Dp elevation = 2.dp, androidx.ui.layout.EdgeInsets paddings = ButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
37+
method public static inline void OutlinedButton(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().surface, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = Border(1.dp, MaterialTheme.colors().onSurface.copy(OutlinedStrokeOpacity)), androidx.ui.unit.Dp elevation = 0.dp, androidx.ui.layout.EdgeInsets paddings = ButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
38+
method public static inline void TextButton(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = Color.Transparent, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = null, androidx.ui.unit.Dp elevation = 0.dp, androidx.ui.layout.EdgeInsets paddings = TextButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
5839
}
5940

6041
public final class CheckboxKt {

‎ui/ui-material/api/restricted_0.1.0-dev05.txt‎

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,9 @@ package androidx.ui.material {
3333
}
3434

3535
public final class ButtonKt {
36-
method public static void Button(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.material.ButtonStyle style = ContainedButtonStyle(), kotlin.jvm.functions.Function0<kotlin.Unit> children);
37-
method public static void Button(String text, androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.material.ButtonStyle style = ContainedButtonStyle());
38-
method public static androidx.ui.material.ButtonStyle ContainedButtonStyle(androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().primary, androidx.ui.graphics.Color contentColor = contentColorFor(backgroundColor), androidx.ui.graphics.Shape shape = button, androidx.ui.unit.Dp elevation = 2.dp);
39-
method public static androidx.ui.material.ButtonStyle OutlinedButtonStyle(androidx.ui.foundation.Border border = Border(1.dp, MaterialTheme.colors().onSurface.copy(OutlinedStrokeOpacity)), androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().surface, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.unit.Dp elevation = 0.dp);
40-
method public static androidx.ui.material.ButtonStyle TextButtonStyle(androidx.ui.graphics.Shape shape = button, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary);
41-
}
42-
43-
public final class ButtonStyle {
44-
ctor public ButtonStyle(androidx.ui.graphics.Color backgroundColor, androidx.ui.graphics.Color contentColor, androidx.ui.graphics.Shape shape, androidx.ui.foundation.Border? border, androidx.ui.unit.Dp elevation, androidx.ui.layout.EdgeInsets paddings);
45-
method public androidx.ui.graphics.Color component1();
46-
method public androidx.ui.graphics.Color component2();
47-
method public androidx.ui.graphics.Shape component3();
48-
method public androidx.ui.foundation.Border? component4();
49-
method public androidx.ui.unit.Dp component5();
50-
method public androidx.ui.layout.EdgeInsets component6();
51-
method public androidx.ui.material.ButtonStyle copy(androidx.ui.graphics.Color backgroundColor, androidx.ui.graphics.Color contentColor, androidx.ui.graphics.Shape shape, androidx.ui.foundation.Border? border, androidx.ui.unit.Dp elevation, androidx.ui.layout.EdgeInsets paddings);
52-
method public androidx.ui.graphics.Color getBackgroundColor();
53-
method public androidx.ui.foundation.Border? getBorder();
54-
method public androidx.ui.graphics.Color getContentColor();
55-
method public androidx.ui.unit.Dp getElevation();
56-
method public androidx.ui.layout.EdgeInsets getPaddings();
57-
method public androidx.ui.graphics.Shape getShape();
36+
method public static void Button(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().primary, androidx.ui.graphics.Color contentColor = contentColorFor(backgroundColor), androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = null, androidx.ui.unit.Dp elevation = 2.dp, androidx.ui.layout.EdgeInsets paddings = ButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
37+
method public static inline void OutlinedButton(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().surface, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = Border(1.dp, MaterialTheme.colors().onSurface.copy(OutlinedStrokeOpacity)), androidx.ui.unit.Dp elevation = 0.dp, androidx.ui.layout.EdgeInsets paddings = ButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
38+
method public static inline void TextButton(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = Color.Transparent, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = null, androidx.ui.unit.Dp elevation = 0.dp, androidx.ui.layout.EdgeInsets paddings = TextButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
5839
}
5940

6041
public final class CheckboxKt {

‎ui/ui-material/api/restricted_current.txt‎

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,9 @@ package androidx.ui.material {
3333
}
3434

3535
public final class ButtonKt {
36-
method public static void Button(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.material.ButtonStyle style = ContainedButtonStyle(), kotlin.jvm.functions.Function0<kotlin.Unit> children);
37-
method public static void Button(String text, androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.material.ButtonStyle style = ContainedButtonStyle());
38-
method public static androidx.ui.material.ButtonStyle ContainedButtonStyle(androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().primary, androidx.ui.graphics.Color contentColor = contentColorFor(backgroundColor), androidx.ui.graphics.Shape shape = button, androidx.ui.unit.Dp elevation = 2.dp);
39-
method public static androidx.ui.material.ButtonStyle OutlinedButtonStyle(androidx.ui.foundation.Border border = Border(1.dp, MaterialTheme.colors().onSurface.copy(OutlinedStrokeOpacity)), androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().surface, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.unit.Dp elevation = 0.dp);
40-
method public static androidx.ui.material.ButtonStyle TextButtonStyle(androidx.ui.graphics.Shape shape = button, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary);
41-
}
42-
43-
public final class ButtonStyle {
44-
ctor public ButtonStyle(androidx.ui.graphics.Color backgroundColor, androidx.ui.graphics.Color contentColor, androidx.ui.graphics.Shape shape, androidx.ui.foundation.Border? border, androidx.ui.unit.Dp elevation, androidx.ui.layout.EdgeInsets paddings);
45-
method public androidx.ui.graphics.Color component1();
46-
method public androidx.ui.graphics.Color component2();
47-
method public androidx.ui.graphics.Shape component3();
48-
method public androidx.ui.foundation.Border? component4();
49-
method public androidx.ui.unit.Dp component5();
50-
method public androidx.ui.layout.EdgeInsets component6();
51-
method public androidx.ui.material.ButtonStyle copy(androidx.ui.graphics.Color backgroundColor, androidx.ui.graphics.Color contentColor, androidx.ui.graphics.Shape shape, androidx.ui.foundation.Border? border, androidx.ui.unit.Dp elevation, androidx.ui.layout.EdgeInsets paddings);
52-
method public androidx.ui.graphics.Color getBackgroundColor();
53-
method public androidx.ui.foundation.Border? getBorder();
54-
method public androidx.ui.graphics.Color getContentColor();
55-
method public androidx.ui.unit.Dp getElevation();
56-
method public androidx.ui.layout.EdgeInsets getPaddings();
57-
method public androidx.ui.graphics.Shape getShape();
36+
method public static void Button(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().primary, androidx.ui.graphics.Color contentColor = contentColorFor(backgroundColor), androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = null, androidx.ui.unit.Dp elevation = 2.dp, androidx.ui.layout.EdgeInsets paddings = ButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
37+
method public static inline void OutlinedButton(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = MaterialTheme.colors().surface, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = Border(1.dp, MaterialTheme.colors().onSurface.copy(OutlinedStrokeOpacity)), androidx.ui.unit.Dp elevation = 0.dp, androidx.ui.layout.EdgeInsets paddings = ButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
38+
method public static inline void TextButton(androidx.ui.core.Modifier modifier = Modifier.None, kotlin.jvm.functions.Function0<kotlin.Unit>? onClick = null, androidx.ui.graphics.Color backgroundColor = Color.Transparent, androidx.ui.graphics.Color contentColor = MaterialTheme.colors().primary, androidx.ui.graphics.Shape shape = button, androidx.ui.foundation.Border? border = null, androidx.ui.unit.Dp elevation = 0.dp, androidx.ui.layout.EdgeInsets paddings = TextButtonPaddings, kotlin.jvm.functions.Function0<kotlin.Unit> children);
5839
}
5940

6041
public final class CheckboxKt {

‎ui/ui-material/integration-tests/material-demos/src/main/java/androidx/ui/material/demos/ButtonActivity.kt‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,44 +32,40 @@
3232

3333
package androidx.ui.material.demos
3434

35-
import android.util.Log
3635
import androidx.compose.Composable
36+
import androidx.ui.core.Text
3737
import androidx.ui.layout.Arrangement
3838
import androidx.ui.layout.Center
3939
import androidx.ui.layout.Column
4040
import androidx.ui.layout.LayoutHeight
4141
import androidx.ui.material.Button
42-
import androidx.ui.material.ContainedButtonStyle
4342
import androidx.ui.material.MaterialTheme
44-
import androidx.ui.material.samples.ButtonWithTextSample
45-
import androidx.ui.material.samples.ContainedButtonSample
43+
import androidx.ui.material.samples.ButtonSample
4644
import androidx.ui.material.samples.OutlinedButtonSample
4745
import androidx.ui.material.samples.TextButtonSample
4846

4947
class ButtonActivity : MaterialDemoActivity() {
5048

5149
@Composable
5250
override fun materialContent() {
53-
val onClick: () -> Unit = { Log.e("ButtonDemo", "onClick") }
5451
Center {
5552
Column(LayoutHeight.Fill, arrangement = Arrangement.SpaceEvenly) {
56-
ContainedButtonSample(onClick)
53+
ButtonSample()
5754

58-
OutlinedButtonSample(onClick)
55+
OutlinedButtonSample()
5956

60-
TextButtonSample(onClick)
57+
TextButtonSample()
6158

62-
Button(
63-
text = "SECONDARY COLOR",
64-
onClick = onClick,
65-
style = ContainedButtonStyle(MaterialTheme.colors().secondary))
66-
67-
ButtonWithTextSample(onClick)
59+
Button(backgroundColor = MaterialTheme.colors().secondary, onClick = {}) {
60+
Text("Secondary Color")
61+
}
6862

6963
// TODO(Andrey): Disabled button has wrong bg and text color for now.
7064
// Need to figure out where will we store their styling. Not a part of
7165
// ColorPalette right now and specs are not clear about this.
72-
Button("DISABLED. TODO")
66+
Button {
67+
Text("DISABLED. TODO")
68+
}
7369
}
7470
}
7571
}

‎ui/ui-material/integration-tests/material-demos/src/main/java/androidx/ui/material/demos/CustomShapeActivity.kt‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ import androidx.ui.graphics.Color
2626
import androidx.ui.layout.LayoutSize
2727
import androidx.ui.layout.Spacer
2828
import androidx.ui.layout.Wrap
29-
import androidx.ui.material.Button
30-
import androidx.ui.material.OutlinedButtonStyle
29+
import androidx.ui.material.OutlinedButton
3130
import androidx.ui.unit.dp
3231

3332
class CustomShapeActivity : MaterialDemoActivity() {
@@ -40,13 +39,11 @@ class CustomShapeActivity : MaterialDemoActivity() {
4039
@Composable
4140
override fun materialContent() {
4241
Wrap(Alignment.Center) {
43-
Button(
42+
OutlinedButton(
4443
onClick = {},
45-
style = OutlinedButtonStyle(
46-
shape = TriangleShape,
47-
backgroundColor = Color.Cyan,
48-
border = Border(size = 1.dp, color = Color.DarkGray)
49-
)
44+
shape = TriangleShape,
45+
backgroundColor = Color.Cyan,
46+
border = Border(size = 1.dp, color = Color.DarkGray)
5047
) {
5148
Spacer(LayoutSize(100.dp, 100.dp))
5249
}

‎ui/ui-material/integration-tests/material-demos/src/main/java/androidx/ui/material/demos/TabActivity.kt‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package androidx.ui.material.demos
1818

1919
import androidx.compose.Composable
2020
import androidx.compose.state
21+
import androidx.ui.core.Text
2122
import androidx.ui.graphics.Color
2223
import androidx.ui.graphics.imageFromResource
2324
import androidx.ui.layout.Arrangement
@@ -26,7 +27,6 @@ import androidx.ui.layout.LayoutGravity
2627
import androidx.ui.layout.LayoutHeight
2728
import androidx.ui.layout.Spacer
2829
import androidx.ui.material.Button
29-
import androidx.ui.material.ContainedButtonStyle
3030
import androidx.ui.material.samples.FancyIndicatorContainerTabs
3131
import androidx.ui.material.samples.FancyIndicatorTabs
3232
import androidx.ui.material.samples.FancyTabs
@@ -59,12 +59,13 @@ class TabActivity : MaterialDemoActivity() {
5959
}
6060
Button(
6161
modifier = LayoutGravity.Center,
62-
style = ContainedButtonStyle(backgroundColor = Color.Cyan),
63-
text = buttonText,
6462
onClick = {
6563
showingSimple.value = !showingSimple.value
66-
}
67-
)
64+
},
65+
backgroundColor = Color.Cyan
66+
) {
67+
Text(buttonText)
68+
}
6869
Spacer(LayoutHeight(50.dp))
6970
}
7071
}

‎ui/ui-material/integration-tests/material-studies/src/main/java/androidx/ui/material/studies/rally/RallyAlertDialog.kt‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ import androidx.ui.layout.EdgeInsets
2424
import androidx.ui.layout.LayoutPadding
2525
import androidx.ui.layout.LayoutWidth
2626
import androidx.ui.material.AlertDialog
27-
import androidx.ui.material.Button
2827
import androidx.ui.material.Divider
2928
import androidx.ui.material.MaterialTheme
30-
import androidx.ui.material.TextButtonStyle
29+
import androidx.ui.material.TextButton
3130
import androidx.ui.unit.dp
3231

3332
@Composable
@@ -41,18 +40,19 @@ fun RallyAlertDialog(
4140
onCloseRequest = onDismiss,
4241
text = { Text(bodyText) },
4342
buttons = {
44-
val style = TextButtonStyle(RectangleShape).copy(paddings = EdgeInsets(16.dp))
4543
Column {
4644
Divider(
4745
LayoutPadding(left = 12.dp, right = 12.dp),
4846
color = MaterialTheme.colors().onSurface.copy(alpha = 0.2f)
4947
)
50-
Button(
51-
text = buttonText,
48+
TextButton(
5249
onClick = onDismiss,
53-
style = style,
50+
shape = RectangleShape,
51+
paddings = EdgeInsets(16.dp),
5452
modifier = LayoutWidth.Fill
55-
)
53+
) {
54+
Text(buttonText)
55+
}
5656
}
5757
}
5858
)

‎ui/ui-material/integration-tests/material-studies/src/main/java/androidx/ui/material/studies/rally/RallyCards.kt‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ import androidx.ui.layout.LayoutWidth
3333
import androidx.ui.layout.Row
3434
import androidx.ui.layout.Spacer
3535
import androidx.ui.layout.Stack
36-
import androidx.ui.material.Button
3736
import androidx.ui.material.Divider
3837
import androidx.ui.material.MaterialTheme
39-
import androidx.ui.material.TextButtonStyle
38+
import androidx.ui.material.TextButton
4039
import androidx.ui.material.ripple.Ripple
4140
import androidx.ui.material.surface.Card
4241
import androidx.ui.unit.dp
@@ -69,7 +68,9 @@ fun RallyAlertCard() {
6968
arrangement = Arrangement.SpaceBetween
7069
) {
7170
Text(text = "Alerts", style = MaterialTheme.typography().subtitle2)
72-
Button(text = "See All", onClick = { }, style = TextButtonStyle())
71+
TextButton(onClick = { }) {
72+
Text("See All")
73+
}
7374
}
7475
}
7576
}
@@ -91,7 +92,9 @@ fun RallyAlertCard() {
9192
// TODO: icons still don't work
9293
// <vectorResource res=context.resources
9394
// resId=androidx.ui.material.studies.R.drawable.sort_icon/>
94-
Button(text = "Sort", onClick = { }, style = TextButtonStyle())
95+
TextButton(onClick = { }) {
96+
Text("Sort")
97+
}
9598
}
9699
}
97100
}
@@ -134,7 +137,9 @@ fun RallyAccountsOverviewCard() {
134137
color = Color(0xFF37EFBA)
135138
)
136139
RallyDivider()
137-
Button(text = "See All", style = TextButtonStyle())
140+
TextButton(onClick = { }) {
141+
Text("See All")
142+
}
138143
}
139144
}
140145
}
@@ -263,7 +268,9 @@ fun RallyBillsOverviewCard() {
263268
color = Color(0xFF37EFBA)
264269
)
265270
RallyDivider()
266-
Button(text = "See All", style = TextButtonStyle())
271+
TextButton(onClick = { }) {
272+
Text("See All")
273+
}
267274
}
268275
}
269276
}

‎ui/ui-material/integration-tests/samples/src/main/java/androidx/ui/material/samples/AlertDialogSample.kt‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,18 @@ fun SideBySideAlertDialogSample() {
4545
" which presents the details regarding the Dialog's purpose.")
4646
},
4747
confirmButton = {
48-
Button("Confirm", onClick = {
48+
Button(onClick = {
4949
openDialog.value = false
50-
})
50+
}) {
51+
Text("Confirm")
52+
}
5153
},
5254
dismissButton = {
53-
Button("Dismiss", onClick = {
55+
Button(onClick = {
5456
openDialog.value = false
55-
})
57+
}) {
58+
Text("Dismiss")
59+
}
5660
},
5761
buttonLayout = AlertDialogButtonLayout.SideBySide
5862
)
@@ -79,14 +83,18 @@ fun StackedAlertDialogSample() {
7983
" which presents the details regarding the Dialog's purpose.")
8084
},
8185
confirmButton = {
82-
Button("Long Confirm Button", onClick = {
86+
Button(onClick = {
8387
openDialog.value = false
84-
})
88+
}) {
89+
Text("Long Confirm Button")
90+
}
8591
},
8692
dismissButton = {
87-
Button("Long Dismiss Button", onClick = {
93+
Button(onClick = {
8894
openDialog.value = false
89-
})
95+
}) {
96+
Text("Long Dismiss Button")
97+
}
9098
},
9199
buttonLayout = AlertDialogButtonLayout.Stacked
92100
)
@@ -112,7 +120,9 @@ fun CustomAlertDialogSample() {
112120
},
113121
buttons = {
114122
Row(arrangement = Arrangement.Center) {
115-
Button("Button", onClick = { openDialog.value = false })
123+
Button(onClick = { openDialog.value = false }) {
124+
Text("Button")
125+
}
116126
}
117127
}
118128
)

‎ui/ui-material/integration-tests/samples/src/main/java/androidx/ui/material/samples/ButtonSamples.kt‎

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,30 @@ package androidx.ui.material.samples
1919
import androidx.annotation.Sampled
2020
import androidx.compose.Composable
2121
import androidx.ui.core.Text
22-
import androidx.ui.graphics.Color
2322
import androidx.ui.material.Button
24-
import androidx.ui.material.OutlinedButtonStyle
25-
import androidx.ui.material.TextButtonStyle
26-
import androidx.ui.text.TextStyle
23+
import androidx.ui.material.OutlinedButton
24+
import androidx.ui.material.TextButton
2725

2826
@Sampled
2927
@Composable
30-
fun OutlinedButtonSample(onClick: () -> Unit) {
31-
Button(text = "Outlined Button", onClick = onClick, style = OutlinedButtonStyle())
32-
}
33-
34-
@Sampled
35-
@Composable
36-
fun ContainedButtonSample(onClick: () -> Unit) {
37-
// ContainedButtonStyle is the default style.
38-
Button(text = "Contained Button", onClick = onClick)
39-
}
40-
41-
@Sampled
42-
@Composable
43-
fun TextButtonSample(onClick: () -> Unit) {
44-
Button(text = "Text Button", onClick = onClick, style = TextButtonStyle())
28+
fun ButtonSample() {
29+
Button(onClick = { /* Do something! */ }) {
30+
Text("Button")
31+
}
4532
}
4633

4734
@Sampled
4835
@Composable
49-
fun ButtonSample(onClick: () -> Unit) {
50-
Button(onClick = onClick) {
51-
Text(text = "Custom text style", style = TextStyle(color = Color.Green))
36+
fun OutlinedButtonSample() {
37+
OutlinedButton(onClick = { /* Do something! */ }) {
38+
Text("Outlined Button")
5239
}
5340
}
5441

5542
@Sampled
5643
@Composable
57-
fun ButtonWithTextSample(onClick: () -> Unit) {
58-
Button(text = "Button", onClick = onClick)
44+
fun TextButtonSample() {
45+
TextButton(onClick = { /* Do something! */ }) {
46+
Text("Text Button")
47+
}
5948
}

‎ui/ui-material/integration-tests/samples/src/main/java/androidx/ui/material/samples/DrawerSamples.kt‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ private fun YourDrawerContent(onStateChange: (DrawerState) -> Unit) {
8484
Column(LayoutHeight.Fill) {
8585
Text(text = "Drawer Content")
8686
Spacer(LayoutHeight(20.dp))
87-
Button(
88-
text = "Close Drawer",
89-
onClick = { onStateChange(DrawerState.Closed) })
87+
Button(onClick = { onStateChange(DrawerState.Closed) }) {
88+
Text("Close Drawer")
89+
}
9090
}
9191
}
9292
}
@@ -97,10 +97,9 @@ private fun YourAppContent(text: String, onDrawerStateChange: (DrawerState) -> U
9797
Column(LayoutHeight.Fill) {
9898
Text(text = text)
9999
Spacer(LayoutHeight(20.dp))
100-
Button(
101-
text = "Click to open",
102-
onClick = { onDrawerStateChange(DrawerState.Opened) }
103-
)
100+
Button(onClick = { onDrawerStateChange(DrawerState.Opened) }) {
101+
Text("Click to open")
102+
}
104103
}
105104
}
106105
}

‎ui/ui-material/integration-tests/samples/src/main/java/androidx/ui/material/samples/SnackbarSample.kt‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import androidx.ui.core.Text
2222
import androidx.ui.graphics.Color
2323
import androidx.ui.material.Button
2424
import androidx.ui.material.Snackbar
25-
import androidx.ui.material.TextButtonStyle
2625

2726
@Sampled
2827
@Composable
@@ -47,10 +46,11 @@ fun SlotsSnackbar() {
4746
},
4847
action = {
4948
Button(
50-
text = "ADD THIS SONG ANYWAY",
51-
style = TextButtonStyle(contentColor = customActionColor),
52-
onClick = { /* call long action here */ }
53-
)
49+
onClick = { /* call long action here */ },
50+
contentColor = customActionColor
51+
) {
52+
Text("ADD THIS SONG ANYWAY")
53+
}
5454
},
5555
actionOnNewLine = true
5656
)

‎ui/ui-material/src/androidTest/java/androidx/ui/material/ButtonTest.kt‎

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ class ButtonTest {
6666
composeTestRule.setMaterialContent {
6767
Center {
6868
TestTag(tag = "myButton") {
69-
Button(onClick = {}, text = "myButton")
69+
Button(onClick = {}) {
70+
Text("myButton")
71+
}
7072
}
7173
}
7274
}
@@ -80,7 +82,7 @@ class ButtonTest {
8082
composeTestRule.setMaterialContent {
8183
Center {
8284
TestTag(tag = "myButton") {
83-
Button(text = "myButton")
85+
Button { Text("myButton") }
8486
}
8587
}
8688
}
@@ -101,7 +103,9 @@ class ButtonTest {
101103

102104
composeTestRule.setMaterialContent {
103105
Center {
104-
Button(onClick = onClick, text = text)
106+
Button(onClick = onClick) {
107+
Text(text)
108+
}
105109
}
106110
}
107111

@@ -128,7 +132,9 @@ class ButtonTest {
128132
}
129133
Center {
130134
TestTag(tag = tag) {
131-
Button(onClick = onClick, text = "Hello")
135+
Button(onClick = onClick) {
136+
Text("Hello")
137+
}
132138
}
133139
}
134140
}
@@ -165,10 +171,14 @@ class ButtonTest {
165171
composeTestRule.setMaterialContent {
166172
Column {
167173
TestTag(tag = button1Tag) {
168-
Button(onClick = button1OnClick, text = text)
174+
Button(onClick = button1OnClick) {
175+
Text(text)
176+
}
169177
}
170178
TestTag(tag = button2Tag) {
171-
Button(onClick = button2OnClick, text = text)
179+
Button(onClick = button2OnClick) {
180+
Text(text)
181+
}
172182
}
173183
}
174184
}
@@ -199,7 +209,9 @@ class ButtonTest {
199209
}
200210
composeTestRule
201211
.setMaterialContentAndCollectSizes {
202-
Button(onClick = {}, text = "Test button")
212+
Button(onClick = {}) {
213+
Text("Test button")
214+
}
203215
}
204216
.assertHeightEqualsTo(36.dp)
205217
}
@@ -224,7 +236,7 @@ class ButtonTest {
224236
@Test
225237
fun buttonTest_ContainedButtonPropagateDefaultTextStyle() {
226238
composeTestRule.setMaterialContent {
227-
Button(onClick = {}, style = ContainedButtonStyle()) {
239+
Button(onClick = {}) {
228240
val style = MaterialTheme.typography().button
229241
.copy(color = MaterialTheme.colors().onPrimary)
230242
assertThat(currentTextStyle()).isEqualTo(style)
@@ -235,7 +247,7 @@ class ButtonTest {
235247
@Test
236248
fun buttonTest_OutlinedButtonPropagateDefaultTextStyle() {
237249
composeTestRule.setMaterialContent {
238-
Button(onClick = {}, style = OutlinedButtonStyle()) {
250+
OutlinedButton(onClick = {}) {
239251
val style = MaterialTheme.typography().button
240252
.copy(color = MaterialTheme.colors().primary)
241253
assertThat(currentTextStyle()).isEqualTo(style)
@@ -246,7 +258,7 @@ class ButtonTest {
246258
@Test
247259
fun buttonTest_TextButtonPropagateDefaultTextStyle() {
248260
composeTestRule.setMaterialContent {
249-
Button(onClick = {}, style = OutlinedButtonStyle()) {
261+
TextButton(onClick = {}) {
250262
val style = MaterialTheme.typography().button
251263
.copy(color = MaterialTheme.colors().primary)
252264
assertThat(currentTextStyle()).isEqualTo(style)
@@ -256,31 +268,34 @@ class ButtonTest {
256268

257269
@Test
258270
fun buttonTest_ContainedButtonHorPaddingIsFromSpec() {
259-
assertLeftPaddingIs(16.dp) {
260-
ContainedButtonStyle()
271+
assertLeftPaddingIs(16.dp) { children ->
272+
Button(onClick = {}, children = children)
261273
}
262274
}
263275

264276
@Test
265277
fun buttonTest_OutlinedButtonHorPaddingIsFromSpec() {
266-
assertLeftPaddingIs(16.dp) {
267-
OutlinedButtonStyle()
278+
assertLeftPaddingIs(16.dp) { children ->
279+
OutlinedButton(onClick = {}, children = children)
268280
}
269281
}
270282

271283
@Test
272284
fun buttonTest_TextButtonHorPaddingIsFromSpec() {
273-
assertLeftPaddingIs(8.dp) {
274-
TextButtonStyle()
285+
assertLeftPaddingIs(8.dp) { children ->
286+
TextButton(onClick = {}, children = children)
275287
}
276288
}
277289

278-
private fun assertLeftPaddingIs(padding: Dp, style: @Composable() () -> ButtonStyle) {
290+
private fun assertLeftPaddingIs(
291+
padding: Dp,
292+
button: @Composable() (@Composable() () -> Unit) -> Unit
293+
) {
279294
var parentCoordinates: LayoutCoordinates? = null
280295
var childCoordinates: LayoutCoordinates? = null
281296
composeTestRule.setMaterialContent {
282297
Wrap {
283-
Button(onClick = {}, style = style()) {
298+
button {
284299
OnPositioned {
285300
parentCoordinates = it
286301
}

‎ui/ui-material/src/androidTest/java/androidx/ui/material/SnackbarTest.kt‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class SnackbarTest {
120120
},
121121
action = {
122122
OnChildPositioned(onPositioned = { buttonCoords = it }) {
123-
Button(style = TextButtonStyle(), onClick = {}) {
123+
TextButton(onClick = {}) {
124124
OnChildPositioned(onPositioned = { buttonTextCoords = it }) {
125125
Text("Undo")
126126
}
@@ -210,7 +210,9 @@ class SnackbarTest {
210210
},
211211
action = {
212212
OnChildPositioned(onPositioned = { buttonCoords = it }) {
213-
Button(text = "Undo", style = TextButtonStyle(), onClick = {})
213+
TextButton(onClick = {}) {
214+
Text("Undo")
215+
}
214216
}
215217
}
216218
)
@@ -264,7 +266,9 @@ class SnackbarTest {
264266
},
265267
action = {
266268
OnChildPositioned(onPositioned = { buttonCoords = it }) {
267-
Button(text = "Undo", style = TextButtonStyle(), onClick = {})
269+
TextButton(onClick = {}) {
270+
Text("Undo")
271+
}
268272
}
269273
},
270274
actionOnNewLine = true

‎ui/ui-material/src/main/java/androidx/ui/material/Button.kt‎

Lines changed: 129 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17+
@file:Suppress("NOTHING_TO_INLINE")
18+
1719
package androidx.ui.material
1820

1921
import androidx.compose.Composable
20-
import androidx.compose.Immutable
2122
import androidx.ui.core.CurrentTextStyleProvider
2223
import androidx.ui.core.Modifier
2324
import androidx.ui.core.Text
@@ -35,63 +36,72 @@ import androidx.ui.unit.Dp
3536
import androidx.ui.unit.dp
3637

3738
/**
38-
* Styling configuration for a [Button].
39-
*
40-
* The three basic Material button styles are provided by [ContainedButtonStyle], intended for high
41-
* emphasis buttons, [OutlinedButtonStyle], intended for medium emphasis buttons, and
42-
* [TextButtonStyle], intended for low emphasis buttons.
43-
*
44-
* @param backgroundColor The background color. Use [Color.Transparent] to have no color
45-
* @param contentColor The preferred content color. Will be used by text and iconography
46-
* @param shape Defines the button's shape as well as its shadow
47-
* @param border Optional border to draw on top of the button
48-
* @param elevation The z-coordinate at which to place this button. This controls the size
49-
* of the shadow below the button
50-
* @param paddings The spacing values to apply internally between the container and the content
51-
*/
52-
@Immutable
53-
data class ButtonStyle(
54-
val backgroundColor: Color,
55-
val contentColor: Color,
56-
val shape: Shape,
57-
val border: Border? = null,
58-
val elevation: Dp = 0.dp,
59-
val paddings: EdgeInsets = ButtonPaddings
60-
)
61-
62-
/**
63-
* Style used to configure a Button to look like a
39+
* Material Design implementation of a
6440
* [Material Contained Button](https://material.io/design/components/buttons.html#contained-button).
6541
*
6642
* Contained buttons are high-emphasis, distinguished by their use of elevation and fill. They
6743
* contain actions that are primary to your app.
6844
*
69-
* @sample androidx.ui.material.samples.ContainedButtonSample
45+
* To make a button clickable, you must provide an onClick. If no onClick is provided, this button
46+
* will display itself as disabled.
47+
*
48+
* The default text style for internal [Text] components will be set to [Typography.button]. Text
49+
* color will try to match the correlated color for the background color. For example if the
50+
* background color is set to [ColorPalette.primary] then the text will by default use
51+
* [ColorPalette.onPrimary].
7052
*
71-
* @see OutlinedButtonStyle
72-
* @see TextButtonStyle
53+
* @sample androidx.ui.material.samples.ButtonSample
7354
*
74-
* @param backgroundColor The background color
55+
* @param modifier Modifier to be applied to the button.
56+
* @param onClick Will be called when the user clicks the button. The button will be disabled if it
57+
* is null.
58+
* @param backgroundColor The background color. Use [Color.Transparent] to have no color
7559
* @param contentColor The preferred content color. Will be used by text and iconography
7660
* @param shape Defines the button's shape as well as its shadow
61+
* @param border Border to draw around the button
7762
* @param elevation The z-coordinate at which to place this button. This controls the size
7863
* of the shadow below the button
64+
* @param paddings The spacing values to apply internally between the container and the content
7965
*/
8066
@Composable
81-
fun ContainedButtonStyle(
67+
fun Button(
68+
modifier: Modifier = Modifier.None,
69+
onClick: (() -> Unit)? = null,
8270
backgroundColor: Color = MaterialTheme.colors().primary,
8371
contentColor: Color = contentColorFor(backgroundColor),
8472
shape: Shape = MaterialTheme.shapes().button,
85-
elevation: Dp = 2.dp
86-
) = ButtonStyle(
87-
backgroundColor = backgroundColor,
88-
shape = shape,
89-
elevation = elevation,
90-
contentColor = contentColor
91-
)
73+
border: Border? = null,
74+
elevation: Dp = 2.dp,
75+
paddings: EdgeInsets = ButtonPaddings,
76+
children: @Composable() () -> Unit
77+
) {
78+
// Since we're adding layouts in between the clickable layer and the content, we need to
79+
// merge all descendants, or we'll get multiple nodes
80+
Semantics(container = true, mergeAllDescendants = true) {
81+
Surface(
82+
shape = shape,
83+
color = backgroundColor,
84+
contentColor = contentColor,
85+
border = border,
86+
elevation = elevation,
87+
modifier = modifier
88+
) {
89+
Ripple(bounded = true, enabled = onClick != null) {
90+
Clickable(onClick = onClick) {
91+
Container(constraints = ButtonConstraints, padding = paddings) {
92+
CurrentTextStyleProvider(
93+
value = MaterialTheme.typography().button,
94+
children = children
95+
)
96+
}
97+
}
98+
}
99+
}
100+
}
101+
}
92102

93103
/**
94-
* Style used to configure a Button to look like a
104+
* Material Design implementation of a
95105
* [Material Outlined Button](https://material.io/design/components/buttons.html#outlined-button).
96106
*
97107
* Outlined buttons are medium-emphasis buttons. They contain actions that are important, but are
@@ -100,156 +110,125 @@ fun ContainedButtonStyle(
100110
* Outlined buttons are also a lower emphasis alternative to contained buttons, or a higher emphasis
101111
* alternative to text buttons.
102112
*
103-
* @sample androidx.ui.material.samples.OutlinedButtonSample
113+
* To make a button clickable, you must provide an onClick. If no onClick is provided, this button
114+
* will display itself as disabled.
104115
*
105-
* @see ContainedButtonStyle
106-
* @see TextButtonStyle
116+
* The default text style for internal [Text] components will be set to [Typography.button]. Text
117+
* color will try to match the correlated color for the background color. For example if the
118+
* background color is set to [ColorPalette.primary] then the text will by default use
119+
* [ColorPalette.onPrimary].
120+
*
121+
* @sample androidx.ui.material.samples.OutlinedButtonSample
107122
*
108-
* @param border Optional border to draw on top of the button
109-
* @param backgroundColor The background color. Provide [Color.Transparent] to have no color.
110-
* @param contentColor The preferred content color. Will be used by text and iconography.
111-
* @param shape Defines the Button's shape.
123+
* @param modifier Modifier to be applied to the button.
124+
* @param onClick Will be called when the user clicks the button. The button will be disabled if it
125+
* is null.
126+
* @param backgroundColor The background color. Use [Color.Transparent] to have no color
127+
* @param contentColor The preferred content color. Will be used by text and iconography
128+
* @param shape Defines the button's shape as well as its shadow
129+
* @param border Border to draw around the button
112130
* @param elevation The z-coordinate at which to place this button. This controls the size
113-
* of the shadow below the button.
131+
* of the shadow below the button
132+
* @param paddings The spacing values to apply internally between the container and the content
114133
*/
115134
@Composable
116-
fun OutlinedButtonStyle(
117-
border: Border =
118-
Border(1.dp, MaterialTheme.colors().onSurface.copy(alpha = OutlinedStrokeOpacity)),
135+
inline fun OutlinedButton(
136+
modifier: Modifier = Modifier.None,
137+
noinline onClick: (() -> Unit)? = null,
119138
backgroundColor: Color = MaterialTheme.colors().surface,
120139
contentColor: Color = MaterialTheme.colors().primary,
121140
shape: Shape = MaterialTheme.shapes().button,
122-
elevation: Dp = 0.dp
123-
) = ButtonStyle(
141+
border: Border? =
142+
Border(1.dp, MaterialTheme.colors().onSurface.copy(alpha = OutlinedStrokeOpacity)),
143+
elevation: Dp = 0.dp,
144+
paddings: EdgeInsets = ButtonPaddings,
145+
noinline children: @Composable() () -> Unit
146+
) = Button(
147+
modifier = modifier,
148+
onClick = onClick,
124149
backgroundColor = backgroundColor,
150+
contentColor = contentColor,
125151
shape = shape,
126152
border = border,
127153
elevation = elevation,
128-
contentColor = contentColor
154+
paddings = paddings,
155+
children = children
129156
)
130157

131158
/**
132-
* Style used to configure a Button to look like a
159+
* Material Design implementation of a
133160
* [Material Text Button](https://material.io/design/components/buttons.html#text-button).
134161
*
135162
* Text buttons are typically used for less-pronounced actions, including those located in cards and
136163
* dialogs.
137164
*
138-
* @sample androidx.ui.material.samples.TextButtonSample
165+
* To make a button clickable, you must provide an onClick. If no onClick is provided, this button
166+
* will display itself as disabled.
139167
*
140-
* @see ContainedButtonStyle
141-
* @see OutlinedButtonStyle
168+
* The default text style for internal [Text] components will be set to [Typography.button]. Text
169+
* color will try to match the correlated color for the background color. For example if the
170+
* background color is set to [ColorPalette.primary] then the text will by default use
171+
* [ColorPalette.onPrimary].
142172
*
143-
* @param shape Defines the Button's shape.
144-
* @param contentColor The preferred content color. Will be used by text and iconography.
145-
*/
146-
@Composable
147-
fun TextButtonStyle(
148-
shape: Shape = MaterialTheme.shapes().button,
149-
contentColor: Color = MaterialTheme.colors().primary
150-
) = ButtonStyle(
151-
backgroundColor = Color.Transparent,
152-
shape = shape,
153-
paddings = TextButtonPaddings,
154-
contentColor = contentColor
155-
)
156-
157-
/**
158-
* Material Design implementation of [Button](https://material.io/design/components/buttons.html).
159-
*
160-
* To make a button clickable, you must provide an onClick. If no onClick is provided, this button will display
161-
* itself as disabled.
162-
*
163-
* The default text style for internal [Text] components will be set to [Typography.button]. Text color will
164-
* try to match the correlated color for the background color. For example if the background color is set to
165-
* [ColorPalette.primary] then the text will by default use [ColorPalette.onPrimary].
166-
*
167-
* @sample androidx.ui.material.samples.ButtonSample
168-
*
169-
* @param modifier Modifier to be applied to the button.
170-
* @param onClick Will be called when the user clicks the button. The button will be disabled if it is null.
171-
* @param style Contains the styling parameters for the button.
172-
*/
173-
@Composable
174-
fun Button(
175-
modifier: Modifier = Modifier.None,
176-
onClick: (() -> Unit)? = null,
177-
style: ButtonStyle = ContainedButtonStyle(),
178-
children: @Composable() () -> Unit
179-
) {
180-
// Since we're adding layouts in between the clickable layer and the content, we need to
181-
// merge all descendants, or we'll get multiple nodes
182-
Semantics(container = true, mergeAllDescendants = true) {
183-
Surface(
184-
shape = style.shape,
185-
color = style.backgroundColor,
186-
contentColor = style.contentColor,
187-
border = style.border,
188-
elevation = style.elevation,
189-
modifier = modifier
190-
) {
191-
Ripple(bounded = true, enabled = onClick != null) {
192-
Clickable(onClick = onClick) {
193-
Container(constraints = ButtonConstraints, padding = style.paddings) {
194-
CurrentTextStyleProvider(
195-
value = MaterialTheme.typography().button,
196-
children = children
197-
)
198-
}
199-
}
200-
}
201-
}
202-
}
203-
}
204-
205-
/**
206-
* Material Design implementation of [Button](https://material.io/design/components/buttons.html) that contains some
207-
* text.
208-
*
209-
* To make a button clickable, you must provide an onClick. If no onClick is provided, this button will display
210-
* itself as disabled.
211-
*
212-
* The default text style for internal [Text] components will be set to [Typography.button]. Text color will
213-
* try to match the correlated color for the background color. For example if the background color is set to
214-
* [ColorPalette.primary] then the text will by default use [ColorPalette.onPrimary].
215-
*
216-
* @sample androidx.ui.material.samples.ButtonWithTextSample
217-
*
218-
* There is a different overload for this component that takes a lambda of customizable content.
173+
* @sample androidx.ui.material.samples.TextButtonSample
219174
*
220-
* @param text The text to display.
221175
* @param modifier Modifier to be applied to the button.
222-
* @param onClick Will be called when the user clicks the button. The button will be disabled if it is null.
223-
* @param style Contains the styling parameters for the button.
176+
* @param onClick Will be called when the user clicks the button. The button will be disabled if it
177+
* is null.
178+
* @param backgroundColor The background color. Use [Color.Transparent] to have no color
179+
* @param contentColor The preferred content color. Will be used by text and iconography
180+
* @param shape Defines the button's shape as well as its shadow
181+
* @param border Border to draw around the button
182+
* @param elevation The z-coordinate at which to place this button. This controls the size
183+
* of the shadow below the button
184+
* @param paddings The spacing values to apply internally between the container and the content
224185
*/
225186
@Composable
226-
fun Button(
227-
text: String,
187+
inline fun TextButton(
228188
modifier: Modifier = Modifier.None,
229-
onClick: (() -> Unit)? = null,
230-
style: ButtonStyle = ContainedButtonStyle()
231-
) {
232-
Button(modifier = modifier, style = style, onClick = onClick) {
233-
Text(text = text)
234-
}
235-
}
189+
noinline onClick: (() -> Unit)? = null,
190+
backgroundColor: Color = Color.Transparent,
191+
contentColor: Color = MaterialTheme.colors().primary,
192+
shape: Shape = MaterialTheme.shapes().button,
193+
border: Border? = null,
194+
elevation: Dp = 0.dp,
195+
paddings: EdgeInsets = TextButtonPaddings,
196+
noinline children: @Composable() () -> Unit
197+
) = Button(
198+
modifier = modifier,
199+
onClick = onClick,
200+
backgroundColor = backgroundColor,
201+
contentColor = contentColor,
202+
shape = shape,
203+
border = border,
204+
elevation = elevation,
205+
paddings = paddings,
206+
children = children
207+
)
236208

237209
// Specification for Material Button:
238210
private val ButtonConstraints = DpConstraints(
239211
minWidth = 64.dp,
240212
minHeight = 36.dp
241213
)
214+
242215
private val ButtonHorizontalPadding = 16.dp
243216
private val ButtonVerticalPadding = 8.dp
244-
private val ButtonPaddings = EdgeInsets(
217+
private val TextButtonHorizontalPadding = 8.dp
218+
219+
@PublishedApi
220+
internal val ButtonPaddings = EdgeInsets(
245221
left = ButtonHorizontalPadding,
246222
top = ButtonVerticalPadding,
247223
right = ButtonHorizontalPadding,
248224
bottom = ButtonVerticalPadding
249225
)
250-
private val TextButtonHorizontalPadding = 8.dp
251-
private val TextButtonPaddings = ButtonPaddings.copy(
226+
227+
@PublishedApi
228+
internal val TextButtonPaddings = ButtonPaddings.copy(
252229
left = TextButtonHorizontalPadding,
253230
right = TextButtonHorizontalPadding
254231
)
255-
private val OutlinedStrokeOpacity = 0.12f
232+
233+
@PublishedApi
234+
internal const val OutlinedStrokeOpacity = 0.12f

‎ui/ui-material/src/main/java/androidx/ui/material/Snackbar.kt‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,13 @@ fun Snackbar(
7272
val actionSlot: @Composable() (() -> Unit)? =
7373
if (actionText != null) {
7474
@Composable {
75-
Button(
76-
text = actionText,
75+
TextButton(
7776
onClick = onActionClick,
78-
style = TextButtonStyle(
79-
// TODO: remove this when primary light variant is figured out
80-
contentColor = makePrimaryVariantLight(MaterialTheme.colors().primary)
81-
)
82-
)
77+
// TODO: remove this when primary light variant is figured out
78+
contentColor = makePrimaryVariantLight(MaterialTheme.colors().primary)
79+
) {
80+
Text(actionText)
81+
}
8382
}
8483
} else {
8584
null

‎ui/ui-test/src/androidTest/java/androidx/ui/test/AssertExistsTest.kt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ class AssertExistsTest {
4646
val (showText, toggle) = state { true }
4747
Column {
4848
TestTag("MyButton") {
49-
Button(text = "Toggle", onClick = { toggle(!showText) })
49+
Button(onClick = { toggle(!showText) }) {
50+
Text("Toggle")
51+
}
5052
}
5153
if (showText) {
5254
Semantics(container = true) {

‎ui/ui-test/src/androidTest/java/androidx/ui/test/CustomActivityTest.kt‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package androidx.ui.test
1919
import android.app.Activity
2020
import android.os.Bundle
2121
import androidx.test.filters.MediumTest
22+
import androidx.ui.core.Text
2223
import androidx.ui.core.setContent
2324
import androidx.ui.layout.Stack
2425
import androidx.ui.material.Button
@@ -37,7 +38,9 @@ class CustomActivity : Activity() {
3738
setContent {
3839
MaterialTheme {
3940
Stack {
40-
Button(text = "Hello")
41+
Button {
42+
Text("Hello")
43+
}
4144
}
4245
}
4346
}

0 commit comments

Comments
 (0)
Please sign in to comment.