-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix FXIOS-8657 Add operation queue to perform batch updates (#19670)
* Remove collectionView updates in newState of TabDisplayView * Make performChainedOperations var private and add template of methods to TabDisplayView * Add updateWith for moving the tab * Add updateWith * WIP * didAddTab called in TabDisplayView * Clean up operation queue * Remove commented code * Fix crash when there's no sections --------- Co-authored-by: Sophie Amin <samin@KPQ47DG99L.lan> (cherry picked from commit 86bd353)
- Loading branch information
1 parent
e97d494
commit fb3bbd7
Showing
5 changed files
with
106 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
firefox-ios/Client/Frontend/Browser/Tabs/TabTrayAnimationQueue.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
|
||
import UIKit | ||
|
||
protocol TabTrayAnimationQueue { | ||
func addAnimation(for collectionView: UICollectionView, | ||
animation: @escaping (() -> Void)) | ||
} | ||
|
||
class TabTrayAnimationQueueImplementation: TabTrayAnimationQueue { | ||
private var animations = [() -> Void]() | ||
private var performingChainedOperations = false | ||
|
||
func addAnimation(for collectionView: UICollectionView, | ||
animation: @escaping (() -> Void)) { | ||
animations.append(animation) | ||
performChainedOperations(for: collectionView) | ||
} | ||
|
||
private func performChainedOperations(for collectionView: UICollectionView) { | ||
guard !performingChainedOperations, | ||
let animation = animations.first | ||
else { return } | ||
|
||
performingChainedOperations = true | ||
animations.removeFirst() | ||
/// Fix crash related to bug from `collectionView.performBatchUpdates` when the | ||
/// collectionView is not visible the dataSource section/items differs from the actions to be perform | ||
/// which causes the crash | ||
if collectionView.numberOfSections != 0 { | ||
collectionView.numberOfItems(inSection: 0) | ||
} | ||
collectionView.performBatchUpdates({ | ||
animation() | ||
}, completion: { [weak self] (done) in | ||
collectionView.reloadData() | ||
self?.performingChainedOperations = false | ||
self?.performChainedOperations(for: collectionView) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters