ibm-js / dapp

AMD-based Application Framework for building Web & Mobile applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simplify the view definition with better default constraints.

edchat opened this issue · comments

We should be able to avoid the need to set the constraint on the view in all or almost all cases if we can tell that the view's parent node is a ViewStack (or a container which expects to be only showing one child) or not.

In the ViewStack case, the default constraint should match all of the other children, so that when a child is shown, the currently selected child will be notified that it is being deactivated, so for ViewStack we can use "center" which is the current default constraint.

In the case of a LinearLayout (or a container which has multiple children showing at once) the default constraint should be different for each view, so we can use the view id as the default constraint.

We can check to see if the parentNode.selectedChildId !== undefined to tell if the parentNode is a ViewStack, but we may want a better test.

Even better, if we use parentNode.id instead of "center" when it is a ViewStack, that way we don't have a conflict if an app has multiple ViewStacks under the same parent view.
My current work on this is here:
https://github.com/edchat/dapp/commits/sidePaneTestAndDefaultConstraints1

@cjolif do you have any suggestion for a better test than parentNode.selectedChildId !== undefined to tell if a parentNode (like ViewStack) expects a single child to be visible at a time or if the parentNode (like LinearLayout) expects to have multiple children visible at a time?

Unfortunately I'm not even sure your test is working? For example deliteful/SidePane accepts a single child and has no selectedChildId property?

Why do you need to have a test for that? Can we just count on the user to put the right constraint and if he does not put it we consider this is a single child container?

SidePane does not enforce a single child, if you call show on a SidePane twice, with 2 different children, they are both appended and shown, it does not hide the previous child. So my test is working with SidePane because it will act like LinearLayout and show both children, if a user wants to only show one child in a SidePane they would have to nest a ViewStack inside it.

We could continue to require the user to setup constraints correctly, but with this change the constraints could be removed from the config for most (or maybe all) delite views. I was able to remove the constraints from the config for all of my tests. This will make it much easier to setup the view configuration.

done with 958caac