Skip to content

Commit 242f4c9

Browse files
authored
Add macOS platform to RTDB (#1254)
1 parent 0370bd2 commit 242f4c9

File tree

10 files changed

+316
-207
lines changed

10 files changed

+316
-207
lines changed

database/DatabaseExampleSwiftUI/DatabaseExample/DatabaseExample.xcodeproj/project.pbxproj

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
C77ABFAC26B8992600BDE919 /* PostListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C77ABFAA26B8992600BDE919 /* PostListViewModel.swift */; };
1717
C77ABFAE26B8A7FF00BDE919 /* Database+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C77ABFAD26B8A7FF00BDE919 /* Database+Extensions.swift */; };
1818
C77ABFAF26B8A7FF00BDE919 /* Database+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C77ABFAD26B8A7FF00BDE919 /* Database+Extensions.swift */; };
19+
C796F29826CCDCEF0076C5F5 /* FirebaseAuth in Frameworks */ = {isa = PBXBuildFile; productRef = C796F29726CCDCEF0076C5F5 /* FirebaseAuth */; };
20+
C796F29A26CCDCF50076C5F5 /* FirebaseDatabase in Frameworks */ = {isa = PBXBuildFile; productRef = C796F29926CCDCF50076C5F5 /* FirebaseDatabase */; };
21+
C796F29C26CCE3DA0076C5F5 /* ScreenDimensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C796F29B26CCE3DA0076C5F5 /* ScreenDimensions.swift */; };
22+
C796F29D26CCE3DA0076C5F5 /* ScreenDimensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C796F29B26CCE3DA0076C5F5 /* ScreenDimensions.swift */; };
23+
C796F29E26CCE9DE0076C5F5 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B9029EF026A10B1500C92F12 /* GoogleService-Info.plist */; };
1924
C799B60E269E1CEF00A43C40 /* PostDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C799B60D269E1CEF00A43C40 /* PostDetailView.swift */; };
2025
C799B60F269E1CEF00A43C40 /* PostDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C799B60D269E1CEF00A43C40 /* PostDetailView.swift */; };
2126
C799B611269E1E3B00A43C40 /* PostCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C799B610269E1E3B00A43C40 /* PostCell.swift */; };
@@ -39,8 +44,6 @@
3944
C7F60CF3268E352F002F68AB /* SignUpView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7F60CF1268E352F002F68AB /* SignUpView.swift */; };
4045
C7F60CF6268EBEDE002F68AB /* UserViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7F60CF5268EBEDE002F68AB /* UserViewModel.swift */; };
4146
C7F60CF7268EBEDE002F68AB /* UserViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7F60CF5268EBEDE002F68AB /* UserViewModel.swift */; };
42-
C7F60CF9268EDFC5002F68AB /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7F60CF8268EDFC5002F68AB /* LoadingView.swift */; };
43-
C7F60CFA268EDFC5002F68AB /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7F60CF8268EDFC5002F68AB /* LoadingView.swift */; };
4447
C7F60CFC268EE316002F68AB /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7F60CFB268EE316002F68AB /* ContentView.swift */; };
4548
C7F60CFD268EE316002F68AB /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7F60CFB268EE316002F68AB /* ContentView.swift */; };
4649
/* End PBXBuildFile section */
@@ -51,6 +54,7 @@
5154
C730A31E26B0998A00A29E81 /* PostsType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostsType.swift; sourceTree = "<group>"; };
5255
C77ABFAA26B8992600BDE919 /* PostListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostListViewModel.swift; sourceTree = "<group>"; };
5356
C77ABFAD26B8A7FF00BDE919 /* Database+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Database+Extensions.swift"; sourceTree = "<group>"; };
57+
C796F29B26CCE3DA0076C5F5 /* ScreenDimensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenDimensions.swift; sourceTree = "<group>"; };
5458
C799B60D269E1CEF00A43C40 /* PostDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostDetailView.swift; sourceTree = "<group>"; };
5559
C799B610269E1E3B00A43C40 /* PostCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostCell.swift; sourceTree = "<group>"; };
5660
C79D1AC226A4114600B6A169 /* PostViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostViewModel.swift; sourceTree = "<group>"; };
@@ -66,7 +70,6 @@
6670
C7C6B5B2268DAC1800546A57 /* Comment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Comment.swift; sourceTree = "<group>"; };
6771
C7F60CF1268E352F002F68AB /* SignUpView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpView.swift; sourceTree = "<group>"; };
6872
C7F60CF5268EBEDE002F68AB /* UserViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserViewModel.swift; sourceTree = "<group>"; };
69-
C7F60CF8268EDFC5002F68AB /* LoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = "<group>"; };
7073
C7F60CFB268EE316002F68AB /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
7174
/* End PBXFileReference section */
7275

