When I first began playing with Flex 4.5 mobile controls, I noticed something odd with the Spark List control. If the amount of data was bigger than the screen, it would "spring" back when your finger left the control. You could scroll down - sure - but the second you let go of the control it scrolled back to the top. I have no idea why this fixes it, but if you simply add height="100%" to your list, it corrects the issue. It doesn't seem to do anything visually to the output at all, but it corrects it immediately. Here is a simple example. First, my top level file will define a list that two sub views will use:
<?xml version="1.0" encoding="utf-8"?>
<s:TabbedViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"> <fx:Script>
<![CDATA[
import mx.collections.ArrayCollection; [Bindable]
public var demo:ArrayCollection = new ArrayCollection([
"Apple",
"Banana",
"Beer",
"Garbage",
"Wine",
"Ray",
"Jeanne",
"Zoid",
"CFSilence",
"Adrok",
"dfgrump",
"Rinaldi",
"Greg",
"Phones",
"Are",
"Little",
"Miniature",
"Spy",
"Camera"]); ]]>
</fx:Script> <s:ViewNavigator label="Broken" width="100%" height="100%" firstView="views.BrokenView"/>
<s:ViewNavigator label="Fixed" width="100%" height="100%" firstView="views.FixedView"/>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations> </s:TabbedViewNavigatorApplication>
Here is the broken view - it will exhibit the behavior I described above:
<fx:Script>
<![CDATA[
import mx.core.FlexGlobals; ]]>
</fx:Script> <s:List dataProvider="{FlexGlobals.topLevelApplication.demo}" width="100%" /> </s:View>
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="Broken">
And here is the good version. The only difference is the addition of the height.
<fx:Script>
<![CDATA[
import mx.core.FlexGlobals; ]]>
</fx:Script> <s:List dataProvider="{FlexGlobals.topLevelApplication.demo}" width="100%" height="100%" /> </s:View>
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="Fixed">
I've attached the FXP if you want to play with this yourself.
Archived Comments
The mobile spark List has "bounce/pull" effects built into it by default (similar to iOS). This means that as you scroll into negative or excess space an animation will play to bring the content back into view. At the top of the List this means returning verticalScrollPosition to zero, and at the bottom of the List this means returning verticalScrollPosition to (contentHeight - height).
Currently the way to toggle bounce/pull effects is tied to the scroll policies on that List. The default mobile spark List skin sets verticalScrollPolicy="on" and horizontalScrollPolicy="auto". This means that the List will always allow vertical scrolling and always have bounce/pull effects in that direction regardless of the content height. It also means that horizontal scroll and bounce/pull will not be enabled unless the content width is larger than the width.
It sounds like you don't want to have bounce/pull when no scrolling is needed. In that case you should set verticalScrollPolicy="auto".
If you would like an API to turn off bounce/pull effects altogether please vote for this enhancement: http://bugs.adobe.com/jira/...
Check out Joan's post on enabling bounce/pull in a List with a horizontal lay: http://butterfliesandbugs.w...
The spec for bounce/pull has a little more information: http://opensource.adobe.com...
And the spec for mobile scrolling might be useful:
http://opensource.adobe.com...
While I believe you are correct about the reason behind this, it is not exactly my issue. My list _was_ longer then the view. I wasn't scrolling _past_ the end of the list, I was scrolling in general. Try my 'bad' example. You can see the list is longer then the view. Just try to scroll it a bit and as soon as you let go, it snaps back. To me, that's a bug. I can't imagine why anyone would wan _that_ particular behavior.
The List being larger than the View doesn't enable scrolling. What is needed is for the List's content size to be larger than its size. You can't see it because your device's screen size isn't large enough, but you actually are scrolling beyond the end of the List. Notice in the case when you set height="100%" on the List you see the bottom border of the List, but when you don't set a size you can't see it. This is because the size of the List is extending off screen.
Does that make sense?
The snapping behavior you are seeing is the default behavior in this case in native iOS and BlackBerry PlayBook applications.
Hmm. It _kinda_ makes sense. I'll be honest - it isn't your description that is lacking but my brain cells. ;)
So - there is a logical reason for this. This blog entry still makes sense though - right? I know I ran into this and was confused, and I've seen others run into it as well.
Thanks, I hit this exact same problem and your fix was the solution.