[TIMOB-11508] Android: Adding WebView to ScrollView causes ScrollView to be initialized scrolled-down
GitHub Issue | n/a |
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-10-26T23:47:43.000+0000 |
Affected Version/s | Release 2.1.3 |
Fix Version/s | Release 2.1.4, Release 3.0.0, Release 3.1.0, 2012 Sprint 22 Core, 2012 Sprint 22 |
Components | Android |
Labels | SupportTeam, core, module_scrollview, qe-review, qe-testadded |
Reporter | Varun Joshi |
Assignee | Allen Yeung |
Created | 2012-10-16T21:59:39.000+0000 |
Updated | 2014-06-19T12:42:42.000+0000 |
Description
Issue
When a WebView is added to a ScrollView containing multiple views stacked vertically, the scrollView get scrolled down to where the WebView has been added (bottom), causing the page to load with the ScrollView initially displaying Accounts near the bottom of the list.
Sample Test case
{noformat}
Titanium.UI.setBackgroundColor('#000');
var win = Ti.UI.createWindow({
backgroundColor : 'white'
});
//Create scroll view
var scrollView = Titanium.UI.createScrollView({
contentHeight : 'auto',
layout : 'vertical',
backgroundColor : 'transparent',
showVerticalScrollIndicator : true
});
//Add to scrollView
for (var i = 0; i < 20; i++) {
scrollView.add(Titanium.UI.createView({
height : 85,
width : 300,
backgroundColor : 'blue',
top : 10,
borderRadius : 6
}));
}
//Add webView -- causes scrollView to scroll down
var webView = Ti.UI.createWebView({
touchEnabled : false,
showScrollbars : false,
scrollType : 'vertical',
willHandleTouches : false,
backgroundColor : 'red',
scrollable : false,
top : 20,
height : 40
});
scrollView.add(webView);
win.add(scrollView);
win.open();
{noformat}
*In iOS, the top most view is visible first.*
Comments
JSON Source
Another test case for horizontal scroll views:
I would highly suggest *not* putting web views in scroll views, *especially* in iOS. In [Apple's own docs ](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWebView_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006950-CH3-DontLinkElementID_1) they stipulate: bq. *Important:* You should not embed
UIWebView
orUITableView
objects inUIScrollView
objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled. UIScrollView is the underlying iOS class behind Ti.UI.ScrollView and Ti.UI.ScrollableView. Long ago, I saw the issue first hand, outside of Titanium. If you have a web view in a scroll view in iOS, you risk the web view becoming unresponsive and never visually updating, with no means to detect nor fix it. Fun times.PR: https://github.com/appcelerator/titanium_mobile/pull/3338
2_1_X PR: https://github.com/appcelerator/titanium_mobile/pull/3341
3_0_X PR: https://github.com/appcelerator/titanium_mobile/pull/3345
Tested with 2.1.4.v20121030173408 on Droid 3 2.3.4