@@ -85,12 +88,21 @@
8588
isa = PBXFrameworksBuildPhase;
8689
buildActionMask = 2147483647;
8790
files = (
91+
C796F29A26CCDCF50076C5F5 /* FirebaseDatabase in Frameworks */,
92+
C796F29826CCDCEF0076C5F5 /* FirebaseAuth in Frameworks */,
8893
);
8994
runOnlyForDeploymentPostprocessing = 0;
9095
};
9196
/* End PBXFrameworksBuildPhase section */
9297

9398
/* Begin PBXGroup section */
99+
C796F29626CCDCEF0076C5F5 /* Frameworks */ = {
100+
isa = PBXGroup;
101+
children = (
102+
);
103+
name = Frameworks;
104+
sourceTree = "<group>";
105+
};
94106
C7C6B56E268C8C9A00546A57 = {
95107
isa = PBXGroup;
96108
children = (
@@ -99,6 +111,7 @@
99111
C7C6B57D268C8C9C00546A57 /* iOS */,
100112
C7C6B584268C8C9C00546A57 /* macOS */,
101113
C7C6B57C268C8C9C00546A57 /* Products */,
114+
C796F29626CCDCEF0076C5F5 /* Frameworks */,
102115
);
103116
sourceTree = "<group>";
104117
};
@@ -144,7 +157,6 @@
144157
children = (
145158
C7C6B575268C8C9A00546A57 /* LoginView.swift */,
146159
C7F60CF1268E352F002F68AB /* SignUpView.swift */,
147-
C7F60CF8268EDFC5002F68AB /* LoadingView.swift */,
148160
C7F60CFB268EE316002F68AB /* ContentView.swift */,
149161
C79D1AEC26A8D9A300B6A169 /* PostsView.swift */,
150162
C70B63FE2696B29400851A91 /* NewPostsView.swift */,
@@ -163,6 +175,7 @@
163175
C730A31E26B0998A00A29E81 /* PostsType.swift */,
164176
C77ABFAA26B8992600BDE919 /* PostListViewModel.swift */,
165177
C77ABFAD26B8A7FF00BDE919 /* Database+Extensions.swift */,
178+
C796F29B26CCE3DA0076C5F5 /* ScreenDimensions.swift */,
166179
);
167180
path = Models;
168181
sourceTree = "<group>";
@@ -205,6 +218,10 @@
205218
dependencies = (
206219
);
207220
name = "DatabaseExample (macOS)";
221+
packageProductDependencies = (
222+
C796F29726CCDCEF0076C5F5 /* FirebaseAuth */,
223+
C796F29926CCDCF50076C5F5 /* FirebaseDatabase */,
224+
);
208225
productName = "DatabaseExample (macOS)";
209226
productReference = C7C6B583268C8C9C00546A57 /* DatabaseExample.app */;
210227
productType = "com.apple.product-type.application";
@@ -263,6 +280,7 @@
263280
buildActionMask = 2147483647;
264281
files = (
265282
C7C6B58C268C8C9C00546A57 /* Assets.xcassets in Resources */,
283+
C796F29E26CCE9DE0076C5F5 /* GoogleService-Info.plist in Resources */,
266284
);
267285
runOnlyForDeploymentPostprocessing = 0;
268286
};
@@ -278,12 +296,12 @@
278296
C799B611269E1E3B00A43C40 /* PostCell.swift in Sources */,
279297
C7C6B5B3268DAC1800546A57 /* Comment.swift in Sources */,
280298
C7F60CF6268EBEDE002F68AB /* UserViewModel.swift in Sources */,
299+
C796F29C26CCE3DA0076C5F5 /* ScreenDimensions.swift in Sources */,
281300
C7C6B589268C8C9C00546A57 /* LoginView.swift in Sources */,
282301
C79D1AED26A8D9A300B6A169 /* PostsView.swift in Sources */,
283302
C77ABFAE26B8A7FF00BDE919 /* Database+Extensions.swift in Sources */,
284303
C7F60CFC268EE316002F68AB /* ContentView.swift in Sources */,
285304
C799B60E269E1CEF00A43C40 /* PostDetailView.swift in Sources */,
286-
C7F60CF9268EDFC5002F68AB /* LoadingView.swift in Sources */,
287305
C70B63FF2696B29400851A91 /* NewPostsView.swift in Sources */,
288306
C7F60CF2268E352F002F68AB /* SignUpView.swift in Sources */,
289307
C7C6B587268C8C9C00546A57 /* DatabaseExampleApp.swift in Sources */,
@@ -300,12 +318,12 @@
300318
C799B612269E1E3B00A43C40 /* PostCell.swift in Sources */,
301319
C7C6B5B4268DAC1800546A57 /* Comment.swift in Sources */,
302320
C7F60CF7268EBEDE002F68AB /* UserViewModel.swift in Sources */,
321+
C796F29D26CCE3DA0076C5F5 /* ScreenDimensions.swift in Sources */,
303322
C7C6B58A268C8C9C00546A57 /* LoginView.swift in Sources */,
304323
C79D1AEE26A8D9A300B6A169 /* PostsView.swift in Sources */,
305324
C77ABFAF26B8A7FF00BDE919 /* Database+Extensions.swift in Sources */,
306325
C7F60CFD268EE316002F68AB /* ContentView.swift in Sources */,
307326
C799B60F269E1CEF00A43C40 /* PostDetailView.swift in Sources */,
308-
C7F60CFA268EDFC5002F68AB /* LoadingView.swift in Sources */,
309327
C70B64002696B29400851A91 /* NewPostsView.swift in Sources */,
310328
C7F60CF3268E352F002F68AB /* SignUpView.swift in Sources */,
311329
C7C6B588268C8C9C00546A57 /* DatabaseExampleApp.swift in Sources */,
@@ -558,6 +576,16 @@
558576
/* End XCRemoteSwiftPackageReference section */
559577

