[AC-4965] View dissapaears after loading views in scrollableView and setting currentPage
GitHub Issue | n/a |
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2017-05-16T16:06:00.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | n/a |
Reporter | Fabian Martinez |
Assignee | Shak Hossain |
Created | 2017-05-15T19:44:17.000+0000 |
Updated | 2017-05-16T16:06:00.000+0000 |
Description
I have a scrollableView with 3 views.
If I scroll to left or right I want to load a new view in the scrollableView.
The problem is that after loading the views in the scrollableView and setting the currentView, the view disappears. This is somehow related to TIMOB-20199 but that example works. If I don't include this code: $.receiptContainer.setCurrentPage(1); everything works.
The main problem I try to resolve is that I have a lot of transactions and the app crashes if I load them all on a scrollableView, so I made a scrollable with only 3 views and try to change views while the user scrolls. I'm aware of the flickering but that's acceptable.
I've attached the app directory.
Actual behavior: When scrolling the view disappears after loading new views and setCurrentPage to 1.
Expected behavior: View should be visible and currentPage should be 1 after setCurrentPage to 1.
*Index.js*
function doClick(e) {
alert($.label.text);
}
$.win.open();
var all_views = [];
var views = [];
for (var i=0;i<10;i++){
var v = Alloy.createController('singleview', {title: i}).getView(); //A view with a label that shows i
all_views.push(v); //Add new view
}
var len = all_views.length;
var minIndex = 5;
maxIndex = 7;
for (var i=minIndex;i<=maxIndex;i++){
var v = all_views[i];
views.push(v);
$.receiptContainer.addView(v);
}
var currentIndex = 1;
$.receiptContainer.addEventListener('scrollend',function(e){
if (e.currentPage == 2){
if (maxIndex+1<=len-1){
maxIndex++;
var v = all_views[maxIndex];;
views.push(v); //Add new view
if (views.length>3){
views.shift(); //remove first view
minIndex++;
}
$.receiptContainer.setViews(views);
$.receiptContainer.setCurrentPage(1);
}
} else if (e.currentPage ==0){
if (minIndex-1>=0){
minIndex--;
var v = all_views[minIndex];;
views.unshift(v); //Add new view at beginning
if (views.length>3){
views.pop(); //remove last view
maxIndex--;
}
$.receiptContainer.setViews(views);
$.receiptContainer.setCurrentPage(1);
}
}
});
//Another way to test it, comment the scroll event and use a button instead, will make same effect
var button = Titanium.UI.createButton({title: 'click to load new views',bottom: 10,width: 100,height: 50});
$.win.add(button);
button.addEventListener('click',function(e)
{
$.receiptContainer.views = [all_views[1],all_views[2],all_views[3]];
$.receiptContainer.setCurrentPage(1);
});
Attachments
File | Date | Size |
app.zip | 2017-05-15T19:42:05.000+0000 | 7119507 |
Sorry, I was able to fix this problem by adding $.receiptContainer.scrollToView(1); after $.receiptContainer.setCurrentPage(1);