Skip to content

Commit 2eeef55

Browse files
authored
Bugfix FXIOS-10584 - [Toolbar Redesign] 20+ new homepage tabs are opened when I try to open just one new tab (#23253)
Make self weak in the button action handler and remove code that checks for existing buttons
1 parent 5c66702 commit 2eeef55

2 files changed

Lines changed: 3 additions & 30 deletions

File tree

BrowserKit/Sources/ToolbarKit/AddressToolbar/BrowserAddressToolbar.swift

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,9 @@ public class BrowserAddressToolbar: UIView,
257257
}
258258

259259
private func updateActionStack(stackView: UIStackView, toolbarElements: [ToolbarElement]) {
260-
let existingButtons = stackView.arrangedSubviews.compactMap { $0 as? ToolbarButton }
261260
stackView.removeAllArrangedViews()
262-
263261
toolbarElements.forEach { toolbarElement in
264-
// find existing button or create new one
265-
// we do this to avoid having a new button every time we re-configure the address toolbar
266-
// as this can result in button taps not resulting in correct action because the action
267-
// as the reference to an old and not displayed button (e.g. the menu that is displayed from the menu button)
268-
let button = newOrExistingToolbarButton(for: toolbarElement, existingButtons: existingButtons)
262+
let button = toolbarElement.numberOfTabs != nil ? TabNumberButton() : ToolbarButton()
269263
button.configure(element: toolbarElement)
270264
stackView.addArrangedSubview(button)
271265

@@ -285,17 +279,6 @@ public class BrowserAddressToolbar: UIView,
285279
}
286280
}
287281

288-
private func newOrExistingToolbarButton(for element: ToolbarElement,
289-
existingButtons: [ToolbarButton]) -> ToolbarButton {
290-
let existingButton = existingButtons.first { $0.isButtonFor(toolbarElement: element) }
291-
292-
guard let existingButton else {
293-
return element.numberOfTabs != nil ? TabNumberButton() : ToolbarButton()
294-
}
295-
296-
return existingButton
297-
}
298-
299282
private func updateActionSpacing() {
300283
// Browser action spacing
301284
let hasBrowserActions = !browserActionStack.arrangedSubviews.isEmpty

BrowserKit/Sources/ToolbarKit/ToolbarButton.swift

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class ToolbarButton: UIButton, ThemeApplicable {
4747
let image = imageConfiguredForRTL(for: element)
4848
let action = UIAction(title: element.a11yLabel,
4949
image: image,
50-
handler: { _ in
50+
handler: { [weak self] _ in
51+
guard let self else { return }
5152
element.onSelected?(self)
5253
UIAccessibility.post(notification: .announcement, argument: element.a11yLabel)
5354
})
@@ -102,17 +103,6 @@ class ToolbarButton: UIButton, ThemeApplicable {
102103
configuration = updatedConfiguration
103104
}
104105

105-
public func isButtonFor(toolbarElement: ToolbarElement) -> Bool {
106-
guard let config = configuration else { return false }
107-
108-
return isSelected == toolbarElement.isSelected &&
109-
config.image == imageConfiguredForRTL(for: toolbarElement) &&
110-
isEnabled == toolbarElement.isEnabled &&
111-
accessibilityIdentifier == toolbarElement.a11yId &&
112-
accessibilityLabel == toolbarElement.a11yLabel &&
113-
accessibilityHint == toolbarElement.a11yHint
114-
}
115-
116106
private func addBadgeIcon(imageName: String) {
117107
badgeImageView = UIImageView(image: UIImage(named: imageName))
118108
guard let badgeImageView, configuration?.image != nil else { return }

0 commit comments

Comments
 (0)