Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): add flag to ListView to ignore recycling #13884

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Jul 26, 2023

When preventRecycling is set to true it won't recycle the ListItem. This can be useful if you add TextFields or Switches into your template. Otherwise they will return to the creation value.

var win = Ti.UI.createWindow();

var myTemplate = {
	childTemplates: [{
			type: 'Ti.UI.TextField',
			properties: {
				left: 10,
				width: 100
			}
		}, {
			type: 'Ti.UI.Label',
			bindId: "text",
		},
		{
			type: 'Ti.UI.Switch',
			properties: {
				right: 10,
			}
		}
	]
};

var listView = Ti.UI.createListView({
	// preventRecycling: true,
	templates: {
		'template': myTemplate
	},
	defaultItemTemplate: 'template'
});
var sections = [];
var items = [];
for (var i = 0; i < 100; ++i) {
	items.push({
		text: {
			text: "prevent: " + (i % 2)
		},
		properties: {
			preventRecycling: i % 2,     // <-------- new property
		}
	})
}

var fruitSection = Ti.UI.createListSection({
	items: items
});
sections.push(fruitSection);

listView.sections = sections;
win.add(listView);
win.open();

Instead of having it in the ListView I've added it to the ListItem properties.

@m1ga m1ga marked this pull request as draft July 27, 2023 13:05
@m1ga m1ga marked this pull request as ready for review July 27, 2023 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant