Playing with Custom Layout in Flex 4
As Flex 4 SDK is almost in it’s Beta state I took a look at his features and what impressed me the most was how the presentation is decoupled from the behavior. I remember a presentation around Max 2007 when Ely Greenfield, the principal scientist for Flex SDK, showed a sneak peek on how this will make a lot of skinning things a lot simpler. For example, it’s simple to make a list look … let’s say to make it look like the Fan effect that Mac users love so much
I found this quite easy to implement using Flex 4. Because the list can be skinned in MXML it’s so easy to program the skin and stay in MXML for the most part. The only thing that I actually needed to program was how the elements are laid out.
The basic List skin looks like this:
<s:states> <s:State name="normal"/> <s:State name="hover"/> <s:State name="disabled"/> </s:states> <fx:Metadata>[HostComponent("spark.components.List")]</fx:Metadata> <s:DataGroup itemRenderer="components.RepeatedItem1" clipAndEnableScrolling="true" id="dataGroup" rollOver="currentState='hover'"> <s:layout> <components:LargeCircleLayout id="myLayout" radius="1400" stepAngle="0" stepAngle.hover="3.5"/> </s:layout> </s:DataGroup>
Notice that it’s nothing but a DataGroup that has a layout. I’ve also added the Hover state to be able to open the list when you hover over it.
To add the nice effect it’s just a matter of animating one layout property:
<s:transitions> <s:Transition autoReverse="true"> <s:Animate target="{myLayout}" duration="200"> <s:SimpleMotionPath property="stepAngle"/> </s:Animate> </s:Transition> </s:transitions>
You can take a look at the source code here and watch the list here.