This requires at least 1 value passed, and the sec...
# doodle
n
This requires at least 1 value passed, and the second value was to avoid collision with the other signatures I think. But it might be possible to remove the need for the second view.
👍 1
a
@Nick You mentioned bundle size as reason why widgets like
label
needs a behavior or theme for it to render. Can you shed more light?
n
The issue is that any default logic for rendering will be included in the bundle since it won't be removed by Dead Code Elimination (DCE, or tree-shaking). So the bundle size will have a larger minimum. Then it will grow if you choose to customize the look/feel a lot in your app using custom `Behavior`s. So most views just do nothing to avoid that cost. This forces you to use a
Theme
or a
Behavior
directly. `Theme`s are easy to use though, so you don't really have to manually set `Behavior`s in most cases. Let me know if that answers your question.
a
@Nick Few more questions 1. Is doodle production ready? 2. Does doodle support SVGs? 3. I came across
container
but still don't know it's difference from
layout
n
It's fairly well tested and good enough for production use in my mind. It does support SVG, if you mean rendering images. The country flags in the docs are all SVG images. There is also support for paths using SVG data. You can see how these are used in the Contacts app. A Container is a View that holds other Views. Technically all Views can hold others, but the View class hides this by default to avoid leaking internal details. This avoids code reaching into a composite View and messing with its children without it explicitly allowing it. Container exposes these aspects. A Layout is not a View. Instead, it manages the positions/sizes of a View’s children. Installing one to a View will make sure it gets invoked whenever the View changes size etc..
a
@Nick I have a top view that holds other views, laying them out using
constraint
layout, but one of the view(which is the last) it holds is a top view too that uses constraint layout in itself. But the inner top view does not render. Like it was ignored. Is it due to constraint layout??
n
It sounds like the missing view is a child of the first AND you added it to the Display (to make it too-level). Let me know if I got that right. The Display works just like a container for views. Adding a view to it will remove the view from its current parent container. Are you trying to achieve a single view with some children? If so, you'd do the following, assuming topLevelView is a Container. Of course it could be any custom view that lets you setup its children as well.
Copy code
// create children and specify their Layouts if they have children

tooLevelView = container {
    this += … // add nested children
    layout = constrain(…) { … } // setup topLevelView’s layout
}

display += topLevelView // show the view and all its children
The order of these operations can change of course. But the end result would be that Display holds ONLY the views at the top of your hierarchy, and those views hold children etc. Display - Child1 - GrandChild1 - … - Child2 - … Let me know if that's clear. If not, it would be easier to help if you shared a code sample of what you're trying to achieve.
a
So this is my topView
Copy code
class TopView(textMetrics: TextMetrics): View(){
    init {
        val but = Button("Click", textMetrics)
        val innerView = InnerView(textMetrics)
        children += listOf(but, innerView)
        layout = constrain(but,innerView){ b1, b2 ->
            <http://b1.top|b1.top> = <http://parent.top|parent.top>
            b1.left = parent.left
            <http://b2.top|b2.top> = b1.bottom
            b2.left = parent.left
        }
    }
}
This is my InnerView
Copy code
class InnerView(textMetrics: TextMetrics): View(){
    init {
        val but = Button("ClickInner", textMetrics)
        children += listOf(but, but)
        layout = constrain(but,but){ b1, b2 ->
            <http://b1.top|b1.top> = <http://parent.top|parent.top>
            b1.left = parent.left
            <http://b2.top|b2.top> = b1.bottom
            b2.left = parent.left
        }
    }
}
Then my app:
Copy code
val vi = TopView(textMetrics)
        display += vi
        display.layout = constrain(vi){view ->
            view.width = parent.width
            view.height = parent.height
        }
But i get
circular dependency
error. Can you tell me what I did wrong
n
You are trying to constrain the same view multiple times:
constrain(but, but)
. You are also adding that view to InnerView twice. Adding twice doesn't matter, but the current constraint impl can't deal with self references. This happens because b1 == b2 since you are constraining the same view. Surely this isn't what you wanted.
a
Yeah that was a mistake. Thanks.
So im able to run it successfully, but only the button in
TopView
was shown
n
Looks like you haven't given the inner view a size, just a position. Set its size to some value in the constraint block.
I'm guessing the button gets its size from measuring it's contained text. This is why you didn't need to be explicit with it.
a
Yea, when i added a size to the
init
block of the
InnerView
it showed. Why does the
TopView
not need a size for the view to be rendered, but InnerView does?
n
You set a size for
TopView
in the layout you assigned to the
Display
. The `Display`’s layout will affect all its children.
a
@Nick Aye captain. Thanks for your help so far 🙂
@Nick is there something like a
matchparent
in views or I'll have to pass around the display object?
n
You can get a View’s
parent
. This is a
View?
which will be
null
if the view is top-level (or hasn't been added to any other view). Top-level views always have a
null
parent
(
Display
is not a
View
). Is your goal to get the
Display
, or just a view’s parent? You'll have to pass the
Display
around if other parts of your app want to use it.
View
actually always knows it's
Display
(once it has been shown). But that value is internal for now. You'll also notice that a View’s parent is just a plain
View
. This is intentional, and avoids leaking information about a View through its children.
What is
matchparent
by the way? Do you mean telling a view to fit the size of its parent? If so, you can use a layout on the parent that sizes the view to it. A constraint is a simple way (like you did before for the top view).
a
@Nick you mean setting size within the constraint with the
parent.height
and
parent.width
?
n
Constraints aren't the only way to do layout by the way. The docs explain a bit more.
a
Yes! I could just quickly relate with constraint layout since I worked with it mostly on Android. Believe me, I'm just getting my hands wet here 😅
On mobile when I tap to click a button, i get ripple effect on the whole screen. Any idea why?
n
Not sure what you mean. Can you share a video? Also, have you added the PointerModule to your app to ensure clicks work?
The latest release has a new constraint layout system that removes a lot of the limitations of the previous one. This system will be the only one in the upcoming 0.9.0 release. But you can start experimenting with it in 0.8.2.