Skip to content

Commit

Permalink
Update on demand example
Browse files Browse the repository at this point in the history
  • Loading branch information
fermoya committed Mar 13, 2021
1 parent 6130ecc commit 51e8555
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
28 changes: 14 additions & 14 deletions Documentation/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,25 +282,25 @@ At the same time, items can be added at the start. Notice you'll need to update

```swift

@State var count: Int = -1
@StateObject var page: Page = .first()
// @ObservedObject var page: Page = .first()
@State var data = Array(0..<5)

Pager(page: self.page,
data: self.data,
id: \.self) {
self.pageView($0)
}
.onPageChanged({ pageIndex in
guard pageIndex == 1 else { return }
let newData = (1...5).map { $0 * self.count }
withAnimation {
self.data.insert(contentsOf: newData, at: 0)
self.page.index += 5
self.count -= 1
var body: some View {
Pager(page: self.page,
data: self.data,
id: \.self) {
self.pageView($0)
}
})
.onPageChanged({ pageIndex in
guard pageIndex == 1 else { return }
let newData = (1...5).map { data1.first! - $0 }.reversed()
withAnimation {
page.index += newData.count
data.insert(contentsOf: newData, at: 0)
}
})
}
```

## Content Loading Policy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ struct InfiniteExampleView: View {

@StateObject var page1 = Page.withIndex(2)
@StateObject var page2 = Page.first()
@State var count: Int = 1
@State var data1 = Array(0..<7)
@State var isPresented: Bool = false
var data2 = Array(0..<20)
Expand All @@ -36,11 +35,10 @@ struct InfiniteExampleView: View {
.onPageChanged({ page in
print("Page changed to: \(page)")
if page == 1 {
let newData = (1...5).map { data1.first! - $0 * count }.reversed()
let newData = (1...5).map { data1.first! - $0 }.reversed()
withAnimation {
page1.index += newData.count
data1.insert(contentsOf: newData, at: 0)
count += 1
isPresented.toggle()
}
} else if page == self.data1.count - 2 {
Expand Down

0 comments on commit 51e8555

Please sign in to comment.