Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17491] Android: contentOffset property of UI.ScrollView not accessible

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-11-04T22:42:44.000+0000
Affected Version/sRelease 3.4.0
Fix Version/sRelease 3.4.2, Release 3.5.0, Release 4.0.0
ComponentsAndroid
Labelsandroid, contentOffset, parity, scrollview
ReporterKevin Frugier
AssigneeHieu Pham
Created2014-08-11T13:59:17.000+0000
Updated2015-04-19T16:07:09.000+0000

Description

The contentOffset property (reflecting what's currently visible in a ScrollView), is undefined on Android. Documentation of [UI.ScrollView|(http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.ScrollView-property-contentOffset] says it's available on Android since 0.9, however in version 3.3.0 GA it (still?) doesn't work.

Notes

* contentOffset is not set manually anywhere in the test code * I'm talking about UI.ScrollView, not tableview or listview

How to reproduce

Create a ScrollView
<Alloy>
	<ScrollView id="myscrollview" />
</Alloy>
In the controller, try to get the value of the property :
alert($.myscrollview.contentOffset.x);

Actual result

On iOS : the value is properly displayed and reflects any scrolling (manual or not) done on the ScrollView On Android : a runtime error occurs with the following message : {panel:title=Runtime Error} Message: Uncaught TypeError: Cannot read property 'x' of undefined Source: alert($.myscrollview.contentOffset.x); {panel}

Expected result

Both iOS & Android should produce the same result. Looking at the source of [TiUIScrollView.java](https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUIScrollView.java) we see that indeed the property is supposed to be updated upon scrolling. However the property is not accessible from JavaScript on Android. (Could it be a problem in the proxy?)

Comments

  1. Shuo Liang 2014-08-12

    Can reproduce with SDK 3.2.3 GA and 3.3.0 GA on Android 4.2.2. Here is a simple test case.
       var win = Ti.UI.createWindow({
         backgroundColor: 'white',
         exitOnClose: true,
         fullscreen: false,
         title: 'ScrollView Demo'
       });
       
       var scrollView = Ti.UI.createScrollView({
         contentWidth: 'auto',
         contentHeight: 'auto',
         showVerticalScrollIndicator: true,
         showHorizontalScrollIndicator: true,
         height: '80%',
         width: '80%'
       });
       var view = Ti.UI.createView({
         backgroundColor:'#336699',
         borderRadius: 10,
         //top: 10,
         height: 2000,
         width: 1000
       });
       
       // output the contentOffset value
       Ti.API.info(scrollView.contentOffset.x);
       
       scrollView.add(view);
       win.add(scrollView);
       win.open();
       
  2. Hieu Pham 2014-10-30

    master PR: https://github.com/appcelerator/titanium_mobile/pull/6292 3.4.X PR: https://github.com/appcelerator/titanium_mobile/pull/6313
  3. Satyam Sekhri 2014-11-25

    The contentOffset property for ScrollView is accessible now and does not show any error. Tested with both the alloy and classic code provided. Verified on: SDK: 3.5.0.v20141124155715 Studio: 3.4.1.201410281743 CLI: 3.4.1 Alloy: 1.5.1 Device: Samsung Galaxy S5 (v4.4.2)
  4. Rainer Schleevoigt 2015-04-19

    It doesn't work with SDK3.5.1.GA

JSON Source