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

Fix crash when quickly adding/removing tabs in switcher #2760

Merged
merged 2 commits into from
Apr 17, 2024
Merged
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
2 changes: 1 addition & 1 deletion DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2245,7 +2245,7 @@ extension MainViewController: TabSwitcherButtonDelegate {
}

func showTabSwitcher() {
guard let currentTab = currentTab ?? tabManager.current(createIfNeeded: true) else {
guard currentTab ?? tabManager.current(createIfNeeded: true) != nil else {
fatalError("Unable to get current tab")
}

Expand Down
1 change: 1 addition & 0 deletions DuckDuckGo/TabSwitcherViewController+KeyCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ extension TabSwitcherViewController {
}

@objc func keyboardNewTab() {
guard !isProcessingUpdates else { return }
delegate?.tabSwitcherDidRequestNewTab(tabSwitcher: self)
dismiss()
}
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/TabSwitcherViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class TabSwitcherViewController: UIViewController {
var currentSelection: Int?

private var tabSwitcherSettings: TabSwitcherSettings = DefaultTabSwitcherSettings()
private var isProcessingUpdates = false
private(set) var isProcessingUpdates = false
private var canUpdateCollection = true

let favicons = Favicons.shared
Expand Down Expand Up @@ -278,6 +278,7 @@ class TabSwitcherViewController: UIViewController {
}

@IBAction func onAddPressed(_ sender: UIBarButtonItem) {
guard !isProcessingUpdates else { return }
delegate.tabSwitcherDidRequestNewTab(tabSwitcher: self)
dismiss()
}
Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/TabViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ class TabViewCell: UICollectionViewCell {
}

private func startRemoveAnimation() {
self.isDeleting = true
self.deleteTab()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows for shorter delay before adding a tab is again possible. Based on my checks it does not interfere with animations. Once this function is called, the gesture is committed anyway.

UIView.animate(withDuration: 0.2, animations: {
self.transform = CGAffineTransform.identity.translatedBy(x: -self.frame.width, y: 0)
}, completion: { _ in
self.isHidden = true
self.isDeleting = true
self.deleteTab()
})
}

Expand Down
Loading