[TIMOB-16879] ScrollableView: Add "insertViewsAt()" method
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-04-26T23:19:31.000+0000 |
Affected Version/s | Release 3.2.2 |
Fix Version/s | Release 5.4.0 |
Components | Android, iOS |
Labels | insert, scrollableView |
Reporter | Ed |
Assignee | Hans Knöchel |
Created | 2014-04-16T21:27:17.000+0000 |
Updated | 2018-12-14T13:12:23.000+0000 |
Description
The ScrollableView currently supports the ".addView()" method to programmatically append additional views to the end of the collection. However, it has no method to insert one or more views at the beginning (prepend), or somewhere in the middle of the collection.
A [suggested workaround](http://developer.appcelerator.com/question/161891/scrollable-view---insert-a-view-into-a-specific-spot) for this limitation involves getting the views array with .getViews(), updating the array, then re-assiging the views array back to the control with .setViews(). While this works, it is not efficient and causes significant flickering on the UI with complex views, every time .setViews() is used.
It would be great to have a method like ".insertViewsAt(idx, views)" so one item (or more) can be prepended or inserted at specific locations without requiring the entire views collection to be re-bound and rendered.
This would also bring the ScrollableView control in line with ListView and TableView, both of which feature "insert" methods.
In my particular case; I'm using a ScrollableView to page through over 500 views which are fairly complex. Loading all views into the ScrollableView is not an option as that takes too much memory and crashes the app. My solution is to have a sliding range that loads 9 views at a time (4 before and 4 after the current page) on the ScrollableView. And as the user moves left or right, it dynamically prepends or appends more views as needed, removing views also from the opposite end so only 9 views are loaded at any given time. Appending with addView() works well (no need for setViews(), so no flickering), but prepending with the getViews()/update/setViews() process does not work well in these situations.
Thanks for the nice writeup. I am curious if you have played around with cacheSize property of ScrollableView for your use case.
Moving this feature request to engineering for further evaluation and prioritization.
+1 for that feature
Please implement this feature.
+1 !!!
+1, very much needed. There currently seems to be no way to have an endless scrolling scrollableview without flickerings.
Hope to see this soon alive!
@nuno, that's a different use case - vertical/horizontal layout container views. +1 for adding this feature
Any news on insertViewsAt(index, views) in order to add a bulk views in one operation ? Thanks Nuno
I know, not a cool solution. But if you just have to, then go for it. Maybe this could be made as an module. I just needed a addViewToStart (beginning) - so I manipulated the SDK (bad solution). But this could probably be used to be manipulated to make a function like insertViewAt()
@Tobias Høegh, Thanks, Im testing!
@Tobias Høegh, can you please tell me what was your use case for? And how you implemented in js side? Was inside a loop like we with "addView " for infiniteve scroll if I scroll to a point that I want insert views (pages ) at the top (index 0) I just call like this: (like infinitive scroll both directions) getPages(prev);
Now, if I scroll to the END of my list usually insert views normally addView() method, in this case , I just call like this: (like infinitive scroll both directions)
This make any sense to you? PS. sorry for the format, not sure why so many spaces and P tags!
Adding this gist for reference [https://gist.github.com/dawsontoth/810171] Also, the setViews() method should not make the scrollableView flicker as it does at the moment.
@Nuno, nope, I don't see that issue at all. I am building an infinite scrollable view, with no "insertAt" method, I'm using setViews as in Dawson Toth's gist. The setViews() call results in a noticeable flicker on update.
@Tobias Høegh, that seams not doing what I want :( "insertAt " aka "preApend" items. "addView" aka "append item" does now!
@nunocostapt I add 3 views on startup setting the currentPage to 1 (0,1,2) - is the user scrolling increasing, then I use addView when we get currentPage 2 or higher. On the opposite side, I call addViewToStart if the currentPage is 0. Check out my app and the due date picker or stats on top of profiles: https://itunes.apple.com/app/moogli/id1068103957 - or check out the tweet I made: http://bit.ly/1RbK6fZ By the way, this infinite scrollable view is really not smooth and has a strange effect on scrolling slowly http://bit.ly/1QNrkJ5
That is the setViews call firing I think. @Tobias have you looked at Android at all?
@Tobias Høegh do you mind to share some piece of the code that please?
Just wanted to chime in here and say that this is something I wanted to file a long time ago, so +1 to this issue being fixed! an insertAt() or prepend() would be such a tremendous help. :)
+1!
PR: https://github.com/appcelerator/titanium_mobile/pull/7764
+1 This is also something I've always wanted
Thanks for the PR folks. We will look into this as soon as we can, because meanwhile, we are trying to make sure this UI component is working well on main thread and with auto layout. After this is stable (which is soon!), we will visit this PR.
@kiat, any updates/progress on this one?
As discussed with [~bduyng@gmail.com], I did some minor refactoring on the initial PR to make it more generic. Updated PR: https://github.com/appcelerator/titanium_mobile/pull/7966 Demo:
Verified the implementation. Works as expected. Closing. Environment: Appc Studio : 4.7.0.201606220541 Ti SDK : 5.4.0.v20160705213725 Ti CLI : 5.0.9 Alloy : 1.9.1 MAC El Capitan : 10.11.5 Appc NPM : 4.2.8-1 Appc CLI : 5.4.0-28 Node: 4.4.4 Nexus 6 - Android 6.0.1
I just tried this, and there doesn't seem to be a way to get away from flickering when adding views to position 0. :( Whenever a view is added to a position before your current page you get thrown around, and when you try to get back with setCurrentPage() it will flicker anyways.
Caio Iglesias yeah, Im in the same situation, I added an array of 22 views to a position 0 to be at the very top, and when I try to get back with setCurrentPage() it will flicker anyways.
Caio Iglesias and all, just and Update on this subject and related to y above comment: I added the prop. directly to .tss
the same number (22) of the views that I have and will load in next round and the flicker just gonne. :) Im still testing with sdk 5.5.1
So if I understand this correctly, the cache size is what holds the views in place so that they don't move when new views are inserted?