Add a new custom Post tab for the tabbar

This commit is contained in:
Thomas Ricouard 2024-01-05 08:36:06 +01:00
parent c0a78ef007
commit 6bb6a02912
5 changed files with 18 additions and 5 deletions

View file

@ -22,7 +22,7 @@ struct AppView: View {
@Binding var selectedTab: Tab
@Binding var sidebarRouterPath: RouterPath
@Binding var appRouterPath: RouterPath
@State var popToRootTab: Tab = .other
@State var iosTabs = iOSTabs.shared
@ -46,6 +46,10 @@ struct AppView: View {
TabView(selection: .init(get: {
selectedTab
}, set: { newTab in
if newTab == .post {
appRouterPath.presentedSheet = .newStatusEditor(visibility: userPreferences.postVisibility)
return
}
if newTab == selectedTab {
/// Stupid hack to trigger onChange binding in tab views.
popToRootTab = .other
@ -74,6 +78,7 @@ struct AppView: View {
}
}
.id(appAccountsManager.currentClient.id)
.withSheetDestinations(sheetDestinations: $appRouterPath.presentedSheet)
}
private func badgeFor(tab: Tab) -> Int {
@ -115,7 +120,7 @@ struct AppView: View {
}
}
}
.environment(sidebarRouterPath)
.environment(appRouterPath)
}
var notificationsSecondaryColumn: some View {

View file

@ -13,7 +13,7 @@ extension IceCubesApp {
#if targetEnvironment(macCatalyst)
openWindow(value: WindowDestinationEditor.newStatusEditor(visibility: userPreferences.postVisibility))
#else
sidebarRouterPath.presentedSheet = .newStatusEditor(visibility: userPreferences.postVisibility)
appRouterPath.presentedSheet = .newStatusEditor(visibility: userPreferences.postVisibility)
#endif
}
.keyboardShortcut("n", modifiers: .command)

View file

@ -6,7 +6,7 @@ import SwiftUI
extension IceCubesApp {
var appScene: some Scene {
WindowGroup(id: "MainWindow") {
AppView(selectedTab: $selectedTab, sidebarRouterPath: $sidebarRouterPath)
AppView(selectedTab: $selectedTab, appRouterPath: $appRouterPath)
.applyTheme(theme)
.onAppear {
setNewClientsInEnv(client: appAccountsManager.currentClient)

View file

@ -28,7 +28,7 @@ struct IceCubesApp: App {
@State var theme = Theme.shared
@State var selectedTab: Tab = .timeline
@State var sidebarRouterPath = RouterPath()
@State var appRouterPath = RouterPath()
@State var isSupporter: Bool = false

View file

@ -12,6 +12,7 @@ enum Tab: Int, Identifiable, Hashable, CaseIterable {
case profile
case bookmarks
case favorites
case post
nonisolated var id: Int {
rawValue
@ -63,6 +64,8 @@ enum Tab: Int, Identifiable, Hashable, CaseIterable {
NavigationTab {
AccountStatusesListView(mode: .favorites)
}
case .post:
VStack { }
case .other:
EmptyView()
}
@ -95,8 +98,11 @@ enum Tab: Int, Identifiable, Hashable, CaseIterable {
Label("accessibility.tabs.profile.picker.bookmarks", systemImage: iconName)
case .favorites:
Label("accessibility.tabs.profile.picker.favorites", systemImage: iconName)
case .post:
Label("menu.new-post", systemImage: iconName)
case .other:
EmptyView()
}
}
@ -126,6 +132,8 @@ enum Tab: Int, Identifiable, Hashable, CaseIterable {
"bookmark"
case .favorites:
"star"
case .post:
"square.and.pencil"
case .other:
""
}