Comments (6)
Hey @CJxD, this is a great question and one I have thought about quite a lot.
TL;DR - Not yet
The SwipeCardStack
class is modeled after UITableView
which only displays a finite amount of cells at a time. If you consider the cards as cells, this question can be rephrased as
Can you have an infinitely scrolling UITableView?
The answer is, of course, yes, but how?
The solution is Pagination. One way to paginate is to fetch your next cell's data model on a background thread whenever you run out of cells while scrolling. To update your tableview, you append the fetched data to your data model list and call reloadData
on the main thread.
Note: this is not the best solution. Ideally you would pre-fetch your data (check out
UITableViewDataSourcePrefetching
!), but let's run with this for now.
So you might have something like this:
func cellForRow(at indexPath: IndexPath) -> UITableViewCell?
if indexPath.row >= models.currentCount - 1 { // asking for the last cell, so we need more data soon!
fetchMoreModels()
}
return YourCell(data: models[indexPath.row])
}
Unfortunately, this approach doesn't work for SwipeCardStack
. Any call to reloadData
removes the swipe history, so calling reloadData
would just displays the card stack as before, just with the new cards queued up.
This is a very difficult problem and one I hope we can solve eventually! It's particularly difficult when you factor in the card stack shift
and undo
functions.
By the way, the reason it crashes is because the SwipeCardStack
tries to capture the state of your swipe history after every swipe (and upon first load). It tries to create an array of size Int.max
. The card stack is actually only loads those images which it is currently displaying.
Give it a try with 10,000 cards - it should be fine (although potentially slow).
from shuffle.
from shuffle.
Hey @CJxD and others. Happy to announce that infinite card stacks are now supported as of version 3.0.1. Take a look at the documentation on Adding News Cards
Cheers,
Mac
from shuffle.
How did you solve the undo function when you're at the first item of the new stack of data @CJxD ?
from shuffle.
Hi @dfmarulanda, sorry for the slow reply.
For me I haven't actually needed this ability (I use undo to return a card back to its original position after swiping up to share), however, I would recommend using a ring buffer that's larger than your stack size by the number of times you allow undos, and reload the data when undo is called.
The data source for the stack will be all cards in between the head and tail of the buffer.
If undo is asking for a card that is not in the current stack, then the head of the buffer is moved back one and the data is reloaded.
For example, if you allow 2 undos, and your stack is of size 5, then your ring buffer is size 7:
First load:
([1], [2], [3], [4], [5], [ ], [ ])
^head ^tail
Second load:
([8], [9], [10], [4], [5], [6], [7])
^tail ^head
Undo 1:
([8], [9], [10], [4], [5], [6], [7])
^tail ^head
Undo 2:
([8], [9], [10], [4], [5], [6], [7])
^tail ^head
Undo 3: not allowed, does nothing.
from shuffle.
Awesome!!
from shuffle.
Related Issues (20)
- Right Swiped Card Appear in view HOT 1
- Undoing the first Swipe in didSwipeCardAt fails HOT 1
- Only the ImageView for the last card in the array shows but all other info is displayed correctly HOT 23
- removed
- Showing square images in the card view HOT 1
- Not able to place a view over the card stack view
- Undo button doesn't display image HOT 2
- how can i use scrollview inside swipecard? HOT 4
- Modifying SwipeCard subview (hidden to not-hidden) from didSwipeCardAt not working
- Show next card under visible card
- Image doesn't display
- Is there any way to generate or create deck shadows?
- Is there any way to show background card little bit?
- The top card is stuck when swiping the card quickly HOT 1
- Getting this error "Dependency "Shuffle" has no shared framework schemes" while carthage update.
- Left swipe bring back previous card
- Property topCardIndex isn't updated immediately
- Swipe Card Temporarily Pauses
- Update Card Swipe Animation
- didSwipeCardAt not being called HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shuffle.