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

View file

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

View file

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

View file

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

View file

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