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

fix(android): tableview content update fix #14169

Closed
wants to merge 1 commit into from
Closed

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Jan 8, 2025

Issue

A user reported an issue on Slack that a label inside a tableview is not updating when setting a new value.
The event fix in #13826 seems to be the culprit. While it fixed the event issue it introduced the label update issue.

Solution

After a few tests it looks like we only have to set/update the parent IF it already had one (when a user reassigns the data) and not if it stays the same data (just updating the label).

I've added a simple null check and update only if there is already a parent. This way both tests (event and label) work fine:

Test 1:

see #13826 for more details

var menu = [];
var lab = Ti.UI.createLabel({text: "Row 0"});
var numrows = 0;

var self = Ti.UI.createWindow({title: "Table Test"});
var table = Ti.UI.createTableView({});

table.addEventListener("click", function(e) {
  console.log("Row " + e.index);
  lab.text = "Clicked " + e.index;
  menu[1].title = "Clicked " + e.index;
  if (e.index == numrows - 1)
    AddRows();
});

function AddRows() {
  var row = Ti.UI.createTableViewRow({title: "Row " + numrows});
  if (menu.length == 0)
    row.add(lab);
  menu.push(row);
  numrows++;
  var row = Ti.UI.createTableViewRow({title: "Row " + numrows});
  menu.push(row);
  numrows++;
  table.data = menu;
};

AddRows();
self.add(table);
self.open();
  • start and click the last row a few times
  • then click any other row and see if the click event still works

Test 2

var win = Ti.UI.createWindow();
var tableData = [];

for (var i=1; i<=10; i++){
  var row = Ti.UI.createTableViewRow({
    className: 'forumEvent', // used to improve table performance
	height: 50
  });
  var labelUserName = Ti.UI.createLabel({
    text: 'Fred Smith ' + i,
	left: 10
  });
  row.add(labelUserName);
  tableData.push(row);
}

var tableView = Ti.UI.createTableView({
  data: tableData
});

win.add(tableView);
win.open();
tableView.data[0].rows[0].children[0].text = "test"
  • start and see if the first label says "test"

--

Test 3

var self = Ti.UI.createWindow({title: "Table Test"});
var table = Ti.UI.createTableView({});

function AddRows() {
	const rows = [];
	for (let i = 0; i < 20; i++) {
		var row = Ti.UI.createTableViewRow({
			title: "Row " + i,
			color: 'black',
			height: 100
		});

		row.add(createRowView());
		
		rows.push(row);
	}
	
	table.data = rows;
};

function createRowView() {
	const imageView = Ti.UI.createImageView({
		height: 80,
		width: 120
	});
	
	// This works on all versions.
	// imageView.image = 'https://picsum.photos/200/300';

	// This does not work on 12.6.1.GA. Use any timeout >=1, or as a result of HTTP call here.
	setTimeout(() => {
		imageView.image = 'https://picsum.photos/200/300';
	}, 1000);

	return imageView;
}

self.add(table);
self.open();
AddRows();
  • images should show up

Currently tested by a Slack user: Feedback was: it's working

@prashantsaini1
Copy link
Contributor

As mentioned in important notes #1, these issues are not valid ones since this is not how the TableView's data property should be used. update/append/delete methods are necessary to alter views since they internally triggers model-data and native view updates.

@@ -189,8 +189,10 @@ private void appendRowInternal(Object rows, KrollDict animation, boolean interna
row.getProperties().optString(TiC.PROPERTY_FOOTER_TITLE,
row.getProperties().getString(TiC.PROPERTY_FOOTER)));

if (row.getParent() != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this conditional code as it would cause more issues because it's changing the parent-section of a row from one to another without properly removing the row from its previous parent-section first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then we have the same code as before and it won't behave the same way it did in 12.5.1 where you were able to set content without running update. Can you create a PR with a proper solution for both cases

@prashantsaini1
Copy link
Contributor

@m1ga The issue reported by Slack user can be resolved via existing methods by properly using TableView. This PR can simply revert the previous changes. 😉

@m1ga m1ga closed this Jan 8, 2025
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.

2 participants