https://kotlinlang.org logo
#compose
Title
# compose
d

dimsuz

11/04/2019, 10:56 AM
Hi! Going through Compose Tutorial. Few things strike me (naming related): •
DrawImage
component name feels a bit weird when used in a declarative framework. It sounds like a command to be executed rather than something describing a component. Following this we should've had
DrawText
instead of
Text
, no? 🙂
Column(modifier = ...)
. Here
modifier
also feels like a name that is way too generic. I mean isn't each and every argument of
Column
component a modifier in some sense (it modifies its behavior/view)? I wish it would be more specific into what exactly it modifies
k

kioba

11/04/2019, 11:04 AM
I believe
DrawImage
is just a draw callback, just like
Draw
that's why the naming. it is better to be placed in a parent with Size. something like this:
Copy code
WithDensity {
     Container(
       width = vector.defaultWidth.toDp(),
       height = vector.defaultHeight.toDp()
     ) {
       DrawVector(vector)
     }
   }
I had a couple of problems with modifiers too, especially when refactoring components or moving compose up or down in the tree. hard to figure out and split the modifiers correctly
d

dimsuz

11/04/2019, 11:07 AM
Well, the message of Jetpack Compose was that "everything is a component/composable", so my intuition as a user is that everything I do in DSL is declarative, that's why I immediately felt something's off. I mean as a user syntactically I cannot distingiush "draw callback" from "regular compose function" they look the same when being used, so maybe something that could be improved...
hard to figure out and split the modifiers correctly
I just started playing, so don't know much about them yet. Same goes for draw callbacks. So this is just a first reaction 🙂
r

romainguy

11/04/2019, 11:09 AM
We initially wanted everything to be composable fonctions
It's clean and simple
But modifiers are a pragmatic compromise that makes a few things like padding or other layout parameters less cumbersome
d

dimsuz

11/04/2019, 11:11 AM
When I tried Flutter I was a bit cringy everytime I had to wrap widget with
Padding
only to add one. I guess then that modifiers is an alternative solution to simplify this.
But still maybe naming could be improved to something more specific than "modifier". Though it's often hard to nail it, but it's worth it.
r

romainguy

11/04/2019, 11:15 AM
We're open to suggestions
But it shouldn't be too specific either
Think of modifiers as non intrinsic properties of composables
(layout params are a great example)
d

dimsuz

11/04/2019, 11:15 AM
If one day it'll come to me in dreams or on the sidewalk, I'll come back 🙂
On the other hand maybe it's something you once learn and then just use and naming is not standing out that much.
p

pavi2410

11/04/2019, 6:51 PM
What about our beloved "style"?
a

Andrey Kulikov

11/04/2019, 9:48 PM
re: DrawImage. Most components emit Layouts, so they not only draw, but also fill the space. DrawX convention is used for the components which ONLY draw. So they use the size of the parent Layout/Container. So specifically about DrawImage there is also a component SimpleImage(name to be updated, maybe to just Image). So the difference is this component also sizes itself with a size of a Bitmap and then internally uses the same DrawImage
d

dimsuz

11/05/2019, 11:17 AM
I see, thanks for explanation! What still bugs me is using verbs in a declarative setting. They read wrong. I'd suggest to turn them into descriptions somehow. Like maybe
DrawImage
->
ImageDrawing
, which is an awful name, but I want to show that it describes UI, it answers the "what is this" question, compared to
DrawImage
which answers "what is being done, what to do" question (reads like a command)
a

Andrey Kulikov

11/05/2019, 11:21 AM
we would need to come up with some rules which is easy to follow and understand, agree. thanks for the feedback
👍 1