Skip to content

Commit

Permalink
fixed logic when scrolling to last page
Browse files Browse the repository at this point in the history
  • Loading branch information
ThasianX committed Jul 15, 2020
1 parent 2702cc4 commit a7a5d37
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ struct ElegantListController: UIViewControllerRepresentable, ElegantListManagerD
self.setActiveIndex(1, animated: false, complete: true) // resets to center
}
case let .scroll(animated):
let pageToTurnTo = currentPage.index > controller.previousPage ? maxPageIndex : 0
let isFirstPage = currentPage.index == 0
let isLastPage = currentPage.index == pageCount-1

if currentPage.index == 0 || currentPage.index == pageCount-1 {
if isFirstPage || isLastPage {
let pageToTurnTo = isFirstPage ? 0 : maxPageIndex
setActiveIndex(pageToTurnTo, animated: animated, complete: true)
controller.reset(manager: manager)
} else {
let pageToTurnTo = currentPage.index > controller.previousPage ? maxPageIndex : 0
// This first call to `setActiveIndex` is responsible for animating the page
// turn to whatever page we want to scroll to
setActiveIndex(pageToTurnTo, animated: animated, complete: false)
Expand Down

0 comments on commit a7a5d37

Please sign in to comment.