Description
When calling setMarker with an itemIndex or sectionIndex value that is greater than the total items or sections an error like below is thrown. This did not occur in 9.2.2.GA
[ERROR] TiExceptionHandler: (main) [76,76] /app.js:12
[ERROR] TiExceptionHandler: listView.addMarker({
[ERROR] TiExceptionHandler: ^
[ERROR] TiExceptionHandler: Error: Index: 1, Size: 1
[ERROR] TiExceptionHandler: at /app.js:12:10
[ERROR] TiExceptionHandler: at Module._runScript (ti:/module.js:587:9)
[ERROR] TiExceptionHandler: at Module.load (ti:/module.js:106:7)
[ERROR] TiExceptionHandler: at Module.loadJavascriptText (ti:/module.js:436:9)
[ERROR] TiExceptionHandler: at Module.loadAsFile (ti:/module.js:488:15)
[ERROR] TiExceptionHandler: at Module.loadAsFileOrDirectory (ti:/module.js:410:20)
[ERROR] TiExceptionHandler: at Module.require (ti:/module.js:239:23)
[ERROR] TiExceptionHandler: at Module.global.Module.require (<embedded>:5050:34)
[ERROR] TiExceptionHandler: at require (ti:/module.js:550:15)
[ERROR] TiExceptionHandler: at global.require (<embedded>:5034:10)
[ERROR] TiExceptionHandler:
[ERROR] TiExceptionHandler: java.util.ArrayList.get(ArrayList.java:437)
[ERROR] TiExceptionHandler: ti.modules.titanium.ui.widget.listview.ListViewProxy.getSectionByIndex(ListViewProxy.java:207)
[ERROR] TiExceptionHandler: ti.modules.titanium.ui.widget.listview.ListViewProxy.addMarker(ListViewProxy.java:72)
[ERROR] TiExceptionHandler: org.appcelerator.kroll.runtime.v8.V8Runtime.nativeRunModule(Native Method)
[ERROR] TiExceptionHandler: org.appcelerator.kroll.runtime.v8.V8Runtime.doRunModule(V8Runtime.java:172)
[ERROR] TiExceptionHandler: org.appcelerator.titanium.TiApplication.launch(TiApplication.java:872)
[ERROR] TiExceptionHandler: org.appcelerator.titanium.TiLaunchActivity.loadScript(TiLaunchActivity.java:96)
[ERROR] TiExceptionHandler: org.appcelerator.titanium.TiRootActivity.loadScript(TiRootActivity.java:500)
[ERROR] TiExceptionHandler: org.appcelerator.titanium.TiLaunchActivity.onResume(TiLaunchActivity.java:177)
[ERROR] TiExceptionHandler: org.appcelerator.titanium.TiRootActivity.onResume(TiRootActivity.java:519)
[ERROR] V8Exception: Exception occurred at /app.js:12: Uncaught Error: Index: 1, Size: 1
var win = Ti.UI.createWindow({backgroundColor: 'gray' });
var listView = Ti.UI.createListView();
var sections = [];
var vegSection = Ti.UI.createListSection({ headerTitle: 'Vegetables' });
var vegDataSet = [
{properties: { title: 'Carrots'}},
{properties: { title: 'Potatoes'}},
];
vegSection.items = vegDataSet;
sections.push(vegSection);
listView.sections = sections;
listView.addMarker({
itemIndex: 0,
sectionIndex: 1
});
win.add(listView);
win.open();
Steps to reproduce
1. Add the code below to an existing app.js
2. Run on Android
Actual
Runtime error and RSOD
Expected
-Maybe a warning log given that technically this is an error case?- <- This is wrong, see comment
Marker should be setup and work correctly
Did some testing on 9.2.2.GA and it appears that setting a marker that doesn't exist yet works totally fine, and will work correctly when it exists in future. With the below code, after adding a new section and scrolling to the bottom the marker event will have fired
master: https://github.com/appcelerator/titanium_mobile/pull/12350
The below test script is a practical use-case for ListView markers where when you scroll to the bottom, it loads more rows, and when you scroll to the bottom again it loads more rows. It doesn't test for the bug mentioned on this ticket, but it is another common way of implementing markers. [^ListViewMarkerTest.js]
FR Passed. Waiting for Jenkins build.
merged to master, backport for 9_3_X merged to 9.3.1 target.