Skip to content

Commit 0cbd014

Browse files
authored
Merge pull request #661 from Esri/Caleb/Fix-PopupViewWarnings
[Fix] `PopupView` deprecation warnings
2 parents 671db64 + b651ac4 commit 0cbd014

File tree

6 files changed

+68
-50
lines changed

6 files changed

+68
-50
lines changed

Shared/Samples/Configure clusters/ConfigureClustersView.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,10 @@ struct ConfigureClustersView: View {
4747
showsPopup = popup != nil
4848
}
4949
}
50-
.floatingPanel(
51-
selectedDetent: .constant(.half),
52-
horizontalAlignment: .leading,
53-
isPresented: $showsPopup
54-
) { [popup] in
55-
PopupView(popup: popup!, isPresented: $showsPopup)
56-
.padding()
50+
.popover(isPresented: $showsPopup, attachmentAnchor: .point(.bottom)) { [popup] in
51+
PopupView(root: popup!, isPresented: $showsPopup)
52+
.presentationDetents([.fraction(0.5)])
53+
.frame(idealWidth: 320, idealHeight: 300)
5754
}
5855
.toolbar {
5956
ToolbarItem(placement: .bottomBar) {

Shared/Samples/Display clusters/DisplayClustersView.swift

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ struct DisplayClustersView: View {
5656
identifyScreenPoint = screenPoint
5757
}
5858
.task(id: identifyScreenPoint) {
59-
layer?.clearSelection()
6059
geoElements.removeAll()
6160

6261
guard let identifyScreenPoint,
@@ -79,32 +78,11 @@ struct DisplayClustersView: View {
7978
layer.selectFeature(feature)
8079
}
8180
}
82-
.floatingPanel(
83-
selectedDetent: .constant(.half),
84-
horizontalAlignment: .leading,
85-
isPresented: $showsPopup
86-
) { [popup] in
87-
PopupView(popup: popup!, isPresented: $showsPopup)
88-
.padding([.top, .horizontal])
89-
90-
if !geoElements.isEmpty {
91-
List {
92-
Section {
93-
ForEach(Array(geoElements.enumerated()),
94-
id: \.offset
95-
) { offset, geoElement in
96-
let name = geoElement.attributes["name"] as? String
97-
Text(name ?? "Geoelement: \(offset)")
98-
}
99-
} header: {
100-
Text("Geoelements")
101-
.font(.title3)
102-
.bold()
103-
.foregroundStyle(.primary)
104-
}
105-
}
106-
.listStyle(.inset)
107-
}
81+
.popover(isPresented: $showsPopup, attachmentAnchor: .point(.bottom)) { [popup] in
82+
ClusterDetailView(popup: popup!, geoElements: geoElements)
83+
.presentationDetents([.fraction(0.5)])
84+
.frame(idealWidth: 320, idealHeight: 380)
85+
.onDisappear(perform: layer?.clearSelection)
10886
}
10987
.toolbar {
11088
ToolbarItem(placement: .bottomBar) {
@@ -131,6 +109,60 @@ struct DisplayClustersView: View {
131109
}
132110
}
133111

112+
/// A view that displays the details of a cluster.
113+
private struct ClusterDetailView: View {
114+
/// The cluster's popup to display.
115+
let popup: Popup
116+
117+
/// The cluster's geoelements to display.
118+
let geoElements: [GeoElement]
119+
120+
/// The action to dismiss the view.
121+
@Environment(\.dismiss) private var dismiss
122+
123+
/// A Boolean value indicating whether the popup is currently being shown in the view.
124+
@State private var popupIsSelectedTab = true
125+
126+
var body: some View {
127+
NavigationStack {
128+
Group {
129+
if popupIsSelectedTab {
130+
PopupView(root: popup)
131+
} else {
132+
List(Array(geoElements.enumerated()), id: \.offset) { offset, geoElement in
133+
let name = geoElement.attributes["name"] as? String
134+
Text(name ?? "Geoelement: \(offset)")
135+
}
136+
.listStyle(.inset)
137+
.navigationTitle("Geoelements")
138+
.navigationBarTitleDisplayMode(.inline)
139+
.overlay {
140+
if geoElements.isEmpty {
141+
ContentUnavailableView(
142+
"No Geoelements",
143+
systemImage: "list.bullet",
144+
description: Text("There are no aggregate geoelements for this cluster.")
145+
)
146+
}
147+
}
148+
}
149+
}
150+
.toolbar {
151+
ToolbarItem(placement: .confirmationAction) {
152+
Button("Done") { dismiss() }
153+
}
154+
ToolbarItem(placement: .bottomBar) {
155+
Picker("Tab", selection: $popupIsSelectedTab) {
156+
Text("Popup").tag(true)
157+
Text("Geoelements").tag(false)
158+
}
159+
.pickerStyle(.segmented)
160+
}
161+
}
162+
}
163+
}
164+
}
165+
134166
#Preview {
135167
NavigationStack {
136168
DisplayClustersView()
-45.5 KB
Loading

Shared/Samples/Set up location-driven geotriggers/SetUpLocationDrivenGeotriggersView.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,16 @@ struct SetUpLocationDrivenGeotriggersView: View {
9898
isShowingPopup = true
9999
}
100100
.disabled(!model.hasCurrentSection)
101-
.opacity(isShowingPopup ? 0 : 1)
102101

103102
Button("Point of Interest") {
104103
model.setPOIPopup()
105104
isShowingPopup = true
106105
}
107106
.disabled(!model.hasPointOfInterest)
108-
.opacity(isShowingPopup ? 0 : 1)
109107
}
110108
}
111-
.floatingPanel(
112-
selectedDetent: .constant(.full),
113-
horizontalAlignment: .leading,
114-
isPresented: $isShowingPopup
115-
) {
116-
PopupView(popup: model.popup!, isPresented: $isShowingPopup)
117-
.padding()
109+
.sheet(isPresented: $isShowingPopup) {
110+
PopupView(root: model.popup!, isPresented: $isShowingPopup)
118111
}
119112
.task(id: isShowingPopup) {
120113
if isShowingPopup {

Shared/Samples/Show popup/ShowPopupView.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,9 @@ struct ShowPopupView: View {
5151
self.popup = identifyResult.first?.popups.first
5252
self.showPopup = self.popup != nil
5353
}
54-
.floatingPanel(
55-
selectedDetent: .constant(.full),
56-
horizontalAlignment: .leading,
57-
isPresented: $showPopup
58-
) { [popup] in
59-
PopupView(popup: popup!, isPresented: $showPopup)
60-
.padding()
54+
.popover(isPresented: $showPopup, attachmentAnchor: .point(.top)) { [popup] in
55+
PopupView(root: popup!, isPresented: $showPopup)
56+
.frame(idealWidth: 320, idealHeight: 600)
6157
}
6258
}
6359
}
-18.4 KB
Loading

0 commit comments

Comments
 (0)