Project: titanium
Issue TIMOB-18080: TableView: When removing the window and attaching it again scroll position is lost
h3. Issue In SDK 3.3.0 and higher when a tableView is scroll and the remove from the window and then added again to the window the scroll position is lost and restored to the original starting position, in SDK 3.2.X when doing this the tableView keeps the original position h3. Steps to repro 1. Run test code 2. Scroll the table 3. Click on a row 4. Click on the "Go Back" button Expected Result: The tableView will be displayed again with the last scroll position Actual Result: The tableView is displayed with the original scroll position (Y value:0) h3. Test Code {code} Titanium.UI.setBackgroundColor('#000'); var win = Titanium.UI.createWindow({ title:'Tab 1', backgroundColor:'#fff' }); var mainView = Ti.UI.createView({ top: 45 }); var tableView = Ti.UI.createTableView(); var rows = []; for (var i = 0; i < 40; i++) { rows.push(Ti.UI.createTableViewRow({ title: 'Row ' + i })); }; tableView.setData(rows); tableView.addEventListener('click', function(e) { mainView.add(anotherView); mainView.remove(tableView); }); var anotherView = Ti.UI.createView({ layout: 'absolute' }); var backButton = Ti.UI.createButton({ title: 'Go back' }); backButton.addEventListener('click', function(e) { mainView.add(tableView); mainView.remove(anotherView); }); anotherView.add(backButton); mainView.add(tableView); win.add(mainView); win.open(); {code} h3. Workaround In order to keep the las position its possible to use e.firstVisibleItem for android and e.contentOffset for iOS in order to keep a similar effect. {code} var win = Titanium.UI.createWindow({ title:'Tab 1', backgroundColor:'#fff' }); var mainView = Ti.UI.createView({ top: 45 }); var tableView = Ti.UI.createTableView(); var rows = []; for (var i = 0; i < 40; i++) { rows.push(Ti.UI.createTableViewRow({ title: 'Row ' + i })); }; tableView.setData(rows); tableView.addEventListener('click', function(e) { mainView.remove(tableView); backButton.visible=true; }); var backButton = Ti.UI.createButton({ title: 'Go back', top:10, visible:false }); var pos,scroll=false; backButton.addEventListener('click', function(e) { if(Ti.Platform.osname == 'android'){ tableView.scrollToIndex(pos); }else{ tableView.scrollToTop(pos.y,false); } mainView.add(tableView); backButton.visible=false; }); tableView.addEventListener('scroll',function(e){ if(Ti.Platform.osname == 'android'){ pos = e.firstVisibleItem; }else{ pos = e.contentOffset; } Ti.API.info(e.firstVisibleItem); }); win.add(backButton); mainView.add(tableView); win.add(mainView); win.open(); {code}
Story points: 13