Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3434] ScrollView: Not able to set default scroll position of content to be viewed.

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionInvalid
Resolution Date2017-05-02T21:47:28.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labelsdefault, defaultscrollposition, position, scroll, scrollview, tbs-1.9.0
ReporterTigerMunky
AssigneeIngo Muschenetz
Created2011-04-15T03:45:09.000+0000
Updated2017-05-02T21:47:28.000+0000

Description

Howdy!

After/during creating a scrollView, I would like to be able to set the default starting position of the content viewed.

e.g.


var scrollView = Ti.UI.createScrollView({

{mkd-extraction-47bdccb44f8a2210a9ce265263aa5916}

});

or


var scrollView = Ti.UI.createScrollView({

{mkd-extraction-03d353c087c05a7679e3039f2021f6fc}

}); scrollView.scrollTo(250, 0); <-- works but straight after this event is fired, another scroll event sets the position to 0,0. I think the "resetting/default scroll event" occurs when the window is opened.
// add more content to scrollView

win.add(scrollView);
win.open();

I think the property "defaultScrollPosition: [250, 0]" would be great.

Tested on the KitchenSink example - scroll_views_tabs.js

Thanks in advance!

TM

Comments

  1. Francisco Antonio Duran Ramirez 2011-09-25

    Problem

    A scrollView created by Ti.UI.createScrollView always seems to start at position (0, 0) regardless of what you set contentOffset to. If you set scrollView.contentOffset after the view is already on the screen, then it does have an effect (of casual scrolling...).

    Reproducible steps:

    1.Run the code below.

    Expected behavior

    Customer wants to scroll to a specific point.

    Sample Code:

       var win = Titanium.UI.createWindow({  
           layout:'vertical',
           backgroundColor:'#fff'
       });
       
       var scrollView = Ti.UI.createScrollView({
       	showHorizontalScrollIndicator:true, showVerticalScrollIndicator:true,
       	width: 250, height: 250, top: 50,
       	borderColor:'green', borderWidth:1,
       	contentWidth:1000, contentHeight:1000,
       	contentOffset: { x:600, y:600}
       });
       
       for(var i=0; i<10; i++) {
       	for(var j=0; j<10; j++) {
       		scrollView.add(Ti.UI.createLabel({
       			top:i*100, left:j*100,
       			width:100, height:100,
       			text:i+':'+j, textAlign:'center',
       			color:'white',
       			backgroundColor:'#A0' + Number(i%2*8).toString(16) +'0'+ Number(8-j%2*8).toString(16)+'0',
       			borderColor:'black', borderWidth:1 
       		}));
       	}
       }
       
       var button = Ti.UI.createButton({title:'Center', width:100, height:50});
       button.addEventListener('click', function() {
       	scrollView.contentOffset = { x:450, y:450};
       });
       
       scrollView.addEventListener('scroll', function() {
       	Ti.API.info('Offset: (' + scrollView.contentOffset.x + ', ' + scrollView.contentOffset.y + ')');
       });
       win.add(scrollView);
       win.add(button);
       win.open();
       
       
  2. Zsombor Papp 2011-09-26

  3. Be Rushton 2014-10-29

    Quite surprised this bug is still open... seems like a common thing to be able to do... There is currently no way to set the content offset on creation. The only way is to set the property after the view has been laid out :(
  4. Lee Morris 2017-05-02

    Resolving ticket as Invalid as there is now a new version of Kitchen Sink available and we no longer support the version which relates to this ticket.

JSON Source