Skip to content

Commit bd326d3

Browse files
authored
Add FXIOS-14379 [Performance] Add back equatable for BVC state (#31217)
* Add back equatable for BVC state * add ticket number * fix tests
1 parent 72fe740 commit bd326d3

File tree

7 files changed

+28
-7
lines changed

7 files changed

+28
-7
lines changed

firefox-ios/Client/Frontend/Browser/BrowserViewController/State/BrowserNavigationType.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import enum MozillaAppServices.VisitType
77
import SummarizeKit
88

99
/// View types that the browser coordinator can navigate to
10-
enum BrowserNavigationDestination {
10+
enum BrowserNavigationDestination: Equatable {
1111
// Native views
1212
case contextMenu
1313
case settings(Route.SettingsSection)
@@ -29,7 +29,7 @@ enum BrowserNavigationDestination {
2929
case shareSheet(ShareSheetConfiguration)
3030
}
3131

32-
struct ShareSheetConfiguration {
32+
struct ShareSheetConfiguration: Equatable {
3333
let shareType: ShareType
3434
let shareMessage: ShareMessage?
3535
let sourceView: UIView
@@ -39,7 +39,7 @@ struct ShareSheetConfiguration {
3939
}
4040

4141
/// This type exists as a field on the BrowserViewControllerState
42-
struct NavigationDestination {
42+
struct NavigationDestination: Equatable {
4343
let destination: BrowserNavigationDestination
4444
let url: URL?
4545
let isPrivate: Bool?

firefox-ios/Client/Frontend/Browser/BrowserViewController/State/BrowserViewControllerState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import WebKit
1010
import SummarizeKit
1111

1212
struct BrowserViewControllerState: ScreenState {
13-
enum NavigationType {
13+
enum NavigationType: Equatable {
1414
case home
1515
case back
1616
case forward

firefox-ios/Client/Frontend/Browser/BrowserViewController/State/BrowserViewType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import Foundation
66

7-
enum BrowserViewType {
7+
enum BrowserViewType: Equatable {
88
case normalHomepage
99
case privateHomepage
1010
case webview

firefox-ios/Client/Frontend/Share/ShareTab.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import Foundation
66

77
protocol ShareTab: Sendable {
8+
nonisolated var tabUUID: TabUUID { get }
9+
810
@MainActor
911
var displayTitle: String { get }
1012
@MainActor

firefox-ios/Client/Frontend/Share/ShareType.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,24 @@ import Foundation
1616
/// __SPECIAL NOTE__: If you download a PDF, you can view that in a tab. In that case, the URL may have a `file://`
1717
/// scheme instead of `http(s)://`, so certain options, like Send to Device / Add to Home Screen, may not be
1818
/// available.
19-
enum ShareType {
19+
enum ShareType: Equatable, Sendable {
2020
case file(url: URL, remoteURL: URL?)
2121
case site(url: URL)
2222
case tab(url: URL, tab: any ShareTab)
2323

24+
static func == (lhs: Self, rhs: Self) -> Bool {
25+
switch (lhs, rhs) {
26+
case let (.file(lhsURL, rhsRemoteURL), .file(rhsURL, lhsRemoteURL)):
27+
return lhsURL == rhsURL && rhsRemoteURL == lhsRemoteURL
28+
case let (.site(lhsURL), .site(rhsURL)):
29+
return lhsURL == rhsURL
30+
case let (.tab(lhsURL, lhsTab), .tab(rhsURL, rhsTab)):
31+
return lhsURL == rhsURL && lhsTab.tabUUID == rhsTab.tabUUID
32+
default:
33+
return false
34+
}
35+
}
36+
2437
/// The share URL wrapped by the given type.
2538
var wrappedURL: URL {
2639
switch self {

firefox-ios/Client/TabManagement/Tab.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ class Tab: NSObject, ThemeApplicable, FeatureFlaggable, ShareTab {
127127

128128
// Setting default page as topsites
129129
var newTabPageType: NewTabPage = .topSites
130-
var tabUUID: TabUUID = UUID().uuidString
130+
// TODO: FXIOS-14381 This can't be nonisolated because it is a var but it is only set once.
131+
// We should probably just do this as part of a Tab init from TabData but it will
132+
// be a bigger refactor.
133+
nonisolated(unsafe) var tabUUID: TabUUID = UUID().uuidString
131134
private var screenshotUUIDString: String?
132135

133136
var screenshotUUID: UUID? {

firefox-ios/firefox-ios-tests/Tests/ClientTests/Mocks/MockShareTab.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Foundation
88

99
@MainActor
1010
class MockShareTab: ShareTab {
11+
nonisolated let tabUUID: Client.TabUUID
1112
var canonicalURL: URL?
1213
var displayTitle: String
1314
var url: URL?
@@ -18,12 +19,14 @@ class MockShareTab: ShareTab {
1819
title: String,
1920
url: URL?,
2021
canonicalURL: URL?,
22+
tabUUID: TabUUID = UUID().uuidString,
2123
withActiveWebView: Bool = true,
2224
withTemporaryDocument: TemporaryDocument? = nil
2325
) {
2426
self.displayTitle = title
2527
self.url = url
2628
self.canonicalURL = canonicalURL
29+
self.tabUUID = tabUUID
2730
self.webView = TabWebView(frame: CGRect.zero, configuration: .init(), windowUUID: .XCTestDefaultUUID)
2831
self.temporaryDocument = withTemporaryDocument
2932
}

0 commit comments

Comments
 (0)