I just published a new Alloy widget for Mads’ popular NappDrawer module. This module provides sliding side-menus like introduced by Facebook.
Good example
The widget is a good example of a new feature in Alloy 1.3, which is the possibility for <require>
and <widget>
to enclose other elements. Just take a look at this example taken from the widget README:
<Alloy> <Widget id="drawer" src="nl.fokkezb.drawer"> <Window role="leftWindow"> <Label>I am left</Label> </Window> <NavigationWindow role="centerWindow"> <Window> <Label>I am center</Label> </Window> </NavigationWindow> <Window role="rightWindow"> <Label>I am right</Label> </Window> </Widget> </Alloy>
How it works
Alloy will compile this to code in something similar to:
$.__views.drawer = Alloy.createWidget("nl.fokkezb.drawer", "widget", { id: "drawer", children: [$.__views.__alloyId1, $.__views.__alloyId2, $.__views.__alloyId3 ] });
How to handle it
In your widget or required controller arguments[0].children
will give you an array containing all its direct child elements. As you can see in the widget controller, I use the custom role
attribute to determine what to do with each of them. How you handle this is in all up to you.
How to use it
This new feature allows you to wrap views that share a common lay-out but have different contents. For example, a custom popup with animations, logic and styling that all sit in the same controller or widget which can be used to wrap multiple popups.
Comments
Rick Blalock
super cool!
olegator
How do I use this widget to show only center and right windows?
Fokke Zandbergen (@FokkeZB)
I don’t believe that is supported by the module it wraps.
olegator
I fpund this:
Napp Drawer does not require you to use the 3 views. You can also use either the combo of center/left or center/right for your desired needs.
Here: https://github.com/viezel/NappDrawer/tree/master/android
but I don’t understand how to do it.
Fokke Zandbergen (@FokkeZB)
@olegator well, the widget lets you assign them via the `role` attribute. So just leave out the left one and you’re done.
olegator
Unfortunately, If I skip role=”leftWindow” element, my app crash on start
Fokke Zandbergen (@FokkeZB)
@olegator, try to use Titanium Classic to if NappDrawer really supports center+right because last time I tried it didn’t. Also, maybe the crash logs give you more information to tell what the actual problem is?