EndouMari / TabPageViewController

Paging view controller and scroll tab view
MIT License
1.39k stars 221 forks source link

Fixed weird animation in moveCurrentBarView when isInfinity is true #80

Open masatootake opened 7 years ago

masatootake commented 7 years ago

I guess it's just a mistake. The following code is using index, but it should be currentIndex. https://github.com/EndouMari/TabPageViewController/blob/master/Sources/TabView.swift#L224

The below is the exact part.

    /**
     Make the tapped cell the current if isInfinity is true

     - parameter index: Next IndexPath√
     */
    fileprivate func updateCurrentIndexForTap(_ index: Int) {
        deselectVisibleCells()

        if isInfinity && (index < pageTabItemsCount) || (index >= pageTabItemsCount * 2) {
            currentIndex = (index < pageTabItemsCount) ? index + pageTabItemsCount : index - pageTabItemsCount
            shouldScrollToItem = true
        } else {
            currentIndex = index
        }
        let indexPath = IndexPath(item: index, section: 0) // FIX: index -> currentIndex
        moveCurrentBarView(indexPath, animated: true, shouldScroll: true)
    }

As a result of this mistake, when isInfinity is true, it causes a weird animation when moving tab from the range of pageTabItemsCount <= currentIndex < pageTabItemsCount * 2 to the range of currentIndex < pageTabItemsCount && pageTabItemsCount * 2 <= currentIndex.