-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prep Mac app for release, fix bugs in iOS app #258
Changes from 9 commits
0608994
827f630
4a244ae
f0df99c
4f97eb5
a07443b
4dba38c
75a8f4c
c410df2
f246dd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,62 +5,86 @@ struct ContentView: View { | |
@EnvironmentObject var errorHandling: ErrorHandling | ||
|
||
var body: some View { | ||
NavigationView { | ||
#if os(macOS) | ||
CollectionListView() | ||
.withErrorHandling() | ||
.toolbar { | ||
Button( | ||
action: { | ||
NSApp.keyWindow?.contentViewController?.tryToPerform( | ||
#selector(NSSplitViewController.toggleSidebar(_:)), with: nil | ||
#if os(macOS) | ||
WFNavigation( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're essentially just wrapping these same views in our new WFNavigation view. |
||
collectionList: { | ||
CollectionListView() | ||
.withErrorHandling() | ||
.toolbar { | ||
if #available(macOS 13, *) { | ||
EmptyView() | ||
} else { | ||
Button( | ||
action: { | ||
NSApp.keyWindow?.contentViewController?.tryToPerform( | ||
#selector(NSSplitViewController.toggleSidebar(_:)), with: nil | ||
) | ||
}, | ||
label: { Image(systemName: "sidebar.left") } | ||
) | ||
}, | ||
label: { Image(systemName: "sidebar.left") } | ||
) | ||
.help("Toggle the sidebar's visibility.") | ||
Spacer() | ||
Button(action: { | ||
withAnimation { | ||
// Un-set the currently selected post | ||
self.model.selectedPost = nil | ||
.help("Toggle the sidebar's visibility.") | ||
} | ||
// Create the new-post managed object | ||
let managedPost = model.editor.generateNewLocalPost(withFont: model.preferences.font) | ||
withAnimation { | ||
DispatchQueue.main.async { | ||
// Load the new post in the editor | ||
self.model.selectedPost = managedPost | ||
Spacer() | ||
Button(action: { | ||
withAnimation { | ||
// Un-set the currently selected post | ||
self.model.selectedPost = nil | ||
} | ||
// Create the new-post managed object | ||
let managedPost = model.editor.generateNewLocalPost(withFont: model.preferences.font) | ||
withAnimation { | ||
DispatchQueue.main.async { | ||
// Load the new post in the editor | ||
self.model.selectedPost = managedPost | ||
} | ||
} | ||
}, label: { Image(systemName: "square.and.pencil") }) | ||
.help("Create a new local draft.") | ||
} | ||
.frame(width: 200) | ||
}, | ||
postList: { | ||
ZStack { | ||
PostListView(selectedCollection: model.selectedCollection, showAllPosts: model.showAllPosts) | ||
.withErrorHandling() | ||
.frame(width: 300) | ||
if model.isProcessingRequest { | ||
ZStack { | ||
Color(NSColor.controlBackgroundColor).opacity(0.75) | ||
ProgressView() | ||
} | ||
}, label: { Image(systemName: "square.and.pencil") }) | ||
.help("Create a new local draft.") | ||
} | ||
.frame(width: 200) | ||
#else | ||
CollectionListView() | ||
.withErrorHandling() | ||
#endif | ||
|
||
#if os(macOS) | ||
ZStack { | ||
PostListView(selectedCollection: model.selectedCollection, showAllPosts: model.showAllPosts) | ||
.withErrorHandling() | ||
.frame(width: 300) | ||
if model.isProcessingRequest { | ||
ZStack { | ||
Color(NSColor.controlBackgroundColor).opacity(0.75) | ||
ProgressView() | ||
} | ||
} | ||
}, | ||
postDetail: { | ||
NoSelectedPostView(isConnected: $model.hasNetworkConnection) | ||
} | ||
) | ||
.environmentObject(model) | ||
.onChange(of: model.hasError) { value in | ||
if value { | ||
if let error = model.currentError { | ||
self.errorHandling.handle(error: error) | ||
} else { | ||
self.errorHandling.handle(error: AppError.genericError()) | ||
} | ||
model.hasError = false | ||
} | ||
#else | ||
PostListView(selectedCollection: model.selectedCollection, showAllPosts: model.showAllPosts) | ||
.withErrorHandling() | ||
#endif | ||
|
||
NoSelectedPostView(isConnected: $model.hasNetworkConnection) | ||
} | ||
#else | ||
WFNavigation( | ||
collectionList: { | ||
CollectionListView() | ||
.withErrorHandling() | ||
}, | ||
postList: { | ||
PostListView(selectedCollection: model.selectedCollection, showAllPosts: model.showAllPosts) | ||
.withErrorHandling() | ||
}, | ||
postDetail: { | ||
NoSelectedPostView(isConnected: $model.hasNetworkConnection) | ||
} | ||
) | ||
.environmentObject(model) | ||
.onChange(of: model.hasError) { value in | ||
if value { | ||
|
@@ -72,6 +96,7 @@ struct ContentView: View { | |
model.hasError = false | ||
} | ||
} | ||
#endif | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import SwiftUI | ||
|
||
struct WFNavigation<CollectionList, PostList, PostDetail>: View | ||
where CollectionList: View, PostList: View, PostDetail: View { | ||
|
||
private var collectionList: CollectionList | ||
private var postList: PostList | ||
private var postDetail: PostDetail | ||
|
||
init( | ||
@ViewBuilder collectionList: () -> CollectionList, | ||
@ViewBuilder postList: () -> PostList, | ||
@ViewBuilder postDetail: () -> PostDetail | ||
) { | ||
self.collectionList = collectionList() | ||
self.postList = postList() | ||
self.postDetail = postDetail() | ||
} | ||
|
||
var body: some View { | ||
#if os(macOS) | ||
NavigationSplitView { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eventually we want to move the iOS app to use NavigationSplitView for iOS 16+ |
||
collectionList | ||
} content: { | ||
postList | ||
} detail: { | ||
postDetail | ||
} | ||
#else | ||
NavigationView { | ||
collectionList | ||
postList | ||
postDetail | ||
} | ||
#endif | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,18 +126,18 @@ struct PostListView: View { | |
.frame(height: frameHeight) | ||
.background(Color(UIColor.systemGray5)) | ||
.overlay(Divider(), alignment: .top) | ||
.onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification)) { _ in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Every time the app becomes active, this notification would fire in iOS 17 and navigate us back to the Post list view. Moving it to an |
||
// We use this to invalidate and refresh the view, so that new posts created outside of the app (e.g., | ||
// in the action extension) show up. | ||
withAnimation { | ||
self.filteredListViewId += 1 | ||
} | ||
} | ||
} | ||
.ignoresSafeArea(.all, edges: .bottom) | ||
.onAppear { | ||
// Set the selected collection and whether or not we want to show all posts | ||
model.selectedCollection = selectedCollection | ||
model.showAllPosts = showAllPosts | ||
|
||
// We use this to invalidate and refresh the view, so that new posts created outside of the app (e.g., | ||
// in the action extension) show up. | ||
withAnimation { | ||
self.filteredListViewId += 1 | ||
} | ||
} | ||
.onChange(of: model.hasError) { value in | ||
if value { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code was throwing warnings in newer versions of Xcode.