Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17954] Android: ScrollView's ScrollTo(x,y) incorrect behavior (Parity)

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2017-03-09T19:05:20.000+0000
Affected Version/sRelease 3.3.0, Release 3.4.0
Fix Version/sRelease 6.1.0
ComponentsAndroid
LabelsTCSupport, android, scrollview
ReporterHani Hamadeh
AssigneeFrankie Merzadyan
Created2014-09-18T08:19:28.000+0000
Updated2017-03-24T21:35:09.000+0000

Description

Problem Description

ScrollTo function takes two coordinate parameters. When the default unit configured for the project is dp, the function still takes the parameters as system units instead causing a behavior disparity between iOS and Android.

Steps to reproduce

1. Create a new mobile project (classic titanium) 2. Paste this code into app.js:
 
var win = Titanium.UI.createWindow({  
    backgroundColor:'#fff',
    layout:'vertical'
});

var btn = Ti.UI.createButton({
	title : 'Scroll',
	height : 'auto',
	width : 'auto',
	top : 20,
	color:'#000'
});

btn.addEventListener('click', function() {
	scrollView.scrollTo(0,500);
});

var scrollView = Ti.UI.createScrollView({
		contentWidth : 'auto',
		contentHeight : 'auto',
		layout : "vertical",
		showVerticalScrollIndicator : false,
		showHorizontalScrollIndicator : true,
		height : '100%',
		width : '100%',
		scrollType : 'vertical',
		horizontalWrap : false,
		backgroundColor:'white',
		top:10
});

var view1 = Ti.UI.createView({
		height : '200',
		backgroundColor:'red'
});
var view2 = Ti.UI.createView({
		height : '200',
		backgroundColor:'green'
});
var view3 = Ti.UI.createView({
		height : '200',
		backgroundColor:'blue'
});
var view4 = Ti.UI.createView({
		height : '200',
		backgroundColor:'yellow'
});
win.add(btn);
win.add(scrollView);
scrollView.add(view1);
scrollView.add(view2);
scrollView.add(view3);
scrollView.add(view4);
win.open();

Extra info

This code scrolls to the middle of the third view on iOS. On Android the scroll location depends on the density of the device used.

Comments

  1. Anna 2016-04-20

    I'm having the same issue on Ti SDK 5.1.2.GA
  2. Anna 2016-04-21

    What units need scrollT(x,y) ??? dp or px?? on Android
  3. Fokke Zandbergen 2016-04-21

    Looking at the [source](https://github.com/appcelerator/titanium_mobile/blob/415bd6c66dcc55b1a59a59574f3babd3c3a84ede/android/modules/ui/src/java/ti/modules/titanium/ui/ScrollViewProxy.java#L121) I'd say px on Android. We should document (and improve that to accept default unit) that.
  4. Anna 2016-04-21

    Yes, I'm having a lot of problems with that. this is crazy!
  5. Aminul Islam 2016-12-26

    Hi, I have tested this issue with latest environment. Still this is a valid issue for android. Test Environment :
       Operating System
         Name                        = Mac OS X
         Version                     = 10.11.6
         Architecture                = 64bit
         # CPUs                      = 4
         Memory                      = 8589934592
       Node.js
         Node.js Version             = 4.4.4
         npm Version                 = 2.15.1
       Titanium CLI
         CLI Version                 = 5.0.11
       Titanium SDK
         SDK Version                 = 6.0.1.GA
       
    Thanks
  6. Frankie Merzadyan 2017-01-11

    master: https://github.com/appcelerator/titanium_mobile/pull/8743. The parity is still a bit off. I suggest a better way to scroll would be to scroll to actual UI components instead if you want precision and better consistency for behavior.
  7. Samir Mohammed 2017-03-24

    Verified fixed in 6.1.0.v20170313171259. Test and other information can be found at: https://github.com/appcelerator/titanium_mobile/pull/8743

JSON Source