Skip to content

Commit cd79199

Browse files
authored
Merge pull request #550 from Esri/Caleb/Update-AddMoreSampleMenuActions
[Update] Add sample action menu
2 parents 8c34d17 + a54bdb9 commit cd79199

File tree

5 files changed

+76
-36
lines changed

5 files changed

+76
-36
lines changed

Samples.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@
280280
D72F272E2ADA1E4400F906DA /* AugmentRealityToShowTabletopSceneView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D72F272B2ADA1E4400F906DA /* AugmentRealityToShowTabletopSceneView.swift */; };
281281
D72F27302ADA1E9900F906DA /* AugmentRealityToShowTabletopSceneView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D72F272B2ADA1E4400F906DA /* AugmentRealityToShowTabletopSceneView.swift */; };
282282
D72FE7032CE6D05600BBC0FE /* AppFavorites.swift in Sources */ = {isa = PBXBuildFile; fileRef = D72FE7022CE6D05600BBC0FE /* AppFavorites.swift */; };
283+
D72FE7082CE6DA1900BBC0FE /* SampleMenuButtons.swift in Sources */ = {isa = PBXBuildFile; fileRef = D72FE7072CE6DA1900BBC0FE /* SampleMenuButtons.swift */; };
283284
D731F3C12AD0D2AC00A8431E /* IdentifyGraphicsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D731F3C02AD0D2AC00A8431E /* IdentifyGraphicsView.swift */; };
284285
D731F3C22AD0D2BB00A8431E /* IdentifyGraphicsView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D731F3C02AD0D2AC00A8431E /* IdentifyGraphicsView.swift */; };
285286
D7337C5A2ABCFDB100A5D865 /* StyleSymbolsFromMobileStyleFileView.SymbolOptionsListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7337C592ABCFDB100A5D865 /* StyleSymbolsFromMobileStyleFileView.SymbolOptionsListView.swift */; };
@@ -967,6 +968,7 @@
967968
D72C43F22AEB066D00B6157B /* GeocodeOfflineView.Model.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeocodeOfflineView.Model.swift; sourceTree = "<group>"; };
968969
D72F272B2ADA1E4400F906DA /* AugmentRealityToShowTabletopSceneView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AugmentRealityToShowTabletopSceneView.swift; sourceTree = "<group>"; };
969970
D72FE7022CE6D05600BBC0FE /* AppFavorites.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppFavorites.swift; sourceTree = "<group>"; };
971+
D72FE7072CE6DA1900BBC0FE /* SampleMenuButtons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleMenuButtons.swift; sourceTree = "<group>"; };
970972
D731F3C02AD0D2AC00A8431E /* IdentifyGraphicsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IdentifyGraphicsView.swift; sourceTree = "<group>"; };
971973
D7337C592ABCFDB100A5D865 /* StyleSymbolsFromMobileStyleFileView.SymbolOptionsListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StyleSymbolsFromMobileStyleFileView.SymbolOptionsListView.swift; sourceTree = "<group>"; };
972974
D7337C5F2ABD142D00A5D865 /* ShowMobileMapPackageExpirationDateView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShowMobileMapPackageExpirationDateView.swift; sourceTree = "<group>"; };
@@ -1147,6 +1149,7 @@
11471149
000558092817C51E00224BC6 /* SampleDetailView.swift */,
11481150
E041ABD6287DB04D0056009B /* SampleInfoView.swift */,
11491151
00273CF52A82AB8700A7A77D /* SampleLink.swift */,
1152+
D72FE7072CE6DA1900BBC0FE /* SampleMenuButtons.swift */,
11501153
00273CF32A82AB5900A7A77D /* SamplesSearchView.swift */,
11511154
E041ABBF287CA9F00056009B /* WebView.swift */,
11521155
);
@@ -3439,6 +3442,7 @@
34393442
95F891292C46E9D60010EBED /* ShowDeviceLocationUsingIndoorPositioningView.swift in Sources */,
34403443
1C2538562BABACFD00337307 /* AugmentRealityToNavigateRouteView.swift in Sources */,
34413444
1C2538572BABACFD00337307 /* AugmentRealityToNavigateRouteView.ARSceneView.swift in Sources */,
3445+
D72FE7082CE6DA1900BBC0FE /* SampleMenuButtons.swift in Sources */,
34423446
D76929FA2B4F79540047205E /* OrbitCameraAroundObjectView.swift in Sources */,
34433447
D771D0C82CD55211004C13CB /* ApplyRasterRenderingRuleView.swift in Sources */,
34443448
79D84D132A81711A00F45262 /* AddCustomDynamicEntityDataSourceView.swift in Sources */,

