Skip to content

Commit 4868a0c

Browse files
authored
Merge pull request #262 from Esri/philium/des12437/Fix-visibility-in-dynamic-entity-layer-sample
[Fix] Add dynamic entity layer settings presentation refactor
2 parents efab71e + 95e5864 commit 4868a0c

File tree

2 files changed

+54
-46
lines changed

2 files changed

+54
-46
lines changed

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

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,55 @@ extension AddDynamicEntityLayerView {
2323
@Environment(\.dismiss) private var dismiss: DismissAction
2424

2525
var body: some View {
26-
NavigationView {
27-
List {
28-
Section("Track display properties") {
29-
Toggle("Track Lines", isOn: $model.showsTrackLine)
30-
Toggle("Previous Observations", isOn: $model.showsPreviousObservations)
31-
}
32-
33-
Section("Observations") {
34-
VStack {
35-
HStack {
36-
Text("Observations per track")
37-
Spacer()
38-
Text(model.maximumObservations.formatted())
39-
.foregroundColor(.secondary)
40-
}
41-
Slider(value: $model.maximumObservations, in: model.maxObservationRange, step: 1)
42-
}
26+
if #available(iOS 16, *) {
27+
NavigationStack {
28+
root
29+
}
30+
} else {
31+
NavigationView {
32+
root
33+
}
34+
.navigationViewStyle(.stack)
35+
}
36+
}
37+
38+
@ViewBuilder var root: some View {
39+
Form {
40+
Section("Track display properties") {
41+
Toggle("Track Lines", isOn: $model.showsTrackLine)
42+
Toggle("Previous Observations", isOn: $model.showsPreviousObservations)
43+
}
44+
45+
Section("Observations") {
46+
VStack {
4347
HStack {
48+
Text("Observations per track")
4449
Spacer()
45-
Button("Purge All Observations") {
46-
Task {
47-
try? await model.streamService.purgeAll()
48-
}
50+
Text(model.maximumObservations.formatted())
51+
.foregroundColor(.secondary)
52+
}
53+
Slider(value: $model.maximumObservations, in: model.maxObservationRange, step: 1)
54+
}
55+
HStack {
56+
Spacer()
57+
Button("Purge All Observations") {
58+
Task {
59+
try? await model.streamService.purgeAll()
4960
}
50-
Spacer()
5161
}
62+
Spacer()
5263
}
5364
}
54-
.navigationTitle("Dynamic Entity Settings")
55-
.navigationBarTitleDisplayMode(.inline)
56-
.toolbar {
57-
ToolbarItem(placement: .confirmationAction) {
58-
Button("Done") {
59-
dismiss()
60-
}
65+
}
66+
.toggleStyle(.switch)
67+
.navigationTitle("Dynamic Entity Settings")
68+
.navigationBarTitleDisplayMode(.inline)
69+
.toolbar {
70+
ToolbarItem(placement: .confirmationAction) {
71+
Button("Done") {
72+
dismiss()
6173
}
6274
}
63-
.navigationViewStyle(.stack)
6475
}
6576
}
6677
}

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ struct AddDynamicEntityLayerView: View {
2020
@StateObject private var model = Model()
2121

2222
/// A Boolean value indicating whether the settings view should be presented.
23-
@State var isShowingSettings = false
23+
@State private var isShowingSettings = false
2424

2525
/// The initial viewpoint for the map.
26-
@State var viewpoint = Viewpoint(
26+
@State private var viewpoint = Viewpoint(
2727
center: Point(x: -12452361.486, y: 4949774.965),
2828
scale: 200_000
2929
)
@@ -33,12 +33,6 @@ struct AddDynamicEntityLayerView: View {
3333
model.streamService.connectionStatus == .connected
3434
}
3535

36-
/// The horizontal size class of the environment.
37-
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
38-
39-
/// The vertical size class of the environment.
40-
@Environment(\.verticalSizeClass) private var verticalSizeClass
41-
4236
var body: some View {
4337
// Creates a map view to display the map.
4438
MapView(map: model.map, viewpoint: viewpoint)
@@ -80,20 +74,23 @@ struct AddDynamicEntityLayerView: View {
8074
let button = Button("Dynamic Entity Settings") {
8175
isShowingSettings = true
8276
}
83-
if #available(iOS 16, *),
84-
horizontalSizeClass == .compact,
85-
verticalSizeClass == .regular {
77+
let settingsView = SettingsView()
78+
.environmentObject(model)
79+
if #available(iOS 16, *) {
8680
button
87-
.sheet(isPresented: $isShowingSettings) {
88-
SettingsView()
89-
.environmentObject(model)
81+
.popover(isPresented: $isShowingSettings, arrowEdge: .bottom) {
82+
settingsView
9083
.presentationDetents([.fraction(0.5)])
84+
#if targetEnvironment(macCatalyst)
85+
.frame(minWidth: 300, minHeight: 270)
86+
#else
87+
.frame(minWidth: 320, minHeight: 390)
88+
#endif
9189
}
9290
} else {
9391
button
9492
.sheet(isPresented: $isShowingSettings, detents: [.medium]) {
95-
SettingsView()
96-
.environmentObject(model)
93+
settingsView
9794
}
9895
}
9996
}

0 commit comments

Comments
 (0)