Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15848] iOS: Clearing listView doesn't work properly when use with scrollToItem(i,i,animation:false)

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-01-02T21:31:05.000+0000
Affected Version/sRelease 3.1.3, Release 3.2.0
Fix Version/s2013 Sprint 26, 2013 Sprint 26 API, Release 3.2.1, Release 3.3.0
ComponentsiOS
LabelsListViews, module_listview, qe-testadded, supportTeam
ReporterMeenakshi Pathak
AssigneeVishal Duggal
Created2013-11-28T11:45:36.000+0000
Updated2014-06-19T12:44:41.000+0000

Description

When we use scrollToItem with animation:false in a listView,clear listView doesn't work properly. However, if use scrollToItem with 'animation:true', everything works fine. *Steps To Reproduce* : 1. Create a new titanium classic project. 2. Copy and paste the below code in app.js :
var win = Ti.UI.createWindow({
	backgroundColor : 'white'
});
var view = Ti.UI.createView({});
var btn = Ti.UI.createButton({
	top : 20,
	backgroundColor : 'red',
	width : 100,
	title : 'Clear'
});

view.add(btn);
win.add(view);
var myTemplate = {
	childTemplates : [{
		type : 'Ti.UI.Label',
		bindId : 'one',
		properties : {
			color : 'black',
			font : {
				fontFamily : 'Arial',
				fontSize : '14dp'
			},
			left : '10dp'
		}
	}, {
		type : 'Ti.UI.Label',
		bindId : 'two',
		properties : {
			color : 'black',
			font : {
				fontFamily : 'Arial',
				fontSize : '14dp'
			},
			left : '50dp'
		}
	}, {
		type : 'Ti.UI.Label',
		bindId : 'three',
		properties : {
			color : 'gray',
			font : {
				fontFamily : 'Arial',
				fontSize : '14dp'
			},
			left : '90dp'
		}
	}, {
		type : 'Ti.UI.Label',
		bindId : 'four',
		properties : {
			color : 'gray',
			font : {
				fontFamily : 'Arial',
				fontSize : '14dp'
			},
			left : '130dp'
		}
	}, {
		type : 'Ti.UI.Label',
		bindId : 'five',
		properties : {
			color : 'gray',
			font : {
				fontFamily : 'Arial',
				fontSize : '14dp'
			},
			left : '170dp'
		}
	}, {
		type : 'Ti.UI.Label',
		bindId : 'six',
		properties : {
			color : 'gray',
			font : {
				fontFamily : 'Arial',
				fontSize : '14dp'
			},
			left : '210dp'
		}
	}, {
		type : 'Ti.UI.Label',
		bindId : 'seven',
		properties : {
			color : 'gray',
			font : {
				fontFamily : 'Arial',
				fontSize : '14dp'
			},
			left : '240dp'
		}
	}]
};

var genData = function(section) {
	var data = [];
	for ( i = 0; i < 20; i++) {
		data.push({
			one : {
				text : section + ' one'
			},
			two : {
				text : 'two'
			},
			three : {
				text : 'three'
			},
			four : {
				text : 'four'
			},
			five : {
				text : 'five'
			},
			six : {
				text : 'six'
			},
			seven : {
				text : 'seven'
			},
			template : 'template'
		});
	}

	return data;
};

var genSections = function() {
	var sections = [];
	for ( j = 0; j < 10; j++) {
		var section = Ti.UI.createListSection({
			headerTitle : 'Section ' + j
		});
		section.setItems(genData(j));
		sections.push(section);
	}

	return sections;
};
var listView = Ti.UI.createListView({
	top : 100
});
function populateEventsList() {

	listView.templates = {
		'template' : myTemplate
	};
	listView.setSections(genSections());

}

btn.addEventListener('click', function() {

	var length = listView.sections.length;
	if (length === 0) {
		populateEventsList();
		btn.title = 'Clear';
		listView.scrollToItem(5, 3, {
			animated : false,

		});
	} else {
		listView.setSections([]);
		btn.title = 'Populate';
	}

});

populateEventsList();
win.add(listView);
win.open();
2. Launch the application in iOS7 simulator/device. 3. Click on 'Clear' button and you will see everything clears perfectly fine. 4. Click on 'Populate' button and you will see everything populates as expected. 5. Now again click on 'Clear' button, you will see listView doesn't cleared properly.

Comments

  1. Ingo Muschenetz 2013-11-28

    Can you please confirm this also happens against SDK 3.2.0?
  2. Betty Tran 2013-12-02

    Tested on 3.2.0.v20131105162443.21b6737, the issue is still occurring. To clarify, the list view does not clear as the first section header is still displayed.
  3. Sabil Rahim 2014-01-02

    fixed by https://github.com/appcelerator/titanium_mobile/pull/5156
  4. Vishal Duggal 2014-01-03

    Backport to 3_2_X https://github.com/appcelerator/titanium_mobile/pull/5181
  5. Paras Mishra 2014-01-07

    Tested with above testapp, listview is getting cleared every time after populating the list Verified fix on: Device : iPhone 5s , iOS version : 7.0.2 SDK: 3.3.0.v20140106195650 SDK: 3.2.1.v20140106195644 CLI version : 3.2.0 OS : MAC OSX 10.9 Alloy: 1.3.1-beta ACS: 1.0.11 npm:1.3.2 Appcelerator Studio, build: 3.2.1.201401061716 titanium-code-processor: 1.1.0 XCode : 5.0.2
  6. Wilson Luu 2014-01-07

    Closing ticket as fixed. Verified the ListView gets cleared properly after populating it with rows. Tested on: Appcelerator Studio, build: 3.2.1.201401061716 SDK build: 3.2.1.v20140106195644, 3.3.0.v20140106195650 CLI: 3.2.0 Alloy: 1.3.1-beta Xcode: 5.0.2 Devices: iphone 4s (6.0.1), iphone 5s (7.0.2), iphone simulator 4-inch retina (6.1), iphone simulator 4-inch retina (7.0.3)

JSON Source