Skip to content

Commit 82571a9

Browse files
committed
Enable macOS support for demo
1 parent adc7648 commit 82571a9

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

Demo/PowerSyncExample.xcodeproj/project.pbxproj

+10-2
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@
709709
CODE_SIGN_STYLE = Automatic;
710710
CURRENT_PROJECT_VERSION = 1;
711711
DEVELOPMENT_ASSET_PATHS = "\"PowerSyncExample/Preview Content\"";
712-
DEVELOPMENT_TEAM = ZGT7463CVJ;
712+
DEVELOPMENT_TEAM = W284TED275;
713713
ENABLE_PREVIEWS = YES;
714714
ENABLE_USER_SCRIPT_SANDBOXING = NO;
715715
GENERATE_INFOPLIST_FILE = YES;
@@ -728,6 +728,10 @@
728728
OTHER_LDFLAGS = "$(inherited)";
729729
PRODUCT_BUNDLE_IDENTIFIER = com.powersync.PowerSyncSwiftExample;
730730
PRODUCT_NAME = "$(TARGET_NAME)";
731+
REGISTER_APP_GROUPS = YES;
732+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
733+
SUPPORTS_MACCATALYST = NO;
734+
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
731735
SWIFT_EMIT_LOC_STRINGS = YES;
732736
SWIFT_OBJC_BRIDGING_HEADER = "PowerSyncExample/PowerSyncExample-Bridging-Header.h";
733737
"SWIFT_OBJC_BRIDGING_HEADER[arch=*]" = "";
@@ -747,7 +751,7 @@
747751
CODE_SIGN_STYLE = Automatic;
748752
CURRENT_PROJECT_VERSION = 1;
749753
DEVELOPMENT_ASSET_PATHS = "\"PowerSyncExample/Preview Content\"";
750-
DEVELOPMENT_TEAM = ZGT7463CVJ;
754+
DEVELOPMENT_TEAM = W284TED275;
751755
ENABLE_PREVIEWS = YES;
752756
ENABLE_USER_SCRIPT_SANDBOXING = NO;
753757
GENERATE_INFOPLIST_FILE = YES;
@@ -765,6 +769,10 @@
765769
OTHER_LDFLAGS = "$(inherited)";
766770
PRODUCT_BUNDLE_IDENTIFIER = com.powersync.PowerSyncSwiftExample;
767771
PRODUCT_NAME = "$(TARGET_NAME)";
772+
REGISTER_APP_GROUPS = YES;
773+
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
774+
SUPPORTS_MACCATALYST = NO;
775+
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
768776
SWIFT_EMIT_LOC_STRINGS = YES;
769777
SWIFT_OBJC_BRIDGING_HEADER = "PowerSyncExample/PowerSyncExample-Bridging-Header.h";
770778
SWIFT_VERSION = 5.0;

Demo/PowerSyncExample/Components/TodoListRow.swift

