Jan Skrasek
04/13/2021, 2:00 PMButtonPrimary(onClick = {}) { Text("Primary") }
ButtonSecondary(onClick = {}) { Text("Secondary") }
or having it configurable via a property and enum?
2️⃣
Button(Kind.Primary, onClick = {}) { Text("Primary") }
Button(Kind.Secondary, onClick = {}) { Text("Primary") }
My SwiftUI friend forces me to the enum way but I would prefer rather the first one (their syntax seems better here - they may use only the .Primary
token as the value.)Bryan Herbst
04/13/2021, 2:05 PMBryan Herbst
04/13/2021, 2:07 PM@Composable
fun PrimaryButton(
onClick: () -> Unit,
modifier: Modifier = Modifier,
state: ButtonState = ButtonState.DEFAULT,
size: ButtonSize = ButtonSize.MEDIUM,
content: @Composable RowScope.() -> Unit
)
Danish Ansari
04/13/2021, 2:23 PMDanish Ansari
04/13/2021, 2:24 PMAdam Powell
04/13/2021, 2:26 PMJan Skrasek
04/13/2021, 2:28 PMJust a little suggestion, if you go with 1st approach, name composables as PrimaryButton(), SecondaryButton() etc as done by @Bryan Herbst. It increases readabilityIt lowers then a discoverability a bit, doesn't it?
Adam Powell
04/13/2021, 2:29 PMAdam Powell
04/13/2021, 2:30 PMKind.Fancy
constant and the code internal to Button
to respect it. It keeps the inner logic of Button
simpler to omit those branching paths based on the Kind
Adam Powell
04/13/2021, 2:31 PMAdam Powell
04/13/2021, 2:34 PM@Composable fun Button(
kind: Kind,
onClick: () -> Unit,
content: @Composable () -> Unit
) {
// ...
when (kind) {
Kind.Primary -> {
Row(primaryModifiers) {
content()
}
Kind.Secondary -> {
Row(secondaryModifiers) {
content()
}
}
}
// ...
}
Adam Powell
04/13/2021, 2:35 PMJan Skrasek
04/13/2021, 2:38 PMmake wanted things easy, make unwanted things possible
I'm asking rather about the outer API style since both of the approaches can be done the way to allow custom styling (if our team will agree on allowing it),
1. option would probably expose the shared impl. taking explicit styling attributes
2. option would be probably rather a sealed interface with one option called Custom holding the styling attributes - similar to ButtonColors?Adam Powell
04/13/2021, 2:49 PMmake wanted things easy, make unwanted things possibleI am also a fan of this philosophy. 🙂 It leads to far fewer emergencies at your doorstep over time.
Adam Powell
04/13/2021, 2:51 PMcontent
function in the implementation details of a composable function with disjoint branching paths have different identity.Adam Powell
04/13/2021, 2:52 PMAdam Powell
04/13/2021, 2:54 PMvar style by remember { mutableStateOf(Kind.Primary) }
Button(style, onClick = { style = nextStyle(style) }) {
var innerState by remember { SomeState() }
SomeStatefulThing(innerState)
}
Adam Powell
04/13/2021, 2:55 PMinnerState
will be reset to a fresh initial value, which is probably quite unexpected for a useralbertosh
04/13/2021, 2:56 PMsealed class StyledButton { ... }
@Composable
fun StyledButton.Primary(...) { ... }
@Composable
fun StyledButton.Secondary(...) { ... }
Pretty similar to the second one, thoughalbertosh
04/13/2021, 2:57 PMAdam Powell
04/13/2021, 2:58 PMAdam Powell
04/13/2021, 3:00 PMAdam Powell
04/13/2021, 3:01 PMJan Skrasek
04/13/2021, 3:08 PMBryan Herbst
04/13/2021, 3:14 PMAdam Powell
04/13/2021, 3:22 PMAdam Powell
04/13/2021, 3:24 PMBryan Herbst
04/13/2021, 3:38 PM