Skip to content

Commit 3a836d2

Browse files
authored
Merge pull request #301 from Esri/Caleb/Update-ErrorAlert
[Setup] Error alert refactor
2 parents 60d388e + cafa55c commit 3a836d2

File tree

48 files changed

+177
-371
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+177
-371
lines changed

Samples.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
0005580A2817C51E00224BC6 /* SampleDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 000558092817C51E00224BC6 /* SampleDetailView.swift */; };
11-
00181B462846AD7100654571 /* View+Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00181B452846AD7100654571 /* View+Alert.swift */; };
11+
00181B462846AD7100654571 /* View+ErrorAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00181B452846AD7100654571 /* View+ErrorAlert.swift */; };
1212
001C6DE127FE8A9400D472C2 /* AppSecrets.swift.masque in Sources */ = {isa = PBXBuildFile; fileRef = 001C6DD827FE585A00D472C2 /* AppSecrets.swift.masque */; };
1313
00273CF42A82AB5900A7A77D /* SamplesSearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00273CF32A82AB5900A7A77D /* SamplesSearchView.swift */; };
1414
00273CF62A82AB8700A7A77D /* SampleRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00273CF52A82AB8700A7A77D /* SampleRow.swift */; };
@@ -521,7 +521,7 @@
521521

522522
/* Begin PBXFileReference section */
523523
000558092817C51E00224BC6 /* SampleDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleDetailView.swift; sourceTree = "<group>"; };
524-
00181B452846AD7100654571 /* View+Alert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Alert.swift"; sourceTree = "<group>"; };
524+
00181B452846AD7100654571 /* View+ErrorAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+ErrorAlert.swift"; sourceTree = "<group>"; };
525525
001C6DD827FE585A00D472C2 /* AppSecrets.swift.masque */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AppSecrets.swift.masque; sourceTree = "<group>"; };
526526
00273CF32A82AB5900A7A77D /* SamplesSearchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SamplesSearchView.swift; sourceTree = "<group>"; };
527527
00273CF52A82AB8700A7A77D /* SampleRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleRow.swift; sourceTree = "<group>"; };
@@ -741,7 +741,7 @@
741741
isa = PBXGroup;
742742
children = (
743743
E08953F02891899600E077CF /* EnvironmentValues+SampleInfoVisibility.swift */,
744-
00181B452846AD7100654571 /* View+Alert.swift */,
744+
00181B452846AD7100654571 /* View+ErrorAlert.swift */,
745745
E0082216287755AC002AD138 /* View+Sheet.swift */,
746746
);
747747
path = Extensions;
@@ -2236,7 +2236,7 @@
22362236
D71FCB8A2AD6277F000E517C /* CreateMobileGeodatabaseView.Model.swift in Sources */,
22372237
D752D9462A3A6F80003EB25E /* MonitorChangesToMapLoadStatusView.swift in Sources */,
22382238
E0082217287755AC002AD138 /* View+Sheet.swift in Sources */,
2239-
00181B462846AD7100654571 /* View+Alert.swift in Sources */,
2239+
00181B462846AD7100654571 /* View+ErrorAlert.swift in Sources */,
22402240
00273CF62A82AB8700A7A77D /* SampleRow.swift in Sources */,
22412241
D7ABA2FF2A32881C0021822B /* ShowViewshedFromGeoelementInSceneView.swift in Sources */,
22422242
E0FE32E728747778002C6ACA /* BrowseBuildingFloorsView.swift in Sources */,

Shared/Samples/Add feature layers/AddFeatureLayersView.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,8 @@ import ArcGIS
1616
import SwiftUI
1717

