Filip Wiesner
04/10/2023, 2:33 PMInput
component with Modifiers
and I am struggling a little. Is there easier way to do this?
@Composable
fun MyTextField(
value: String,
onValueChange: (String) -> Unit,
type: InputType<String> = InputType.Text,
) {
Input(
type = type,
attrs = Modifier
.attrsModifier(inputAttrs(value, onValueChange) as AttrsScope<*>.() -> Unit)
.toAttrs()
)
}
private fun inputAttrs(
value: String,
onValueChange: (String) -> Unit
): InputAttrsScope<String>.() -> Unit = {
value(value)
onInput { onValueChange(it.value) }
}
David Herman
04/10/2023, 5:39 PMkobweb create examples/chat
for some examples of how I'm wrapping inputs in my own code.Filip Wiesner
04/10/2023, 7:48 PMtoAttrs
and pass a extension lambda. That makes senseDavid Herman
04/10/2023, 8:55 PMFilip Wiesner
04/11/2023, 8:59 AMattrsModifier
, (instead of AttrsScope<*>
) for similar usecases?
Does that even make sense?David Herman
04/11/2023, 7:46 PMFilip Wiesner
04/11/2023, 7:55 PMattrsModifier
lamda has AttrsScope<*>.() -> Unit
signature so I cannot access functions of specific attr scope (like InputAttrsScope
in the example). The only way to add is with toAttrs {}
which is "typed" to attr scope of the element it is applied toModifier.attrsModifier<InputAttrsScope<String>> { onInput { ... } }
David Herman
04/11/2023, 7:56 PMFilip Wiesner
04/11/2023, 7:58 PMInput
David Herman
04/11/2023, 7:59 PMFilip Wiesner
04/11/2023, 8:01 PMDavid Herman
04/11/2023, 8:03 PMFilip Wiesner
04/11/2023, 8:08 PMDavid Herman
04/11/2023, 8:08 PMFilip Wiesner
04/11/2023, 8:10 PMDavid Herman
04/11/2023, 8:23 PMFilip Wiesner
04/11/2023, 8:27 PMComponentStyle
approach and I'll see when (if) it will be limiting meDavid Herman
04/11/2023, 8:34 PMFilip Wiesner
04/11/2023, 8:38 PMDavid Herman
04/11/2023, 8:38 PMFilip Wiesner
04/11/2023, 8:42 PMI don't think there's a right answer thereExactly and there are a few problems I face • migrating from one approach to another is not straight forward because of need of migrating function parameters into component variants • you cannot easily combine both of them. I mean technically you can but from UI component design perspective it's not easy task • you have to use styles for pseudo elements/selectors
David Herman
04/11/2023, 8:43 PMFilip Wiesner
04/11/2023, 8:44 PMDavid Herman
04/11/2023, 8:44 PMFilip Wiesner
04/11/2023, 8:45 PMDavid Herman
04/11/2023, 8:45 PMFilip Wiesner
04/11/2023, 8:46 PMAPI design, all silk widgets take a Modifier and a variantYeah I do the same with my components. Let's see how it works out
David Herman
04/11/2023, 8:47 PMFilip Wiesner
04/11/2023, 8:48 PMDavid Herman
04/11/2023, 8:49 PMFilip Wiesner
04/11/2023, 8:51 PMI'm happy to hear how you feel about it over timeDon't you worry about that. I like talking about code and code design 😄 So I think this is not our last 50+ message thread