| | |
| | | ) { |
| | | let oldNames = self.items.map(\.name) |
| | | let newNames = items.map(\.name) |
| | | let needsRebuild = Set(oldNames) != Set(newNames) || self.orientation != orientation |
| | | let needsRebuild = oldNames.count != newNames.count || Set(oldNames) != Set(newNames) || self.orientation != orientation |
| | | self.items = items |
| | | self.orientation = orientation |
| | | self.contentInsets = contentInsets |
| | |
| | | } |
| | | |
| | | private func reuseButtonsInCurrentOrder() { |
| | | let existing = Dictionary(uniqueKeysWithValues: buttons.map { ($0.itemName, $0) }) |
| | | var existing: [String: [TagNavigationButton]] = [:] |
| | | for button in buttons { |
| | | existing[button.itemName, default: []].append(button) |
| | | } |
| | | buttons = items.compactMap { item in |
| | | guard let button = existing[item.name] else { return nil } |
| | | guard var candidates = existing[item.name], !candidates.isEmpty else { return nil } |
| | | let button = candidates.removeFirst() |
| | | existing[item.name] = candidates |
| | | button.configure(item: item, orientation: orientation) |
| | | button.refreshAppDropRegistration() |
| | | return button |