+8
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ struct TodoListRow: View {
88
let capturePhotoTapped: () -> Void
99
let selectPhotoTapped: () -> Void
1010

11+
#if os(iOS)
1112
@State private var image: UIImage? = nil
13+
#endif
1214

1315
var body: some View {
1416
HStack {
1517
Text(todo.description)
18+
#if os(iOS)
1619
Group {
1720
if let image = image {
1821
Image(uiImage: image)
@@ -34,6 +37,7 @@ struct TodoListRow: View {
3437
EmptyView()
3538
}
3639
}
40+
#endif
3741
Spacer()
3842
VStack {
3943
if todo.photoId == nil {
@@ -69,14 +73,17 @@ struct TodoListRow: View {
6973
}
7074
.buttonStyle(.plain)
7175
}.onChange(of: todo.photoId) { _, newPhotoId in
76+
#if os(iOS)
7277
if newPhotoId == nil {
7378
// Clear the image when photoId becomes nil
7479
image = nil
7580
}
81+
#endif
7682
}
7783
}
7884
}
7985

86+
#if os(iOS)
8087
private func loadImage() async {
8188
guard let urlString = todo.photoUri else { return }
8289
let url = URL(fileURLWithPath: urlString)
@@ -92,6 +99,7 @@ struct TodoListRow: View {
9299
print("Error loading image from disk:", error)
93100
}
94101
}
102+
#endif
95103
}
96104

97105
#Preview {

Demo/PowerSyncExample/Components/TodoListView.swift

+25
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ struct TodoListView: View {
1212
@State private var newTodo: NewTodo?
1313
@State private var editing: Bool = false
1414

15+
#if os(iOS)
1516
// Called when a photo has been captured. Individual widgets should register the listener
1617
@State private var onMediaSelect: ((_: Data) async throws -> Void)?
1718
@State private var pickMediaType: UIImagePickerController.SourceType = .camera
1819
@State private var showMediaPicker = false
1920
@State private var isCameraAvailable: Bool = false
21+
#endif
2022

2123
var body: some View {
2224
List {
@@ -33,6 +35,7 @@ struct TodoListView: View {
3335
}
3436

3537
ForEach(todos) { todo in
38+
#if os(iOS)
3639
TodoListRow(
3740
todo: todo,
3841
isCameraAvailable: isCameraAvailable,
@@ -68,6 +71,20 @@ struct TodoListView: View {
6871
pickMediaType = .photoLibrary
6972
showMediaPicker = true
7073
}
74+
#else
75+
TodoListRow(
76+
todo: todo,
77+
isCameraAvailable: false,
78+
completeTapped: {
79+
Task {
80+
await toggleCompletion(of: todo)
81+
}
82+
},
83+
deletePhotoTapped: {},
84+
capturePhotoTapped: {},
85+
selectPhotoTapped: {},
86+
)
87+
#endif
7188
}
7289
.onDelete { indexSet in
7390
Task {
@@ -80,12 +97,14 @@ struct TodoListView: View {
8097
}
8198
}
8299
}
100+
#if os(iOS)
83101
.sheet(isPresented: $showMediaPicker) {
84102
CameraView(
85103
onMediaSelect: $onMediaSelect,
86104
mediaType: $pickMediaType
87105
)
88106
}
107+
#endif
89108
.animation(.default, value: todos)
90109
.navigationTitle("Todos")
91110
.toolbar {
@@ -111,9 +130,11 @@ struct TodoListView: View {
111130
}
112131
}
113132
}
133+
#if os(iOS)
114134
.onAppear {
115135
checkCameraAvailability()
116136
}
137+
#endif
117138
.task {
118139
await system.watchTodos(listId) { tds in
119140
withAnimation {
@@ -144,6 +165,7 @@ struct TodoListView: View {
144165
}
145166
}
146167

168+
#if os(iOS)
147169
/// Registers a callback which saves a photo for the specified Todo item if media is sucessfully loaded.
148170
func registerMediaCallback(todo: Todo) {
149171
// Register a callback for successful image capture
@@ -181,6 +203,7 @@ struct TodoListView: View {
181203
isCameraAvailable = UIImagePickerController.isSourceTypeAvailable(.camera)
182204
#endif
183205
}
206+
#endif
184207
}
185208

186209
#Preview {
@@ -191,6 +214,7 @@ struct TodoListView: View {
191214
}
192215
}
193216

217+
#if os(iOS)
194218
struct CameraView: UIViewControllerRepresentable {
195219
@Binding var onMediaSelect: ((_: Data) async throws -> Void)?
196220
@Binding var mediaType: UIImagePickerController.SourceType
@@ -244,3 +268,4 @@ struct CameraView: UIViewControllerRepresentable {
244268
}
245269
}
246270
}
271+
#endif

Demo/PowerSyncExample/Screens/SignInScreen.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,19 @@ struct SignInScreen: View {
1919
Form {
2020
Section {
2121
TextField("Email", text: $email)
22-
.keyboardType(.emailAddress)
2322
.textContentType(.emailAddress)
2423
.autocorrectionDisabled()
24+
#if os(iOS)
25+
.keyboardType(.emailAddress)
2526
.textInputAutocapitalization(.never)
26-
27+
#endif
28+
2729
SecureField("Password", text: $password)
2830
.textContentType(.password)
2931
.autocorrectionDisabled()
32+
#if os(iOS)
3033
.textInputAutocapitalization(.never)
34+
#endif
3135
}
3236

3337
Section {

Demo/PowerSyncExample/Screens/SignUpScreen.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ struct SignUpScreen: View {
2020
Form {
2121
Section {
2222
TextField("Email", text: $email)
23-
.keyboardType(.emailAddress)
2423
.textContentType(.emailAddress)
2524
.autocorrectionDisabled()
25+
#if os(ios)
26+
.autocorrectionDisabled()
2627
.textInputAutocapitalization(.never)
28+
#endif
2729

2830
SecureField("Password", text: $password)
2931
.textContentType(.password)
3032
.autocorrectionDisabled()
33+
#if os(ios)
3134
.textInputAutocapitalization(.never)
35+
#endif
3236
}
3337

3438
Section {

0 commit comments

Comments
 (0)