Titanium JIRA Archive
Appcelerator Community (AC)

[AC-4965] View dissapaears after loading views in scrollableView and setting currentPage

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionFixed
Resolution Date2017-05-16T16:06:00.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsn/a
ReporterFabian Martinez
AssigneeShak Hossain
Created2017-05-15T19:44:17.000+0000
Updated2017-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

FileDateSize
app.zip2017-05-15T19:42:05.000+00007119507

Comments

  1. Fabian Martinez 2017-05-16

    Sorry, I was able to fix this problem by adding $.receiptContainer.scrollToView(1); after $.receiptContainer.setCurrentPage(1);

JSON Source