560578
/* Begin XCSwiftPackageProductDependency section */
579+
C796F29726CCDCEF0076C5F5 /* FirebaseAuth */ = {
580+
isa = XCSwiftPackageProductDependency;
581+
package = C7C6B595268C8D7800546A57 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
582+
productName = FirebaseAuth;
583+
};
584+
C796F29926CCDCF50076C5F5 /* FirebaseDatabase */ = {
585+
isa = XCSwiftPackageProductDependency;
586+
package = C7C6B595268C8D7800546A57 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
587+
productName = FirebaseDatabase;
588+
};
561589
C7C6B596268C8D7800546A57 /* FirebaseDatabaseSwift-Beta */ = {
562590
isa = XCSwiftPackageProductDependency;
563591
package = C7C6B595268C8D7800546A57 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// Copyright (c) 2021 Google Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
import SwiftUI
18+
19+
class ScreenDimensions {
20+
#if os(iOS)
21+
static var width: CGFloat = UIScreen.main.bounds.size.width
22+
static var height: CGFloat = UIScreen.main.bounds.size.height
23+
#elseif os(macOS)
24+
static var width: CGFloat = NSScreen.main?.visibleFrame.size.width ?? 0
25+
static var height: CGFloat = NSScreen.main?.visibleFrame.size.height ?? 0
26+
#endif
27+
}

database/DatabaseExampleSwiftUI/DatabaseExample/Shared/Views/ContentView.swift

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ import Firebase
1919

2020
struct ContentView: View {
2121
@AppStorage("isSignedIn") var isSignedIn = true
22-
@State private var selection: PostsType = .recentPosts
22+
23+
// define variables for creating a new post for macOS
24+
#if os(macOS)
25+
@StateObject var postList = PostListViewModel()
26+
@State private var newPostsViewPresented = false
27+
#endif
2328

2429
var body: some View {
2530
if isSignedIn {
26-
TabView(selection: $selection) {
31+
let tabView = TabView {
2732
PostsView(title: "Recents", postsType: .recentPosts)
2833
.tabItem {
2934
Label("Recents", systemImage: "arrow.counterclockwise")
@@ -38,6 +43,30 @@ struct ContentView: View {
3843
}
3944
}
4045
.accentColor(Color(.systemTeal))
46+
#if os(iOS)
47+
tabView
48+
#elseif os(macOS)
49+
tabView
50+
.toolbar {
51+
Button(action: {
52+
user.logout()
53+
}) {
54+
HStack {
55+
Image(systemName: "chevron.left")
56+
Text("Logout")
57+
}
58+
}
59+
Spacer()
60+
Button(action: {
61+
newPostsViewPresented = true
62+
}) {
63+
Image(systemName: "plus")
64+
}
65+
.sheet(isPresented: $newPostsViewPresented) {
66+
NewPostsView(postList: postList, isPresented: $newPostsViewPresented)
67+
}
68+
}
69+
#endif
4170
} else {
4271
LoginView()
4372
}

database/DatabaseExampleSwiftUI/DatabaseExample/Shared/Views/LoadingView.swift

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)