Skip to content

Commit bb50b83

Browse files
authored
Merge pull request #28 from harlanhaskins/harlan/visions-of-sugarplums
Fix build on visionOS
2 parents bbab569 + f89fdd6 commit bb50b83

File tree

6 files changed

+49
-5
lines changed

6 files changed

+49
-5
lines changed

Examples/Example.xcodeproj/project.pbxproj

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,11 @@
401401
MARKETING_VERSION = 1.0;
402402
PRODUCT_BUNDLE_IDENTIFIER = dk.shape.Spices.SwiftUIExample;
403403
PRODUCT_NAME = "$(TARGET_NAME)";
404+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
405+
SUPPORTS_MACCATALYST = NO;
406+
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
404407
SWIFT_EMIT_LOC_STRINGS = YES;
405-
TARGETED_DEVICE_FAMILY = "1,2";
408+
TARGETED_DEVICE_FAMILY = "1,2,7";
406409
};
407410
name = Debug;
408411
};
@@ -430,8 +433,11 @@
430433
MARKETING_VERSION = 1.0;
431434
PRODUCT_BUNDLE_IDENTIFIER = dk.shape.Spices.SwiftUIExample;
432435
PRODUCT_NAME = "$(TARGET_NAME)";
436+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
437+
SUPPORTS_MACCATALYST = NO;
438+
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
433439
SWIFT_EMIT_LOC_STRINGS = YES;
434-
TARGETED_DEVICE_FAMILY = "1,2";
440+
TARGETED_DEVICE_FAMILY = "1,2,7";
435441
};
436442
name = Release;
437443
};
@@ -457,8 +463,11 @@
457463
MARKETING_VERSION = 1.0;
458464
PRODUCT_BUNDLE_IDENTIFIER = dk.shape.Spices.UIKitExample;
459465
PRODUCT_NAME = "$(TARGET_NAME)";
466+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
467+
SUPPORTS_MACCATALYST = NO;
468+
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
460469
SWIFT_EMIT_LOC_STRINGS = YES;
461-
TARGETED_DEVICE_FAMILY = "1,2";
470+
TARGETED_DEVICE_FAMILY = "1,2,7";
462471
};
463472
name = Debug;
464473
};
@@ -484,8 +493,11 @@
484493
MARKETING_VERSION = 1.0;
485494
PRODUCT_BUNDLE_IDENTIFIER = dk.shape.Spices.UIKitExample;
486495
PRODUCT_NAME = "$(TARGET_NAME)";
496+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
497+
SUPPORTS_MACCATALYST = NO;
498+
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
487499
SWIFT_EMIT_LOC_STRINGS = YES;
488-
TARGETED_DEVICE_FAMILY = "1,2";
500+
TARGETED_DEVICE_FAMILY = "1,2,7";
489501
};
490502
name = Release;
491503
};

Examples/SwiftUIExample/ContentView.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SwiftUI
33

44
struct ContentView: View {
55
@EnvironmentObject private var spiceStore: AppSpiceStore
6+
@State private var isShowingEditorPopover = false
67

78
var body: some View {
89
NavigationStack {
@@ -46,6 +47,18 @@ struct ContentView: View {
4647
}
4748
}
4849
.navigationTitle("Example")
50+
.toolbar {
51+
#if os(visionOS)
52+
ToolbarItem(placement: .topBarTrailing) {
53+
Button("Edit spices") {
54+
isShowingEditorPopover = true
55+
}
56+
.popover(isPresented: $isShowingEditorPopover) {
57+
SpiceEditor(editing: spiceStore)
58+
}
59+
}
60+
#endif
61+
}
4962
}
5063
#if DEBUG
5164
.presentSpiceEditorOnShake(editing: spiceStore)

Examples/UIKitExample/ContentViewController.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ final class ContentViewController: UIViewController {
6565
this.translatesAutoresizingMaskIntoConstraints = false
6666
return this
6767
}()
68+
private lazy var editSpicesItem = UIBarButtonItem(title: "Edit spices", style: .plain, target: self, action: #selector(editSpicesButtonPressed))
6869

6970
override func loadView() {
7071
view = tableView
@@ -77,6 +78,7 @@ final class ContentViewController: UIViewController {
7778
setupDataSource()
7879
updateSnapshot()
7980
observeSpices()
81+
updateNavigationItem()
8082
}
8183
}
8284

@@ -146,6 +148,19 @@ private extension ContentViewController {
146148
}
147149
.store(in: &cancellables)
148150
}
151+
152+
private func updateNavigationItem() {
153+
#if os(visionOS)
154+
navigationItem.rightBarButtonItem = editSpicesItem
155+
#endif
156+
}
157+
158+
@objc private func editSpicesButtonPressed() {
159+
let editor = SpiceEditorViewController(editing: spiceStore)
160+
editor.modalPresentationStyle = .popover
161+
editor.popoverPresentationController?.sourceItem = editSpicesItem
162+
present(editor, animated: true)
163+
}
149164
}
150165

151166
extension ContentViewController: UITableViewDelegate {

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import PackageDescription
55

66
let package = Package(
77
name: "Spices",
8-
platforms: [.iOS(.v15)],
8+
platforms: [.iOS(.v15), .visionOS(.v1)],
99
products: [
1010
.library(name: "Spices", targets: ["Spices"])
1111
],

Sources/Spices/SpiceEditorViewController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ public final class SpiceEditorViewController: UIHostingController<SpiceEditor> {
3737

3838
private extension SpiceEditorViewController {
3939
private func configureSheetPresentation() {
40+
#if !os(visionOS)
4041
sheetPresentationController?.detents = [.medium(), .large()]
42+
#endif
4143
}
4244
}
4345
#endif

Sources/Spices/View+SpiceEditor.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ private struct PresentSpiceEditorOnShakeViewModifier<Editor: View>: ViewModifier
9191
return
9292
}
9393
let viewController = UIHostingController(rootView: editor)
94+
#if !os(visionOS)
9495
viewController.sheetPresentationController?.detents = [.medium(), .large()]
96+
#endif
9597
window.rootViewController?.shp_topViewController.present(viewController, animated: true)
9698
PresentedSpiceEditorBox.viewController = viewController
9799
}

0 commit comments

Comments
 (0)