Fudge
06/03/2019, 9:35 PMText("Hello World")
.padding()
Seems nicer than
Padding {
Text("Hello World")
}
I have to be honest.miha-x64
06/03/2019, 9:40 PMpadding()
, why, and how should I support it in my custom widgets.
External margins/paddings feel natural and simple.Fudge
06/03/2019, 9:49 PMpadding()
, just like you can nest any widget in Padding{}
. Padding is a modifier added to a widget, in which case a widget extension method is in order and not a "helper method" that receives a widget.
This has all of the added benefits of using extension methods over "helper methods" - being more discover-able and being easier to apply on already typed objects.
This also has the obvious upside of reducing nesting.louiscad
06/03/2019, 9:55 PMText(someLongString).wrapInScrollContainer()
. In fact, that's how I'm currently doing it with `View`s, using wrapInScrollView()
or wrapInRecyclerView()
extension functions.romainguy
06/03/2019, 10:03 PMlouiscad
06/03/2019, 10:06 PMFudge
06/03/2019, 10:07 PMmiha-x64
06/03/2019, 10:13 PMbut would such a syntax be possible?Annotation-based Unit-returning bullshit, with implicit receiver, of course, should be reworked.
Fudge
06/03/2019, 10:14 PMFudge
06/03/2019, 10:14 PMelizarov
06/03/2019, 10:40 PMelizarov
06/03/2019, 10:43 PMelizarov
06/03/2019, 10:44 PMFudge
06/03/2019, 10:45 PMelizarov
06/03/2019, 10:49 PMText("...").padding()
vs
Padding { Text("...") }
It is a matter of taste, style, and habit. I, for one, have been programming with Swing for too much, so the second one looks more natural for me.Fudge
06/03/2019, 10:51 PMFudge
06/03/2019, 10:52 PMromainguy
06/03/2019, 10:53 PM.padding()
on themelizarov
06/03/2019, 10:54 PMText("...").color(...)
example. I'll have to dig how it really works, but it looks like it have to mutate 😱 the view, which makes the whole thing not-so-very-reactive-at-allelizarov
06/03/2019, 10:56 PMFudge
06/03/2019, 10:57 PMRuckus
06/03/2019, 10:58 PMelizarov
06/03/2019, 10:59 PMRuckus
06/03/2019, 11:00 PMPadding { <20 lines here> }
vs <20 lines here>.padding()
elizarov
06/03/2019, 11:00 PMRuckus
06/03/2019, 11:01 PMromainguy
06/03/2019, 11:01 PMRuckus
06/03/2019, 11:02 PMromainguy
06/03/2019, 11:02 PMelizarov
06/03/2019, 11:03 PMromainguy
06/03/2019, 11:03 PMelizarov
06/03/2019, 11:04 PMFudge
06/03/2019, 11:05 PMpadding
at the end of the Row
for example.
It definitely may be that there is enough cases in which you have multiple children without a layout widget wrapping them, but I doubt that.moetouban
06/03/2019, 11:22 PMPadding(
padding: EdgeInsets.all(8.0),
child: const Card(child: Text('Hello World!')),
)
which uses padding as a widget.Tudor Luca
06/03/2019, 11:27 PMelizarov
06/03/2019, 11:29 PMTudor Luca
06/03/2019, 11:29 PMkioba
06/04/2019, 6:09 AMText("").padding()
but Kotlin capable of supporting both of this solution.
Widget.padding() : Widget = Padding { this }
the unit return types just removes this great Kotlin language feature from the developers.louiscad
06/04/2019, 6:14 AMUnit
that is annotated with @Composable
could work. Maybe it's as simple as that?miha-x64
06/04/2019, 7:49 AMdalexander
06/04/2019, 7:56 AMmiha-x64
06/04/2019, 8:02 AMdalexander
06/04/2019, 8:05 AMelizarov
06/04/2019, 8:12 AM@Compose
compiler plugin.miha-x64
06/04/2019, 8:13 AMelizarov
06/04/2019, 8:15 AMelizarov
06/04/2019, 8:17 AMmiha-x64
06/04/2019, 8:22 AMelizarov
06/04/2019, 9:03 AMelizarov
06/04/2019, 9:04 AMelizarov
06/04/2019, 9:04 AMmiha-x64
06/04/2019, 9:07 AMthemishkun
06/04/2019, 10:04 AMelizarov
06/04/2019, 10:08 AMGil Goldzweig
06/04/2019, 12:12 PMGil Goldzweig
06/04/2019, 12:12 PM@ComposableStyle
fun CustomPaddingAndThings() {
}
@Composable
fun SomeComponenet(directParent = CustomPaddingAndThings()) {
}
Gil Goldzweig
06/04/2019, 12:14 PMFudge
06/04/2019, 12:14 PMFudge
06/04/2019, 12:16 PM@Composable
fun SomeComponent (directParent = CustomPaddingAndThings()) {
}
would be the same as
So @Composable
fun SomeComponent = CustomPaddingAndThings() {
}
?Fudge
06/04/2019, 12:17 PMGil Goldzweig
06/04/2019, 12:22 PMGil Goldzweig
06/04/2019, 12:23 PMFudge
06/04/2019, 12:23 PMGil Goldzweig
06/04/2019, 12:23 PMGil Goldzweig
06/04/2019, 12:24 PMGil Goldzweig
06/04/2019, 12:24 PMGil Goldzweig
06/04/2019, 12:25 PM@Composable
fun SomeComponent (directParent = SomeClass::CustomPaddingAndThings) {
}
Adam Powell
06/04/2019, 2:03 PM.padding()
is undesirable for compose. In compose, like in flutter, padding is a layout component of its own used as a wrapper, not a property of a base View class. There's nothing special about it in the compose framework, anyone could write it using public API. And perhaps more importantly, anyone else writing their own components doesn't have to think about how to correctly handle padding in their component implementation - the caller will add a Padding {}
wrapper in the right place if it's desired.Adam Powell
06/04/2019, 2:04 PMAdam Powell
06/04/2019, 2:05 PMAdam Powell
06/04/2019, 2:05 PMAdam Powell
06/04/2019, 2:08 PMCard(...) {
Padding(...) {
TODO("content")
}
}
vs.
Compose(Card(...), Padding(...)) {
TODO("content")
}
Adam Powell
06/04/2019, 2:10 PMAdam Powell
06/04/2019, 2:12 PMFudge
06/04/2019, 2:13 PMCompose(Card(...), Padding(...)) {
TODO("content")
}
Is such a construct not available right now?Adam Powell
06/04/2019, 2:14 PMGil Goldzweig
06/04/2019, 2:16 PMAdam Powell
06/04/2019, 2:17 PM@Composable() () -> Unit
function references if they need to display arbitrary content, and in many cases the caller can add padding around their content they put there if they want it. Some designs might call for padding emitted by the container before calling the provided function, some might not.Gil Goldzweig
06/04/2019, 2:18 PMAdam Powell
06/04/2019, 2:19 PM@Composable fun PaddedCard(padding: ..., content: @Composable() () -> Unit) = Card {
Padding(padding, content)
}
Adam Powell
06/04/2019, 2:20 PMGil Goldzweig
06/04/2019, 2:20 PMGil Goldzweig
06/04/2019, 2:21 PMAdam Powell
06/04/2019, 2:21 PMAdam Powell
06/04/2019, 2:21 PMGil Goldzweig
06/04/2019, 2:22 PMAdam Powell
06/04/2019, 2:26 PMGil Goldzweig
06/04/2019, 2:29 PMAdam Powell
06/04/2019, 2:30 PMGil Goldzweig
06/04/2019, 2:33 PM<include>
elementGil Goldzweig
06/04/2019, 2:34 PMAdam Powell
06/04/2019, 2:34 PM<include>
tag problems since you can use the lexical scope of the caller to perform more logic/provide parameters for deeper contentAdam Powell
06/04/2019, 2:35 PMAdam Powell
06/04/2019, 2:38 PMGil Goldzweig
06/04/2019, 2:38 PMAdam Powell
06/04/2019, 2:39 PMGil Goldzweig
06/04/2019, 2:47 PMGil Goldzweig
06/04/2019, 2:49 PMnwh
06/10/2019, 7:30 PM