Project: titanium
Issue TIMOB-19335: iOS: ListView editActions specify better action
Since 4.1.0.Beta we got a really super-duper feature: https://docs.appcelerator.com/platform/latest/#!/guide/ListViews-section-37521650_ListViews-ActionItems But one thing is not really charming. The listener for which action is pressed by the user has to be the title of the edit button? That seems very untypical. *Existing example* {code:javascript} var win = Ti.UI.createWindow({backgroundColor: 'white'}), favoriteAction = { title: 'Favorite', style: Ti.UI.iOS.ROW_ACTION_STYLE_DEFAULT }, unfavoriteAction = { title: 'Unfavorite', style: Ti.UI.iOS.ROW_ACTION_STYLE_NORMAL }, data = [ {properties: {canEdit: true, editActions: [favoriteAction], title: 'Kitten Whiskers'}}, {properties: {canEdit: true, editActions: [favoriteAction], title: 'Copper Kettle'}}, {properties: {canEdit: true, editActions: [favoriteAction], title: 'Woolen Mittens'}}, {properties: {canEdit: true, editActions: [favoriteAction], title: 'Apple Strudel'}}, {properties: {canEdit: true, editActions: [favoriteAction], title: 'Brown Packages'}}, {properties: {canEdit: true, editActions: [favoriteAction], title: 'Dog Bites'}}, {properties: {canEdit: true, editActions: [favoriteAction], title: 'Bee Stings'}} ], listSection = Ti.UI.createListSection({ items: data }), listView = Ti.UI.createListView({ top: 15, sections: [listSection] }); listView.addEventListener('editaction', function(e) { var item = e.section.getItemAt(e.itemIndex) if (e.action === 'Favorite') { item.properties.editActions = [unfavoriteAction]; } else if (e.action === 'Unfavorite') { item.properties.editActions = [favoriteAction]; } e.section.updateItemAt(e.itemIndex, item); }); win.add(listView); win.open(); {code} *Should be example* {code:javascript} var win = Ti.UI.createWindow({backgroundColor: 'white'}), favoriteAction = {	action: 'setFavorite', title: 'Favorite', style: Ti.UI.iOS.ROW_ACTION_STYLE_DEFAULT }, unfavoriteAction = {	action: 'unsetFavorite', title: 'Unfavorite', style: Ti.UI.iOS.ROW_ACTION_STYLE_NORMAL }, data = [ {properties: {canEdit: true, editActions: [favoriteAction], title: 'Kitten Whiskers'}}, {properties: {canEdit: true, editActions: [favoriteAction], title: 'Copper Kettle'}}, {properties: {canEdit: true, editActions: [favoriteAction], title: 'Woolen Mittens'}}, {properties: {canEdit: true, editActions: [favoriteAction], title: 'Apple Strudel'}}, {properties: {canEdit: true, editActions: [favoriteAction], title: 'Brown Packages'}}, {properties: {canEdit: true, editActions: [favoriteAction], title: 'Dog Bites'}}, {properties: {canEdit: true, editActions: [favoriteAction], title: 'Bee Stings'}} ], listSection = Ti.UI.createListSection({ items: data }), listView = Ti.UI.createListView({ top: 15, sections: [listSection] }); listView.addEventListener('editaction', function(e) { var item = e.section.getItemAt(e.itemIndex) if (e.action === 'setFavorite') { item.properties.editActions = [unfavoriteAction]; } else if (e.action === 'unsetFavorite') { item.properties.editActions = [favoriteAction]; } e.section.updateItemAt(e.itemIndex, item); }); win.add(listView); win.open(); {code} As you see, the developer can define the action himself. Otherwise I have to compare on localized strings. That's not a good coding behavior . What do you think?
Story points: 2