Shared/Supporting Files/Models/Sample.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ protocol Sample: Sendable {
4242
// MARK: Computed Variables
4343

4444
extension Sample {
45+
/// The web URL to the sample's Esri Developer page.
46+
var esriDeveloperURL: URL {
47+
let dashedName = name.replacingOccurrences(of: " ", with: "-").lowercased()
48+
return URL(string: "https://developers.arcgis.com/swift/sample-code")!
49+
.appendingPathComponent(dashedName)
50+
}
51+
4552
/// The URL to a sample's sub-directory on GitHub main branch.
4653
var gitHubURL: URL {
4754
URL(string: "https://github.com/Esri/arcgis-maps-sdk-swift-samples/tree/main/Shared/Samples")!

Shared/Supporting Files/Views/SampleDetailView.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ struct SampleDetailView: View {
2525
@StateObject private var onDemandResource: OnDemandResource
2626

2727
/// A Boolean value indicating whether a sample should use on-demand resources.
28-
var usesOnDemandResources: Bool {
28+
private var usesOnDemandResources: Bool {
2929
#if targetEnvironment(macCatalyst)
3030
// Mac Catalyst isn't supported by `NSBundleResourceRequest`. Instead, Xcode
31-
// put the offline data into the app bundle on Mac Catalyst.
31+
// puts the offline data into the app bundle on Mac Catalyst.
3232
return false
3333
#else
3434
return sample.hasDependencies
@@ -84,14 +84,12 @@ struct SampleDetailView: View {
8484
.navigationTitle(sample.name)
8585
.navigationBarTitleDisplayMode(.inline)
8686
.toolbar {
87-
ToolbarItemGroup(placement: .topBarTrailing) {
88-
#if targetEnvironment(macCatalyst)
89-
Link("View on GitHub", destination: sample.gitHubURL)
90-
#endif
91-
Button {
92-
isSampleInfoViewPresented = true
93-
} label: {
94-
Image(systemName: "info.circle")
87+
ToolbarItem(placement: .topBarTrailing) {
88+
Menu("Sample Actions", systemImage: "ellipsis.circle") {
89+
Button("View Info", systemImage: "info.circle") {
90+
isSampleInfoViewPresented = true
91+
}
92+
SampleMenuButtons(sample: sample)
9593
}
9694
.sheet(isPresented: $isSampleInfoViewPresented) {
9795
NavigationStack {

Shared/Supporting Files/Views/SampleLink.swift

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,15 @@ struct SampleLink: View {
3838
// of its map when a keyboard is presented in landscape mode.
3939
.ignoresSafeArea(.keyboard, edges: .bottom)
4040
} label: {
41-
SampleRow(
42-
name: sample.name.boldingFirstOccurrence(of: textToBold),
43-
description: sample.description.boldingFirstOccurrence(of: textToBold)
44-
)
41+
SampleRow(sample, textToBold: textToBold)
4542
}
4643
}
4744
}
4845

4946
private extension SampleLink {
5047
struct SampleRow: View {
51-
/// The name of the sample.
52-
private let name: String
48+
/// The sample for the row.
49+
private let sample: Sample
5350

5451
/// The name of the sample with attributes.
5552
private let attributedName: AttributedString
@@ -63,15 +60,10 @@ private extension SampleLink {
6360
/// The names of the favorite samples loaded from user defaults.
6461
@AppFavorites private var favoriteNames
6562

66-
/// A Boolean value indicating whether the sample is a favorite.
67-
private var sampleIsFavorite: Bool {
68-
favoriteNames.contains(name)
69-
}
70-
71-
init(name: AttributedString, description: AttributedString) {
72-
self.name = String(name.characters)
73-
self.attributedName = name
74-
self.attributedDescription = description
63+
init(_ sample: Sample, textToBold: String) {
64+
self.sample = sample
65+
self.attributedName = sample.name.boldingFirstOccurrence(of: textToBold)
66+
self.attributedDescription = sample.description.boldingFirstOccurrence(of: textToBold)
7567
}
7668

7769
var body: some View {
@@ -88,7 +80,7 @@ private extension SampleLink {
8880
}
8981
Spacer()
9082

91-
if sampleIsFavorite {
83+
if favoriteNames.contains(sample.name) {
9284
Image(systemName: "star.fill")
9385
.foregroundStyle(.yellow)
9486
}
@@ -103,16 +95,7 @@ private extension SampleLink {
10395
}
10496
}
10597
.contextMenu {
106-
Button {
107-
if sampleIsFavorite {
108-
favoriteNames.removeAll { $0 == name }
109-
} else {
110-
favoriteNames.append(name)
111-
}
112-
} label: {
113-
Label(sampleIsFavorite ? "Unfavorite" : "Favorite", systemImage: "star")
114-
.symbolVariant(sampleIsFavorite ? .slash : .none)
115-
}
98+
SampleMenuButtons(sample: sample)
11699
}
117100
.animation(.easeOut(duration: 0.2), value: isShowingDescription)
118101
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2024 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+
import SwiftUI
16+
17+
struct SampleMenuButtons: View {
18+
/// The sample to show the menu buttons for.
19+
let sample: Sample
20+
21+
/// The names of the favorite samples loaded from user defaults.
22+
@AppFavorites private var favoriteNames
23+
24+
/// A Boolean value indicating whether the sample is a favorite.
25+
private var sampleIsFavorite: Bool {
26+
favoriteNames.contains(sample.name)
27+
}
28+
29+
var body: some View {
30+
Link(destination: sample.esriDeveloperURL) {
31+
Label("View on Esri Developer", systemImage: "link")
32+
}
33+
Link(destination: sample.gitHubURL) {
34+
Label("View on GitHub", systemImage: "link")
35+
}
36+
Divider()
37+
Button {
38+
if sampleIsFavorite {
39+
favoriteNames.removeAll(where: { $0 == sample.name })
40+
} else {
41+
favoriteNames.append(sample.name)
42+
}
43+
} label: {
44+
Label(sampleIsFavorite ? "Unfavorite" : "Favorite", systemImage: "star")
45+
.symbolVariant(sampleIsFavorite ? .slash : .none)
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)