Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2728] Titanium.UI.ScrollableView.views is immutable on Android

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionNeeds more info
Resolution Date2011-12-29T05:00:05.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsn/a
ReporterSven Herzberg
AssigneePaul Dowsett
Created2011-11-24T04:01:03.000+0000
Updated2016-03-08T07:47:37.000+0000

Description

In iOS, we've been using this piece of code to insert a view into a ScrollableView before the last element:
/* initialize default window */
var win = Ti.UI.createWindow({backgroundColor: 'white'});
win.open();

/* initialize ScrollableView */
var sv = Ti.UI.createScrollableView({
	views: [Ti.UI.createView({backgroundColor: 'red'})]
});
win.add(sv);

/* actual test */
var views = sv.views;
try {
	views.splice(views.length - 1, 0, Ti.UI.createView({backgroundColor: 'green'}));
} catch (e) {
	Ti.API.error(String.format("Exeption: %s", e));
}
sv.views = views;
Now, on Android the splice() call in the code yields this exception: "Cannot find default value for object." This forces us to create a temporary array, populate it and then set the new array as the view array of the ScrollableView:
var views = [];
for(var i = 0; i < sv.views.length; i++) {
	views.push(sv.views[i]);
}
views.splice(views.length - 1, 0, Ti.UI.createView({backgroundColor: 'green'}));
sv.views = views;
This code is more verbose than necessary, it may introduce bugs (e.g. typos) and it is inconsistent with the behavior on iOS. Please fix.

Comments

  1. Paul Dowsett 2011-12-29

    Thanks for raising this ticket. In order for me to escalate it to the core team, all the fields must be complete. Please check it against the [JIRA Ticket Checklist](https://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report#HowtoSubmitaBugReport-JIRATicketChecklist), and add any missing information. Furthermore, a test case must run without modification, as per the [Creating a Test Case](https://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report#HowtoSubmitaBugReport-CreatingaTestCase) section. I will mark this resolved for now. Please reopen it once it is complete, and I will move it to the main project. Cheers
  2. Sven Herzberg 2012-01-03

    Updated the code example to be standalone.
  3. Paul Dowsett 2012-01-03

    Sven I have tested this, and it has been fixed in 1.8.0.1. Be aware for future that the environment field should only contain the versions of each component that exhibits the issue. Hence, only include the versions that you have physically tested. Cheers
  4. Paul Dowsett 2012-02-17

    Closing due to inactivity. If this issue still exists, please raise a new ticket, including all the information in the [JIRA Ticket Checklist](https://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report#HowtoSubmitaBugReport-JIRATicketChecklist) to ensure that we can escalate it quickly. Read [How to Submit a Bug Report](https://wiki.appcelerator.org/display/guides/How+to+Submit+a+Bug+Report) if you have not read it before, and always start a ticket using the [JIRA Ticket Template](https://wiki.appcelerator.org/display/guides/JIRA+Ticket+Template). Thanks in advance

JSON Source