Skip to content

Commit fd470e0

Browse files
authored
Merge pull request #481 from Esri/Caleb/Update-UseLabeledContent
[Update] Use `LabeledContent` in samples
2 parents 53f4d3c + 0b04374 commit fd470e0

File tree

13 files changed

+78
-146
lines changed

13 files changed

+78
-146
lines changed

Shared/Samples/Add dynamic entity layer/AddDynamicEntityLayerView.SettingsView.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ extension AddDynamicEntityLayerView {
3636

3737
Section("Observations") {
3838
VStack {
39-
HStack {
40-
Text("Observations per track")
41-
Spacer()
42-
Text(model.maximumObservations.formatted())
43-
.foregroundStyle(.secondary)
44-
}
39+
LabeledContent(
40+
"Observations per track",
41+
value: model.maximumObservations.formatted()
42+
)
4543
Slider(value: $model.maximumObservations, in: model.maxObservationRange, step: 1)
4644
}
4745
HStack {

Shared/Samples/Add features with contingent values/AddFeaturesWithContingentValuesView.AddFeatureView.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ extension AddFeaturesWithContingentValuesView {
8787
}
8888

8989
VStack {
90-
HStack {
91-
Text("Exclusion Area Buffer Size")
92-
Spacer()
93-
Text("\(Int(selectedBufferSize ?? 0))")
94-
}
90+
LabeledContent(
91+
"Exclusion Area Buffer Size",
92+
value: selectedBufferSize ?? 0,
93+
format: .number.precision(.fractionLength(0))
94+
)
9595

9696
Slider(
9797
value: Binding(

Shared/Samples/Animate 3D graphic/Animate3DGraphicView.swift

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ struct Animate3DGraphicView: View {
3535
VStack {
3636
HStack {
3737
Spacer()
38-
VStack {
39-
StatRow("Altitude", value: model.animation.currentFrame.altitude.formatted(.length))
40-
StatRow("Heading", value: model.animation.currentFrame.heading.formatted(.angle))
41-
StatRow("Pitch", value: model.animation.currentFrame.pitch.formatted(.angle))
42-
StatRow("Roll", value: model.animation.currentFrame.roll.formatted(.angle))
38+
VStack(spacing: 3) {
39+
LabeledContent("Altitude", value: model.animation.currentFrame.altitude, format: .length)
40+
LabeledContent("Heading", value: model.animation.currentFrame.heading, format: .angle)
41+
LabeledContent("Pitch", value: model.animation.currentFrame.pitch, format: .angle)
42+
LabeledContent("Roll", value: model.animation.currentFrame.roll, format: .angle)
4343
}
4444
.frame(width: 170, height: 100)
4545
.padding([.leading, .trailing])
@@ -103,7 +103,7 @@ struct Animate3DGraphicView: View {
103103
List {
104104
Section("Mission") {
105105
VStack {
106-
StatRow("Progress", value: model.animation.progress.formatted(.rounded))
106+
LabeledContent("Progress", value: model.animation.progress, format: .rounded)
107107
ProgressView(value: model.animation.progress)
108108
}
109109
.padding(.vertical)
@@ -135,7 +135,7 @@ struct Animate3DGraphicView: View {
135135
Section {
136136
ForEach(CameraProperty.allCases, id: \.self) { property in
137137
VStack {
138-
StatRow(property.label, value: model.cameraPropertyTexts[property] ?? "")
138+
LabeledContent(property.label, value: model.cameraPropertyTexts[property] ?? "")
139139
Slider(value: cameraPropertyBinding(for: property), in: property.range, step: 1)
140140
.padding(.horizontal)
141141
}
@@ -162,27 +162,6 @@ extension Animate3DGraphicView {
162162
case .pitch: return $model.cameraController.cameraPitchOffset
163163
}
164164
}
165-
166-
/// A view for displaying a statistic name and value in a row.
167-
struct StatRow: View {
168-
/// The name of the statistic.
169-
var label: String
170-
/// The formatted value of the statistic.
171-
var value: String
172-
173-
init(_ label: String, value: String) {
174-
self.label = label
175-
self.value = value
176-
}
177-
178-
var body: some View {
179-
HStack {
180-
Text(label)
181-
Spacer()
182-
Text(value)
183-
}
184-
}
185-
}
186165
}
187166

188167
private extension FormatStyle where Self == Measurement<UnitLength>.FormatStyle {

Shared/Samples/Change map view background/ChangeMapViewBackgroundView.SettingsView.swift

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,11 @@ extension ChangeMapViewBackgroundView {
2828
ColorPicker("Color", selection: $model.color)
2929
ColorPicker("Line Color", selection: $model.lineColor)
3030
VStack {
31-
HStack {
32-
Text("Line Width")
33-
Spacer()
34-
Text(model.lineWidth.formatted())
35-
.foregroundStyle(.secondary)
36-
}
31+
LabeledContent("Line Width", value: model.lineWidth.formatted())
3732
Slider(value: $model.lineWidth, in: model.lineWidthRange, step: 1)
3833
}
3934
VStack {
40-
HStack {
41-
Text("Grid Size")
42-
Spacer()
43-
Text(model.size.formatted())
44-
.foregroundStyle(.secondary)
45-
}
46-
Spacer()
35+
LabeledContent("Grid Size", value: model.size.formatted())
4736
Slider(value: $model.size, in: model.sizeRange, step: 1)
4837
}
4938
}

Shared/Samples/Configure clusters/ConfigureClustersView.SettingsView.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,11 @@ extension ConfigureClustersView {
5858
model.maxScale = Double(newMaxScale)
5959
}
6060

61-
HStack {
62-
Text("Current Map Scale")
63-
Spacer()
64-
Text(mapViewScale, format: .number.precision(.fractionLength(0)))
65-
.foregroundStyle(.secondary)
66-
}
61+
LabeledContent(
62+
"Current Map Scale",
63+
value: mapViewScale,
64+
format: .number.precision(.fractionLength(0))
65+
)
6766
}
6867
}
6968
.navigationTitle("Clustering Settings")

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ extension CreateLoadReportView {
3232
.onTapGesture {
3333
model.deletePhase(phase)
3434
}
35-
Text("Phase: \(phase.name)")
36-
Spacer()
37-
Text(model.summaryForPhase(phase))
35+
LabeledContent(
36+
"Phase: \(phase.name)",
37+
value: model.summaryForPhase(phase)
38+
)
3839
}
3940
}
4041
.onDelete { indexSet in

Shared/Samples/Densify and generalize geometry/DensifyAndGeneralizeGeometryView.SettingsView.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ extension DensifyAndGeneralizeGeometryView {
3232
model.updateGraphics()
3333
}
3434
VStack {
35-
HStack {
36-
Text("Max Deviation")
37-
Spacer()
38-
Text(String(Int(model.maxDeviation)))
39-
}
35+
LabeledContent(
36+
"Max Deviation",
37+
value: model.maxDeviation,
38+
format: .number.precision(.fractionLength(0))
39+
)
4040
Slider(value: $model.maxDeviation, in: 1...250)
4141
.onChange(of: model.maxDeviation) { _ in
4242
model.updateGraphics()
@@ -50,11 +50,11 @@ extension DensifyAndGeneralizeGeometryView {
5050
model.updateGraphics()
5151
}
5252
VStack {
53-
HStack {
54-
Text("Max Segment Length")
55-
Spacer()
56-
Text(String(Int(model.maxSegmentLength)))
57-
}
53+
LabeledContent(
54+
"Max Segment Length",
55+
value: model.maxSegmentLength,
56+
format: .number.precision(.fractionLength(0))
57+
)
5858
Slider(value: $model.maxSegmentLength, in: 50...500)
5959
.onChange(of: model.maxSegmentLength) { _ in
6060
model.updateGraphics()

Shared/Samples/Generate offline map with custom parameters/GenerateOfflineMapWithCustomParametersView.CustomParameters.swift

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,29 @@ extension GenerateOfflineMapWithCustomParametersView {
7070
Form {
7171
Section("Adjust Basemap") {
7272
VStack {
73-
Text("Min Scale Level")
74-
.badge(
75-
Text(minScaleLevel, format: .number.precision(.fractionLength(0)))
76-
)
73+
LabeledContent(
74+
"Min Scale Level",
75+
value: minScaleLevel,
76+
format: .number.precision(.fractionLength(0))
77+
)
7778
Slider(value: $minScaleLevel, in: scaleLevelRange, step: 1)
7879
}
7980

8081
VStack {
81-
Text("Max Scale Level")
82-
.badge(
83-
Text(maxScaleLevel, format: .number.precision(.fractionLength(0)))
84-
)
82+
LabeledContent(
83+
"Max Scale Level",
84+
value: maxScaleLevel,
85+
format: .number.precision(.fractionLength(0))
86+
)
8587
Slider(value: $maxScaleLevel, in: scaleLevelRange, step: 1.0)
8688
}
8789

8890
VStack {
89-
Text("Extent Buffer Distance")
90-
.badge(
91-
Text(basemapExtentBufferDistance, format: .number.precision(.fractionLength(0)))
92-
)
91+
LabeledContent(
92+
"Extent Buffer Distance",
93+
value: basemapExtentBufferDistance,
94+
format: .number.precision(.fractionLength(0))
95+
)
9396
Slider(value: $basemapExtentBufferDistance, in: basemapExtentBufferRange)
9497
}
9598
}
@@ -101,10 +104,11 @@ extension GenerateOfflineMapWithCustomParametersView {
101104

102105
Section("Filter Feature Layer") {
103106
VStack {
104-
Text("Min Hydrant Flow Rate")
105-
.badge(
106-
Text(minHydrantFlowRate, format: .number.precision(.fractionLength(0)))
107-
)
107+
LabeledContent(
108+
"Min Hydrant Flow Rate",
109+
value: minHydrantFlowRate,
110+
format: .number.precision(.fractionLength(0))
111+
)
108112
Slider(value: $minHydrantFlowRate, in: hydrantFlowRateRange, step: 1.0)
109113
}
110114
}

Shared/Samples/Orbit camera around object/OrbitCameraAroundObjectView.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,7 @@ private extension OrbitCameraAroundObjectView {
108108
NavigationStack {
109109
List {
110110
VStack {
111-
Text("Camera Heading")
112-
.badge(
113-
Text(cameraHeading, format: .degrees)
114-
)
111+
LabeledContent("Camera Heading", value: cameraHeading, format: .degrees)
115112

116113
Slider(value: $cameraHeading.value, in: -45...45)
117114
.onChange(of: cameraHeading.value) { newValue in
@@ -120,10 +117,7 @@ private extension OrbitCameraAroundObjectView {
120117
}
121118

122119
VStack {
123-
Text("Plane Pitch")
124-
.badge(
125-
Text(planePitch, format: .degrees)
126-
)
120+
LabeledContent("Plane Pitch", value: planePitch, format: .degrees)
127121

128122
Slider(value: $planePitch.value, in: -90...90)
129123
.onChange(of: planePitch.value) { newValue in

Shared/Samples/Set visibility of subtype sublayer/SetVisibilityOfSubtypeSublayerView.Views.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,7 @@ extension SetVisibilityOfSubtypeSublayerView {
4242
}
4343
}
4444
Section("Sublayer Minimum Scale") {
45-
HStack {
46-
Text("Minimum Scale")
47-
Spacer()
48-
Text(model.minimumScaleText)
49-
.foregroundStyle(.secondary)
50-
}
45+
LabeledContent("Minimum Scale", value: model.minimumScaleText)
5146
HStack {
5247
Button("Set Current to Minimum Scale") {
5348
model.setMinimumScale()

0 commit comments

Comments
 (0)