Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11508] Android: Adding WebView to ScrollView causes ScrollView to be initialized scrolled-down

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-10-26T23:47:43.000+0000
Affected Version/sRelease 2.1.3
Fix Version/sRelease 2.1.4, Release 3.0.0, Release 3.1.0, 2012 Sprint 22 Core, 2012 Sprint 22
ComponentsAndroid
LabelsSupportTeam, core, module_scrollview, qe-review, qe-testadded
ReporterVarun Joshi
AssigneeAllen Yeung
Created2012-10-16T21:59:39.000+0000
Updated2014-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

  1. Allen Yeung 2012-10-26

    Another test case for horizontal scroll views:
       Titanium.UI.setBackgroundColor('#000');
       var win = Ti.UI.createWindow({
           backgroundColor : 'white'
       });
        
       //Create scroll view
       var scrollView = Titanium.UI.createScrollView({
           contentHeight : 'auto',
           layout : 'horizontal',
       	horizontalWrap: 'false',
           backgroundColor : 'transparent',
           scrollType : 'horizontal'
       });
        
       //Add to scrollView
       for (var i = 0; i < 20; i++) {
           scrollView.add(Titanium.UI.createView({
               height : 85,
               width : 50,
               backgroundColor : 'blue',
               left : 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,
           left : 10,
           height : 40
       });
        
       scrollView.add(webView);
        
       win.add(scrollView);
       win.open(); 
       
  2. Blain Hamon 2012-10-26

    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 or UITableView objects in UIScrollView 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.
  3. Allen Yeung 2012-10-26

    PR: https://github.com/appcelerator/titanium_mobile/pull/3338
  4. Ping Wang 2012-10-26

    2_1_X PR: https://github.com/appcelerator/titanium_mobile/pull/3341
  5. Allen Yeung 2012-10-26

    3_0_X PR: https://github.com/appcelerator/titanium_mobile/pull/3345
  6. Natalie Huynh 2012-11-01

    Tested with 2.1.4.v20121030173408 on Droid 3 2.3.4

JSON Source