Description of the problem
When a ScrollableView is added inside a ScrollView, all of the scroll events will be captured by the ScrollView. This makes the ScrollableView difficult to scroll.
Steps to reproduce
Use the following code to reproduce the problem: trying to scroll through the ScrollableView screens does not work as it should.
var win = Ti.UI.createWindow();
win.open();
var scroll = Ti.UI.createScrollView({
height: Ti.UI.FILL,
width: Ti.UI.FILL,
backgroundColor: 'orange',
contentHeight: '2000',
contentWidth: 'auto',
layout: 'vertical'
});
var v1 = Ti.UI.createView({
height: Ti.UI.FILL,
width: Ti.UI.FILL,
backgroundColor: 'blue'
});
var v2 = Ti.UI.createView({
height: Ti.UI.FILL,
width: Ti.UI.FILL,
backgroundColor: 'green'
});
var v3 = Ti.UI.createView({
height: Ti.UI.FILL,
width: Ti.UI.FILL,
backgroundColor: 'red'
});
var v4 = Ti.UI.createView({
height: Ti.UI.FILL,
width: Ti.UI.FILL,
backgroundColor: 'purple'
});
var scrollable = Ti.UI.createScrollableView({
height: 300,
width: 400,
backgroundColor: 'pink',
views: [v1,v2,v3,v4]
});
scroll.add(scrollable);
win.add(scroll);
{quote} canCancelEvents : Boolean Determines whether this scroll view can cancel subview touches in order to scroll instead. Set to false to ensure that subview touches always take effect. Default: true {quote}
@Max: this doesn't really work in this case. Although setting canCancelEvents to false makes the ScrollableView working perfectly, the ScrollView behind it stops to react to any touch event - as they are prevented by the property. In particular, if I touch an "empty" space of the ScrollView, everything goes well, but if I touch any other view (a button, a label, a transparent container etc.), the scroll isn't captured. Below an updated sample code that shows what I mean:
I do have the ScrollableView on top (blue background), which just works seamlessly, but I cannot scroll down unless I touch the very little orange line between the ScrollableView and another View below it (left 50px on purpose in this example).
The same applies for MapView inside ScrollView and can be fixed by extending the native Android class for this view and adding this code:
Maybe this could be implemented and be enabled/disabled via a property?
We seem to have an even bigger problem in Titanium 3.0, in the sense that even with canCancelEvents: false, it's almost impossible to scroll the scrollableview now. I've traced that problem to this commit: https://github.com/appcelerator/titanium_mobile/commit/533f6d187c We'll no doubt have some parity issues to work out as well. My impression of using iOS on an iPhone _simulator_ is that it "just works" even without setting "canCancelEvents" at all (which means leaving it at its "true" default, I take it.)
I have a PR for this that will essentially block touch events to the scroll view from a scrollable view. You do no need to use 'canCancelEvents' to achieve this, so please test with the original test case. https://github.com/appcelerator/titanium_mobile/pull/3558 This PR also contains changes for the 'canCancelEvents' property, which should be tested against TIMOB-9955. The behavior for 'canCancelEvents' may be different in iOS since it's a native property there and I have updated the docs to say this as well.
This ticket has been pushed back about 3 sprints now. Is there an ETA when it will actually be merged in?
ScrollableView is now easy to scroll. Environment used for verification - Titanium SDK: 3.1.0.v20130223030327 Titanium Studio:3.0.2.201302141201 Device : Nexus 7 Android 4.1
Using SDK 3.1.1 with Alloy project, when I tried test code that has ScrollableView inside ScrollView, I get 2 different behaviors mentioned below: 1. Creating controls in controller -> I tested the code snippet provided in the JIRA ticket you mentioned, on Alloy controller, the scrollable view works fine. But, another big problem is that ScrollView does not respond if you swipe up/down direction initiating touch from scrollable view. 2. Creating controls in XML -> Scrollable view does not swipes smoothly and works only if swipe direction is horizontal. In an angular motion on scrollableview, scrollView starts scrolling. In this approach ScrollView has expected behavior while swiping up/down directions. Attached herewith both the code snippets.
Here is the sample code: 1. Creating controls in controller -> Used the original code in the issue and placed it in index.js 2. Creating controls in XML ->
Per Priti's comment above - this is still an issue.
[~psrivastava], 1. This is expected behavior. As I mentioned before, for the android implementation, we block off all events to the scroll view from a scrollable view. This is why a vertical scroll inside a scrollable view won't affect the scroll view. 2. In terms of scrolling not being smooth, this is native behavior. If you check out the demo at http://developer.android.com/training/animation/screen-slide.html, you get similar scrolling behavior. We just use the native ViewPager under the hood.
Verified fixed. TiSDK 3.2.0.v20131022050844 CLI 3.2.0 Titanium Studio 3.2.0.201310181940 Closing.