1818
struct AddFeatureLayersView: View {
19-
/// A Boolean value indicating whether to show an alert.
20-
@State private var isShowingAlert = false
21-
22-
/// The error shown in the alert.
23-
@State private var error: Error? {
24-
didSet { isShowingAlert = error != nil }
25-
}
19+
/// The error shown in the error alert.
20+
@State private var error: Error?
2621

2722
/// The current viewpoint of the map view.
2823
@State private var viewpoint: Viewpoint?
@@ -52,7 +47,7 @@ struct AddFeatureLayersView: View {
5247
}
5348
}
5449
}
55-
.alert(isPresented: $isShowingAlert, presentingError: error)
50+
.errorAlert(presentingError: $error)
5651
.onAppear {
5752
// Updates the URL session challenge handler to use the
5853
// specified credentials and tokens for any challenges.

Shared/Samples/Add raster from file/AddRasterFromFileView.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,8 @@ struct AddRasterFromFileView: View {
1919
/// A map with imagery basemap and a raster layer.
2020
@State private var map = Map(basemapStyle: .arcGISImageryStandard)
2121

22-
/// A Boolean value indicating whether to show an alert.
23-
@State private var isShowingAlert = false
24-
25-
/// The error shown in the alert.
26-
@State private var error: Error? {
27-
didSet { isShowingAlert = error != nil }
28-
}
22+
/// The error shown in the error alert.
23+
@State private var error: Error?
2924

3025
/// The current viewpoint of the map view.
3126
@State private var viewpoint: Viewpoint?
@@ -34,7 +29,7 @@ struct AddRasterFromFileView: View {
3429
// Creates a map view with a viewpoint to display the map.
3530
MapView(map: map, viewpoint: viewpoint)
3631
.onViewpointChanged(kind: .centerAndScale) { viewpoint = $0 }
37-
.alert(isPresented: $isShowingAlert, presentingError: error)
32+
.errorAlert(presentingError: $error)
3833
.task {
3934
guard map.operationalLayers.isEmpty else { return }
4035
do {

Shared/Samples/Analyze network with subnetwork trace/AnalyzeNetworkWithSubnetworkTraceView.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,8 @@ struct AnalyzeNetworkWithSubnetworkTraceView: View {
4646
/// A Boolean value indicating whether to include containment features in the trace results.
4747
@State private var includesContainers = true
4848

49-
/// A Boolean value indicating whether to show an alert.
50-
@State private var isPresentingError = false
51-
52-
/// The error shown in the alert.
53-
@State private var error: Error? {
54-
didSet { isPresentingError = error != nil }
55-
}
49+
/// The error shown in the error alert.
50+
@State private var error: Error?
5651

5752
var body: some View {
5853
if !model.isSetUp {
@@ -150,7 +145,7 @@ struct AnalyzeNetworkWithSubnetworkTraceView: View {
150145
.shadow(radius: 50)
151146
}
152147
}
153-
.alert(isPresented: $isPresentingError, presentingError: error)
148+
.errorAlert(presentingError: $error)
154149
}
155150

156151
@ViewBuilder var conditionMenu: some View {

Shared/Samples/Augment reality to show tabletop scene/AugmentRealityToShowTabletopSceneView.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@ struct AugmentRealityToShowTabletopSceneView: View {
2020
/// The scene used to create the scene view.
2121
@State private var scene = ArcGIS.Scene()
2222

23-
/// A Boolean value indicating whether to show an error alert.
24-
@State private var isShowingErrorAlert = false
25-
2623
/// The error shown in the error alert.
27-
@State private var error: Error? {
28-
didSet { isShowingErrorAlert = error != nil }
29-
}
24+
@State private var error: Error?
3025

3126
/// The location point of the scene that will be anchored on a physical surface.
3227
private let anchorPoint = Point(
@@ -77,7 +72,7 @@ struct AugmentRealityToShowTabletopSceneView: View {
7772
self.error = error
7873
}
7974
}
80-
.alert(isPresented: $isShowingErrorAlert, presentingError: error)
75+
.errorAlert(presentingError: $error)
8176
}
8277
}
8378

Shared/Samples/Browse building floors/BrowseBuildingFloorsView.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,8 @@ import ArcGISToolkit
1717
import SwiftUI
1818

1919
struct BrowseBuildingFloorsView: View {
20-
/// A Boolean value indicating whether to show an alert.
21-
@State private var isShowingAlert = false
22-
23-
/// The error shown in the alert.
24-
@State private var error: Error? {
25-
didSet { isShowingAlert = error != nil }
26-
}
20+
/// The error shown in the error alert.
21+
@State private var error: Error?
2722

2823
/// The current viewpoint of the map.
2924
@State private var viewpoint: Viewpoint?
@@ -46,7 +41,7 @@ struct BrowseBuildingFloorsView: View {
4641
MapView(map: map)
4742
.onViewpointChanged(kind: .centerAndScale) { viewpoint = $0 }
4843
.onNavigatingChanged { isMapNavigating = $0 }
49-
.alert(isPresented: $isShowingAlert, presentingError: error)
44+
.errorAlert(presentingError: $error)
5045
.ignoresSafeArea(.keyboard, edges: .bottom)
5146
.overlay(alignment: .bottomTrailing) {
5247
if isMapLoaded,

Shared/Samples/Create and save KML file/CreateAndSaveKMLView.Model.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,8 @@ extension CreateAndSaveKMLView {
6060
/// A Boolean value indicating if the file exporter button should be disabled.
6161
@Published var fileExporterButtonIsDisabled = true
6262

63-
/// A Boolean value indicating whether to show an alert.
64-
@Published var isShowingAlert = false
65-
66-
/// The error shown in the alert.
67-
@Published var error: Error? {
68-
didSet { isShowingAlert = error != nil }
69-
}
63+
/// The error shown in the error alert.
64+
@Published var error: Error?
7065

7166
/// Creates the model for this view.
7267
init() {

Shared/Samples/Create and save KML file/CreateAndSaveKMLView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct CreateAndSaveKMLView: View {
2323
var body: some View {
2424
MapView(map: model.map)
2525
.geometryEditor(model.geometryEditor)
26-
.alert(isPresented: $model.isShowingAlert, presentingError: model.error)
26+
.errorAlert(presentingError: $model.error)
2727
.toolbar {
2828
ToolbarItem(placement: .primaryAction) {
2929
HStack {

Shared/Samples/Create load report/CreateLoadReportView.Model.swift

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,12 @@ extension CreateLoadReportView {
5959
private(set) var setupError: Error? {
6060
didSet {
6161
updateAllowsCreateLoadReport()
62-
isShowingSetupError = setupError != nil
62+
error = setupError
6363
}
6464
}
6565

66-
/// A Boolean value indicating whether a setup error is showing.
67-
@Published var isShowingSetupError = false
68-
69-
/// An error that occurred creating the load report.
70-
private(set) var loadReportError: Error? {
71-
didSet {
72-
isShowingLoadReportError = loadReportError != nil
73-
}
74-
}
75-
76-
/// A Boolean value indicating whether a load report error is showing.
77-
@Published var isShowingLoadReportError = false
66+
/// The error shown in the error alert.
67+
@Published var error: Error?
7868

7969
// MARK: Methods
8070

@@ -249,7 +239,7 @@ extension CreateLoadReportView {
249239
} catch {
250240
// On error, remove any summaries already generated.
251241
summaries.removeAll()
252-
loadReportError = error
242+
self.error = error
253243
}
254244
}
255245

Shared/Samples/Create load report/CreateLoadReportView.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ struct CreateLoadReportView: View {
2424
.task {
2525
await model.setup()
2626
}
27-
.alert(isPresented: $model.isShowingSetupError, presentingError: model.setupError)
28-
.alert(isPresented: $model.isShowingLoadReportError, presentingError: model.loadReportError)
27+
.errorAlert(presentingError: $model.error)
2928
.toolbar {
3029
ToolbarItemGroup(placement: .bottomBar) {
3130
Button("Run") {

0 commit comments

Comments
 (0)