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): flatten ListView layout #14037

Merged
merged 9 commits into from
Aug 26, 2024
Merged

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented May 16, 2024

The current layout of the ListView/RecyclerView is a nested RelativeLayout:
Screenshot_20240516_110828

Having a flatter layout is always better for RecyclerView performance.

This PR will use the ConstraintLayout and removes the nested layers:
Screenshot_20240516_110809

Changes

  • flatten layout
  • use ConstraintLayout
  • minor update to recyclerview library (only fixes a sporadic crash in animations we don't use)
  • switch to AsyncListDiffer

Testing
I'm testing it with KitchenSink as that has 4 different ListView examples (editable, marker, multi select, normal with accessoryTypes) and this code:

var win = Ti.UI.createWindow();
var img = "./images/icon.png";

var myTemplate2 = {
	childTemplates: [
		{
			type: 'Ti.UI.Label',
			bindId: 'info',
			properties: { font: {fontSize: 20,fontWeight: 'bold'},left: 0,top: 0,}
		},
		{
			type: 'Ti.UI.Label',
			bindId: 'es_info',
			properties: { font: {fontSize: 14},left: 0,top: 25}}
	]
};

var myTemplate = {
	childTemplates: [{
			type: 'Ti.UI.ImageView',
			bindId: 'pic',
			properties: {width: 50,height: 50,left: 0, top: 0,backgroundColor: "#333"}
		},
		{
			type: 'Ti.UI.Label',
			bindId: 'info',
			properties: {font: {fontSize: 20,fontWeight: 'bold'},left: 60,top: 0,}},
		{
			type: 'Ti.UI.Label',
			bindId: 'es_info',
			properties: {font: {fontSize: 14},left: 60,top: 25,}
		}
	]
};

var listView = Ti.UI.createListView({
	templates: {
		'template': myTemplate,
		'myTemplate2': myTemplate2
	},
	//allowsSelectionDuringEditing: true,
	//allowsMultipleSelectionDuringEditing: true,
	editing: true,
	defaultItemTemplate: 'template'
});
var sections = [];

var fruitDataSet = []
for (var i=0;i<10;++i) {
	fruitDataSet.push({ info: {text: 'Apple'}, es_info: {text: 'Manzana'}, pic: {image: img}, properties: { accessoryType: Titanium.UI.LIST_ACCESSORY_TYPE_CHECKMARK}})
}
var fruitSection = Ti.UI.createListSection({ headerTitle: 'Fruits / Frutas', items: fruitDataSet});
sections.push(fruitSection);

var vegDataSet = []
for (var i=0;i<10;++i) {
	vegDataSet.push({ info: {text: 'Carrot'}, es_info: {text: 'Zanahoria'}, pic: {image: img}, properties: {canEdit: true, canMove:true}})
}
var hv = Ti.UI.createView({height: 100,backgroundColor: "#444"});
var vegSection = Ti.UI.createListSection({ headerView: hv, items: vegDataSet});
sections.push(vegSection);

var grainDataSet = [];
for (var i=0;i<10;++i) {
    grainDataSet.push({ info: {text: 'Corn'}, es_info: {text: 'Maiz'}, pic: {image: img}, properties: {template:'myTemplate2'}});
}
var fv = Ti.UI.createView({height: 100,backgroundColor: "#733"});
var grainSection = Ti.UI.createListSection({ headerTitle: 'Grains / Granos', items: grainDataSet, footerView: fv});
sections.push(grainSection);


var dataSet = [];
for (var i=0;i<10;++i) {
    dataSet.push({ info: {text: 'Corn'}, es_info: {text: 'Maiz'}, pic: {image: img}});
}
var grainSection = Ti.UI.createListSection({ headerTitle: 'Grains / Granos', items: dataSet, footerTitle: "footer"});
sections.push(grainSection);

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

@m1ga m1ga marked this pull request as ready for review May 21, 2024 13:14
@m1ga m1ga added the feature label May 23, 2024
@hansemannn
Copy link
Collaborator

@prashantsaini1 If you have time, it'd be great to test this with our app to see if it works well, as we also use some complex list views. You can grab a build from Github Actions

@hansemannn hansemannn merged commit b9fd683 into master Aug 26, 2024
6 checks passed
@hansemannn hansemannn deleted the androidListViewLayout branch August 26, 2024 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants