Skip to content
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

try to fix issue#741 #753

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Sources/BaseButtonBarPagerTabStripViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ open class BaseButtonBarPagerTabStripViewController<ButtonBarCellType: UICollect
public var buttonBarItemSpec: ButtonBarItemSpec<ButtonBarCellType>!
public var changeCurrentIndex: ((_ oldCell: ButtonBarCellType?, _ newCell: ButtonBarCellType?, _ animated: Bool) -> Void)?
public var changeCurrentIndexProgressive: ((_ oldCell: ButtonBarCellType?, _ newCell: ButtonBarCellType?, _ progressPercentage: CGFloat, _ changeCurrentIndex: Bool, _ animated: Bool) -> Void)?
private var oldCurrentIndex: Int = -1

@IBOutlet public weak var buttonBarView: ButtonBarView!

Expand Down Expand Up @@ -150,6 +151,11 @@ open class BaseButtonBarPagerTabStripViewController<ButtonBarCellType: UICollect
buttonBarView.moveTo(index: currentIndex, animated: false, swipeDirection: .none, pagerScroll: .yes)
}

open override func updateContent() {
oldCurrentIndex = currentIndex
super.updateContent()
}

open func calculateStretchedCellWidths(_ minimumCellWidths: [CGFloat], suggestedStretchedCellWidth: CGFloat, previousNumberOfLargeCells: Int) -> CGFloat {
var numberOfLargeCells = 0
var totalWidthOfLargeCells: CGFloat = 0
Expand Down Expand Up @@ -205,6 +211,8 @@ open class BaseButtonBarPagerTabStripViewController<ButtonBarCellType: UICollect
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard indexPath.item != currentIndex else { return }

oldCurrentIndex = currentIndex

buttonBarView.moveTo(index: indexPath.item, animated: true, swipeDirection: .none, pagerScroll: .yes)
shouldUpdateButtonBarView = false

Expand Down Expand Up @@ -237,13 +245,14 @@ open class BaseButtonBarPagerTabStripViewController<ButtonBarCellType: UICollect

configure(cell: cell, for: indicatorInfo)

let isCurrentIndex = currentIndex == indexPath.item && oldCurrentIndex != indexPath.item
if pagerBehaviour.isProgressiveIndicator {
if let changeCurrentIndexProgressive = changeCurrentIndexProgressive {
changeCurrentIndexProgressive(currentIndex == indexPath.item ? nil : cell, currentIndex == indexPath.item ? cell : nil, 1, true, false)
changeCurrentIndexProgressive(isCurrentIndex ? nil : cell, isCurrentIndex ? cell : nil, 1, true, false)
}
} else {
if let changeCurrentIndex = changeCurrentIndex {
changeCurrentIndex(currentIndex == indexPath.item ? nil : cell, currentIndex == indexPath.item ? cell : nil, false)
changeCurrentIndex(isCurrentIndex ? nil : cell, isCurrentIndex ? cell : nil, false)
}
}

Expand Down
14 changes: 12 additions & 2 deletions Sources/ButtonBarPagerTabStripViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ open class ButtonBarPagerTabStripViewController: PagerTabStripViewController, Pa

public var changeCurrentIndex: ((_ oldCell: ButtonBarViewCell?, _ newCell: ButtonBarViewCell?, _ animated: Bool) -> Void)?
public var changeCurrentIndexProgressive: ((_ oldCell: ButtonBarViewCell?, _ newCell: ButtonBarViewCell?, _ progressPercentage: CGFloat, _ changeCurrentIndex: Bool, _ animated: Bool) -> Void)?

private var oldCurrentIndex: Int = -1

@IBOutlet public weak var buttonBarView: ButtonBarView!

Expand Down Expand Up @@ -198,6 +200,11 @@ open class ButtonBarPagerTabStripViewController: PagerTabStripViewController, Pa
cachedCellWidths = calculateWidths()
buttonBarView.moveTo(index: currentIndex, animated: false, swipeDirection: .none, pagerScroll: .yes)
}

open override func updateContent() {
oldCurrentIndex = currentIndex
super.updateContent()
}

open func calculateStretchedCellWidths(_ minimumCellWidths: [CGFloat], suggestedStretchedCellWidth: CGFloat, previousNumberOfLargeCells: Int) -> CGFloat {
var numberOfLargeCells = 0
Expand Down Expand Up @@ -279,6 +286,8 @@ open class ButtonBarPagerTabStripViewController: PagerTabStripViewController, Pa
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard indexPath.item != currentIndex else { return }

oldCurrentIndex = currentIndex

buttonBarView.moveTo(index: indexPath.item, animated: true, swipeDirection: .none, pagerScroll: .yes)
shouldUpdateButtonBarView = false

Expand Down Expand Up @@ -329,13 +338,14 @@ open class ButtonBarPagerTabStripViewController: PagerTabStripViewController, Pa

configureCell(cell, indicatorInfo: indicatorInfo)

let isCurrentIndex = currentIndex == indexPath.item && oldCurrentIndex != indexPath.item
if pagerBehaviour.isProgressiveIndicator {
if let changeCurrentIndexProgressive = changeCurrentIndexProgressive {
changeCurrentIndexProgressive(currentIndex == indexPath.item ? nil : cell, currentIndex == indexPath.item ? cell : nil, 1, true, false)
changeCurrentIndexProgressive(isCurrentIndex ? nil : cell, isCurrentIndex ? cell : nil, 1, true, false)
}
} else {
if let changeCurrentIndex = changeCurrentIndex {
changeCurrentIndex(currentIndex == indexPath.item ? nil : cell, currentIndex == indexPath.item ? cell : nil, false)
changeCurrentIndex(isCurrentIndex ? nil : cell, isCurrentIndex ? cell : nil, false)
}
}
cell.isAccessibilityElement = true
Expand Down