problem
When calling Ti.UI.DashboardView.setData(), one would expect, like with Ti.UI.TableView, that the data given to the function call would reset the DashboardView. The problem is that instead of reseting it with the given array of DashboardItems, it instead appends the array to the existing list of data. This essentially leaves developers with no programmatic way to reset or remove items from the DashboardView. The remove() function operates on Views added to the Dashboard's view hierarchy, not its collection of items and will not work on DashboardItems.
This creates an issue with applications that contain a data model that describes the items. This existed originally in this Q&A question (unresolved):
http://developer.appcelerator.com/question/92191/bug-in-dashboardview-when-adding-view-items
Additionally, this is a problem for Alloy when it comes to data binding. Developers in Alloy should be able to define their DashboardItems as a collection and use binding to control the appearance of the DashboardView. As of now this is not possible and will cause unexpected behavior.
test case
Create a new Titanium mobile project
Run the following code for iOS (iphone sim is what I tested):
var win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
var data = [];
data.push(Ti.UI.createDashboardItem({
image: 'KS_nav_ui.png',
badge: 10,
label: 'test1',
customId: 'id1'
}));
data.push(Ti.UI.createDashboardItem({
image: 'KS_nav_views.png',
badge: 99,
label: 'test2',
customId: 'id2'
}));
var dash = Ti.UI.createDashboardView({
wobble: true,
data: data
});
dash.addEventListener('click', function(e) {
for (var i = 0; i < data.length; i++) {
if (data[i].customId === e.item.customId) {
data[i].badge = 0;
}
}
dash.data = data; // appends data, does not reset it
// dash.setData(data); // this doesn't work either
});
win.add(dash);
win.open();
Click a DashboardItem. It should set the badge to zero. It instead appends all the items again, having unexpected behavior with its re-rendering as well as with the resulting badge numbers.
PR https://github.com/appcelerator/titanium_mobile/pull/3964
Pull merged.
Tested with: SDK:3.1.0.v20130319222852 Studio: 3.0.2.201302191606 Device: iPad2(v 5.1)