Skip to content

Commit c5de31a

Browse files
dfeinzimerCalebRas
andcommitted
Add and use EquatableObject
Co-Authored-By: Caleb Rasmussen <crasmussen@esri.com>
1 parent 40f5099 commit c5de31a

File tree

6 files changed

+36
-31
lines changed

6 files changed

+36
-31
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2025 Esri
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/// An equatable wrapper for an object.
16+
///
17+
/// Equality is determined by object identity.
18+
struct EquatableObject<Object: AnyObject & Sendable>: Equatable {
19+
let object: Object
20+
21+
static func == (lhs: Self, rhs: Self) -> Bool {
22+
lhs.object === rhs.object
23+
}
24+
}

Sources/ArcGISToolkit/Components/FeatureFormView/EmbeddedFeatureFormView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct EmbeddedFeatureFormView: View {
8282
.padding([.horizontal])
8383
.preference(
8484
key: PresentedFeatureFormPreferenceKey.self,
85-
value: .init(featureForm: embeddedFeatureFormViewModel.featureForm)
85+
value: .init(object: embeddedFeatureFormViewModel.featureForm)
8686
)
8787
.task {
8888
await embeddedFeatureFormViewModel.initialEvaluation()

Sources/ArcGISToolkit/Components/FeatureFormView/FeatureFormView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public struct FeatureFormView: View {
145145
.navigationTitle(result.filter.title, subtitle: embeddedFeatureFormViewModel.title)
146146
.preference(
147147
key: PresentedFeatureFormPreferenceKey.self,
148-
value: .init(featureForm: embeddedFeatureFormViewModel.featureForm)
148+
value: .init(object: embeddedFeatureFormViewModel.featureForm)
149149
)
150150
case let .utilityAssociationGroupResultView(result, embeddedFeatureFormViewModel):
151151
UtilityAssociationGroupResultView(
@@ -269,7 +269,7 @@ public struct FeatureFormView: View {
269269
.environment(\.validationErrorVisibilityInternal, $validationErrorVisibilityInternal)
270270
.onPreferenceChange(PresentedFeatureFormPreferenceKey.self) { wrappedFeatureForm in
271271
guard let wrappedFeatureForm else { return }
272-
formChangedAction(wrappedFeatureForm.featureForm)
272+
formChangedAction(wrappedFeatureForm.object)
273273
}
274274
}
275275
}

Sources/ArcGISToolkit/Components/FeatureFormView/PresentedFeatureFormPreferenceKey.swift

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,12 @@ import SwiftUI
1717

1818
/// A preference key that specifies the feature form currently presented in the `FeatureFormView` navigation stack.
1919
struct PresentedFeatureFormPreferenceKey: PreferenceKey {
20-
/// A wrapper for making a feature form equatable.
21-
struct EquatableFeatureForm: Equatable {
22-
let featureForm: FeatureForm
23-
24-
static func == (lhs: Self, rhs: Self) -> Bool {
25-
lhs.featureForm === rhs.featureForm
26-
}
27-
}
28-
29-
// MARK: PreferenceKey Conformance
30-
31-
static let defaultValue: EquatableFeatureForm? = nil
20+
static let defaultValue: EquatableObject<FeatureForm>? = nil
3221

33-
static func reduce(value: inout EquatableFeatureForm?, nextValue: () -> EquatableFeatureForm?) {
22+
static func reduce(
23+
value: inout EquatableObject<FeatureForm>?,
24+
nextValue: () -> EquatableObject<FeatureForm>?
25+
) {
3426
guard let nextValue = nextValue() else { return }
3527
value = nextValue
3628
}

Sources/ArcGISToolkit/Components/Popups/EmbeddedPopupView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct EmbeddedPopupView: View {
6060
.frame(maxWidth: .infinity, maxHeight: .infinity)
6161
.background(Color(.systemBackground))
6262
#endif
63-
.preference(key: PresentedPopupPreferenceKey.self, value: .init(popup: popup))
63+
.preference(key: PresentedPopupPreferenceKey.self, value: .init(object: popup))
6464
.popupViewHeader(title: popup.title)
6565
.task(id: ObjectIdentifier(popup)) {
6666
// Initial evaluation for a newly assigned popup.

Sources/ArcGISToolkit/Components/Popups/PopupView.swift

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public struct PopupView: View {
9191
.environment(\.deprecatedProperties, deprecatedProperties)
9292
.onPreferenceChange(PresentedPopupPreferenceKey.self) { wrappedPopup in
9393
guard let wrappedPopup else { return }
94-
onPopupChanged?(wrappedPopup.popup)
94+
onPopupChanged?(wrappedPopup.object)
9595
}
9696
}
9797
}
@@ -111,20 +111,9 @@ public extension PopupView {
111111

112112
/// A preference key that specifies the popup currently presented in the `PopupView` navigation stack.
113113
struct PresentedPopupPreferenceKey: PreferenceKey {
114-
/// A wrapper for making a popup equatable.
115-
struct EquatablePopup: Equatable {
116-
let popup: Popup
117-
118-
static func == (lhs: Self, rhs: Self) -> Bool {
119-
lhs.popup === rhs.popup
120-
}
121-
}
122-
123-
// MARK: PreferenceKey Conformance
124-
125-
static let defaultValue: EquatablePopup? = nil
114+
static let defaultValue: EquatableObject<Popup>? = nil
126115

127-
static func reduce(value: inout EquatablePopup?, nextValue: () -> EquatablePopup?) {
116+
static func reduce(value: inout EquatableObject<Popup>?, nextValue: () -> EquatableObject<Popup>?) {
128117
guard let nextValue = nextValue() else { return }
129118
value = nextValue
130119
}

0 commit comments

Comments
 (0)