From 63b0191174651f4f677f92bab53c376e07f27ee6 Mon Sep 17 00:00:00 2001 From: sz ashik Date: Mon, 23 May 2022 17:36:48 +0600 Subject: [PATCH 1/2] continuous crash fixed --- Sources/ButtonBarPagerTabStripViewController.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sources/ButtonBarPagerTabStripViewController.swift b/Sources/ButtonBarPagerTabStripViewController.swift index 36e008d6..00bc282a 100644 --- a/Sources/ButtonBarPagerTabStripViewController.swift +++ b/Sources/ButtonBarPagerTabStripViewController.swift @@ -65,6 +65,8 @@ public struct ButtonBarPagerTabStripSettings { } open class ButtonBarPagerTabStripViewController: PagerTabStripViewController, PagerTabStripDataSource, PagerTabStripIsProgressiveDelegate, UICollectionViewDelegate, UICollectionViewDataSource { + + private var shouldUpdateContent = true public var settings = ButtonBarPagerTabStripSettings() @@ -192,12 +194,23 @@ open class ButtonBarPagerTabStripViewController: PagerTabStripViewController, Pa // MARK: - Public Methods open override func reloadPagerTabStripView() { + shouldUpdateContent = false super.reloadPagerTabStripView() + shouldUpdateContent = true + guard isViewLoaded else { return } buttonBarView.reloadData() cachedCellWidths = calculateWidths() + buttonBarView.layoutIfNeeded() + updateContent() buttonBarView.moveTo(index: currentIndex, animated: false, swipeDirection: .none, pagerScroll: .yes) } + + open override func updateContent() { + if shouldUpdateContent { + super.updateContent() + } + } open func calculateStretchedCellWidths(_ minimumCellWidths: [CGFloat], suggestedStretchedCellWidth: CGFloat, previousNumberOfLargeCells: Int) -> CGFloat { var numberOfLargeCells = 0 From 62796ce452884f7594ef17a00bc0a92802f17228 Mon Sep 17 00:00:00 2001 From: sz ashik Date: Tue, 24 May 2022 12:23:15 +0600 Subject: [PATCH 2/2] fix 575 --- Sources/ButtonBarView.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/ButtonBarView.swift b/Sources/ButtonBarView.swift index a204971e..9b039d26 100644 --- a/Sources/ButtonBarView.swift +++ b/Sources/ButtonBarView.swift @@ -78,7 +78,10 @@ open class ButtonBarView: UICollectionView { open func move(fromIndex: Int, toIndex: Int, progressPercentage: CGFloat, pagerScroll: PagerScroll) { selectedIndex = progressPercentage > 0.5 ? toIndex : fromIndex - let fromFrame = layoutAttributesForItem(at: IndexPath(item: fromIndex, section: 0))!.frame + var fromFrame = CGRect.zero + if let layout = layoutAttributesForItem(at: IndexPath(item: fromIndex, section: 0)) { + fromFrame = layout.frame + } let numberOfItems = dataSource!.collectionView(self, numberOfItemsInSection: 0) var toFrame: CGRect