-
-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] Support RandomAccessCollection in the initializers rather than fixed Array #135
Comments
@TheNoim I'm a bit confused by "A way to use this without passing an array". How is All in all, the way you describe Just for further clarification: @State var page: Int = 0
var items = Array(0..<10)
var body: some View {
Pager(page: $page,
data: items,
id: \.identifier,
content: { index in
//
// This isn't just an index. It's an item from data. In this example is an integer
//
Text("Page: \(index)")
})
} What you would need to do is something like this: // 9 as we're in October
@State var page: Int = CalendaryMonth.current.monthIndex
@State var oldPage: Int = CalendaryMonth.current.monthIndex
@State var year = 2020
let months = [CalendarMonth(.january), ..., CalendarMonth(.october), CalendarMonth(.november), CalendarMonth(.december)]
var body: some View {
Pager(page: $page,
data: months,
id: \.monthIndex,
content: { month in
// Render month accordingly depending on the year
CalendarViewMonth(month: month, year: year)
})
.loopPages()
.onPageChanged { newPage in
if newPage == 0 && page == 11 { year += 1 }
if newPage == 11 && oldPage == 0 { year -= 1 }
oldPage = newPage
}
} |
This is not really against my post. My suggestion was more like this: |
I'm not following, could you please show me an example? Even just pseudo-code. I wanna see how you dynamically add data and change the index. As far as I know, I think you could have a |
I'm gonna start supporting As far as I can see in your gist, this would be enough for you. Then, if you implement
|
Is your feature request related to a problem? Please describe.
There is currently no good way library out that supports infinitive page swiping with an unknown size. This could be very useful. Example use case: Infinitiv calendar swipe view. The issue is, a calendar does not have a clear end in both directions. First, when I found this library I thought I finally have a good way to implement a week calendar view. However, then I found out that I still need to pass an array with a known size and a positive index.
Describe the solution you'd like
A way to use this without passing an array. Instead of:
this
Describe alternatives you've considered
The alternative would be to allow to pass custom array implementations. For example: Some struct which implements the RandomAccessCollection. Then you could implement your own "array" which auto extends itself in both directions. Negative and positive. RandomAccessCollection supports this:
You can update and define your own end and start.
I tried to implement something similar once by myself. But this is a bit buggy and not really nice:
https://gist.github.com/TheNoim/6ca6f35eb830a2d53d6adf04d68e05ba
The text was updated successfully, but these errors were encountered: