Views refactoring
This commit is contained in:
parent
fcbde22dc9
commit
aca8cf3ecd
|
@ -84,6 +84,7 @@
|
|||
F86B7221296C49A300EE59EC /* EmptyButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86B7220296C49A300EE59EC /* EmptyButtonStyle.swift */; };
|
||||
F86BC9E929EBBB67009415EC /* ImageSaver.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86BC9E829EBBB66009415EC /* ImageSaver.swift */; };
|
||||
F86BC9EB29EBDA2E009415EC /* ActivityView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F86BC9EA29EBDA2E009415EC /* ActivityView.swift */; };
|
||||
F870EE5229F1645C00A2D43B /* MainNavigationOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F870EE5129F1645C00A2D43B /* MainNavigationOptions.swift */; };
|
||||
F871F21D29EF0D7000A351EF /* NavigationMenuItemDetails.swift in Sources */ = {isa = PBXBuildFile; fileRef = F871F21C29EF0D7000A351EF /* NavigationMenuItemDetails.swift */; };
|
||||
F8742FC429990AFB00E9642B /* ClientError.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8742FC329990AFB00E9642B /* ClientError.swift */; };
|
||||
F8764187298ABB520057D362 /* ViewState.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8764186298ABB520057D362 /* ViewState.swift */; };
|
||||
|
@ -178,7 +179,7 @@
|
|||
F8F6E44D29BCC1F90004795E /* MediumWidgetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8F6E44829BCC0F00004795E /* MediumWidgetView.swift */; };
|
||||
F8F6E44E29BCC1FB0004795E /* LargeWidgetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8F6E44A29BCC0FF0004795E /* LargeWidgetView.swift */; };
|
||||
F8F6E45129BCE9190004795E /* UIImage+Resize.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8F6E45029BCE9190004795E /* UIImage+Resize.swift */; };
|
||||
F8FB8ABA29EB2ED400342C04 /* NavigationMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8FB8AB929EB2ED400342C04 /* NavigationMenu.swift */; };
|
||||
F8FB8ABA29EB2ED400342C04 /* NavigationMenuButtons.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8FB8AB929EB2ED400342C04 /* NavigationMenuButtons.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
|
@ -278,6 +279,7 @@
|
|||
F86B7220296C49A300EE59EC /* EmptyButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyButtonStyle.swift; sourceTree = "<group>"; };
|
||||
F86BC9E829EBBB66009415EC /* ImageSaver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageSaver.swift; sourceTree = "<group>"; };
|
||||
F86BC9EA29EBDA2E009415EC /* ActivityView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityView.swift; sourceTree = "<group>"; };
|
||||
F870EE5129F1645C00A2D43B /* MainNavigationOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainNavigationOptions.swift; sourceTree = "<group>"; };
|
||||
F871F21C29EF0D7000A351EF /* NavigationMenuItemDetails.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationMenuItemDetails.swift; sourceTree = "<group>"; };
|
||||
F871F21F29EF0FEC00A351EF /* Vernissage-011.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Vernissage-011.xcdatamodel"; sourceTree = "<group>"; };
|
||||
F8742FC329990AFB00E9642B /* ClientError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientError.swift; sourceTree = "<group>"; };
|
||||
|
@ -364,7 +366,7 @@
|
|||
F8F6E44829BCC0F00004795E /* MediumWidgetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediumWidgetView.swift; sourceTree = "<group>"; };
|
||||
F8F6E44A29BCC0FF0004795E /* LargeWidgetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LargeWidgetView.swift; sourceTree = "<group>"; };
|
||||
F8F6E45029BCE9190004795E /* UIImage+Resize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Resize.swift"; sourceTree = "<group>"; };
|
||||
F8FB8AB929EB2ED400342C04 /* NavigationMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationMenu.swift; sourceTree = "<group>"; };
|
||||
F8FB8AB929EB2ED400342C04 /* NavigationMenuButtons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationMenuButtons.swift; sourceTree = "<group>"; };
|
||||
F8FFBD4929E99BEE0047EE80 /* Vernissage-009.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Vernissage-009.xcdatamodel"; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
|
@ -540,6 +542,7 @@
|
|||
F88AB05429B3626300345EDE /* ImageGrid.swift */,
|
||||
F8AFF7C329B25EF40087D083 /* ImagesGrid.swift */,
|
||||
F89D6C49297196FF001DA3D4 /* ImageViewer.swift */,
|
||||
F870EE5129F1645C00A2D43B /* MainNavigationOptions.swift */,
|
||||
);
|
||||
path = Widgets;
|
||||
sourceTree = "<group>";
|
||||
|
@ -645,7 +648,7 @@
|
|||
F88BC53729E068D200CE6141 /* ViewModifiers */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
F8FB8AB929EB2ED400342C04 /* NavigationMenu.swift */,
|
||||
F8FB8AB929EB2ED400342C04 /* NavigationMenuButtons.swift */,
|
||||
F88BC53A29E06A5100CE6141 /* ImageContextMenu.swift */,
|
||||
);
|
||||
path = ViewModifiers;
|
||||
|
@ -1112,6 +1115,7 @@
|
|||
F876418D298AE5020057D362 /* PaginableStatusesView.swift in Sources */,
|
||||
F85D49852964301800751DF7 /* StatusData+Attachments.swift in Sources */,
|
||||
F8764187298ABB520057D362 /* ViewState.swift in Sources */,
|
||||
F870EE5229F1645C00A2D43B /* MainNavigationOptions.swift in Sources */,
|
||||
F88ABD9429687CA4004EF61E /* ComposeView.swift in Sources */,
|
||||
F89CEB802984198600A1376F /* AttachmentData+HighestImage.swift in Sources */,
|
||||
F86B7214296BFDCE00EE59EC /* UserProfileHeaderView.swift in Sources */,
|
||||
|
@ -1123,7 +1127,7 @@
|
|||
F8D5444329D4066C002225D6 /* AppDelegate.swift in Sources */,
|
||||
F802884F297AEED5000BDD51 /* DatabaseError.swift in Sources */,
|
||||
F86A4307299AA5E900DF7645 /* ThanksView.swift in Sources */,
|
||||
F8FB8ABA29EB2ED400342C04 /* NavigationMenu.swift in Sources */,
|
||||
F8FB8ABA29EB2ED400342C04 /* NavigationMenuButtons.swift in Sources */,
|
||||
F88BC51D29E0377B00CE6141 /* AccountData+AccountModel.swift in Sources */,
|
||||
F89B5CC229D01BF700549F2F /* InstanceView.swift in Sources */,
|
||||
F89F57B029D1C11200001EE3 /* RelationshipModel.swift in Sources */,
|
||||
|
|
|
@ -5,18 +5,25 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
class NavigationMenuItemDetails: ObservableObject, Identifiable {
|
||||
let id: Int32
|
||||
|
||||
@Published var viewMode: MainView.ViewMode
|
||||
@Published var title: String
|
||||
@Published var viewMode: MainView.ViewMode {
|
||||
didSet {
|
||||
self.title = viewMode.title
|
||||
self.image = viewMode.image
|
||||
}
|
||||
}
|
||||
|
||||
@Published var title: LocalizedStringKey
|
||||
@Published var image: String
|
||||
|
||||
init(id: Int32, viewMode: MainView.ViewMode, title: String, image: String) {
|
||||
init(id: Int32, viewMode: MainView.ViewMode) {
|
||||
self.id = id
|
||||
self.viewMode = viewMode
|
||||
self.title = title
|
||||
self.image = image
|
||||
self.title = viewMode.title
|
||||
self.image = viewMode.image
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,39 +10,36 @@ import EnvironmentKit
|
|||
import ServicesKit
|
||||
|
||||
extension View {
|
||||
func navigationMenu<MenuItems>(menuPosition: Binding<MenuPosition>,
|
||||
onViewModeIconTap: @escaping (MainView.ViewMode) -> Void,
|
||||
@ViewBuilder menuItems: @escaping () -> MenuItems) -> some View where MenuItems: View {
|
||||
modifier(NavigationMenu(menuPosition: menuPosition, onViewModeIconTap: onViewModeIconTap, menuItems: menuItems))
|
||||
func navigationMenuButtons(menuPosition: Binding<MenuPosition>,
|
||||
onViewModeIconTap: @escaping (MainView.ViewMode) -> Void) -> some View {
|
||||
modifier(NavigationMenuButtons(menuPosition: menuPosition, onViewModeIconTap: onViewModeIconTap))
|
||||
}
|
||||
}
|
||||
|
||||
private struct NavigationMenu<MenuItems>: ViewModifier where MenuItems: View {
|
||||
private struct NavigationMenuButtons: ViewModifier {
|
||||
@EnvironmentObject var routerPath: RouterPath
|
||||
|
||||
private let menuItems: () -> MenuItems
|
||||
private let onViewModeIconTap: (MainView.ViewMode) -> Void
|
||||
private let imageFontSize = 20.0
|
||||
|
||||
private let customMenuItems = [
|
||||
NavigationMenuItemDetails(id: 1, viewMode: .home, title: "mainview.tab.homeTimeline", image: "house"),
|
||||
NavigationMenuItemDetails(id: 2, viewMode: .local, title: "mainview.tab.localTimeline", image: "building"),
|
||||
NavigationMenuItemDetails(id: 3, viewMode: .federated, title: "mainview.tab.federatedTimeline", image: "globe.europe.africa"),
|
||||
NavigationMenuItemDetails(id: 4, viewMode: .search, title: "mainview.tab.search", image: "magnifyingglass"),
|
||||
NavigationMenuItemDetails(id: 5, viewMode: .profile, title: "mainview.tab.userProfile", image: "person.crop.circle"),
|
||||
NavigationMenuItemDetails(id: 6, viewMode: .notifications, title: "mainview.tab.notifications", image: "bell.badge")
|
||||
NavigationMenuItemDetails(id: 1, viewMode: .home),
|
||||
NavigationMenuItemDetails(id: 2, viewMode: .local),
|
||||
NavigationMenuItemDetails(id: 3, viewMode: .federated),
|
||||
NavigationMenuItemDetails(id: 4, viewMode: .search),
|
||||
NavigationMenuItemDetails(id: 5, viewMode: .profile),
|
||||
NavigationMenuItemDetails(id: 6, viewMode: .notifications)
|
||||
]
|
||||
|
||||
@State private var selectedCustomMenuItems = [
|
||||
NavigationMenuItemDetails(id: 1, viewMode: .home, title: "mainview.tab.homeTimeline", image: "house"),
|
||||
NavigationMenuItemDetails(id: 2, viewMode: .local, title: "mainview.tab.localTimeline", image: "building"),
|
||||
NavigationMenuItemDetails(id: 3, viewMode: .profile, title: "mainview.tab.userProfile", image: "person.crop.circle")
|
||||
NavigationMenuItemDetails(id: 1, viewMode: .home),
|
||||
NavigationMenuItemDetails(id: 2, viewMode: .local),
|
||||
NavigationMenuItemDetails(id: 3, viewMode: .profile)
|
||||
]
|
||||
|
||||
@Binding var menuPosition: MenuPosition
|
||||
|
||||
init(menuPosition: Binding<MenuPosition>, onViewModeIconTap: @escaping (MainView.ViewMode) -> Void, @ViewBuilder menuItems: @escaping () -> MenuItems) {
|
||||
self.menuItems = menuItems
|
||||
init(menuPosition: Binding<MenuPosition>, onViewModeIconTap: @escaping (MainView.ViewMode) -> Void) {
|
||||
self.onViewModeIconTap = onViewModeIconTap
|
||||
self._menuPosition = menuPosition
|
||||
}
|
||||
|
@ -123,7 +120,9 @@ private struct NavigationMenu<MenuItems>: ViewModifier where MenuItems: View {
|
|||
@ViewBuilder
|
||||
private func contextMenuView() -> some View {
|
||||
Menu {
|
||||
self.menuItems()
|
||||
MainNavigationOptions { viewMode in
|
||||
self.onViewModeIconTap(viewMode)
|
||||
}
|
||||
} label: {
|
||||
Image(systemName: "ellipsis")
|
||||
.font(.system(size: self.imageFontSize))
|
||||
|
@ -174,9 +173,7 @@ private struct NavigationMenu<MenuItems>: ViewModifier where MenuItems: View {
|
|||
ForEach(self.customMenuItems) { item in
|
||||
Button {
|
||||
withAnimation {
|
||||
customMenuItem.title = item.title
|
||||
customMenuItem.viewMode = item.viewMode
|
||||
customMenuItem.image = item.image
|
||||
}
|
||||
|
||||
// Saving in core data.
|
||||
|
@ -191,7 +188,7 @@ private struct NavigationMenu<MenuItems>: ViewModifier where MenuItems: View {
|
|||
break
|
||||
}
|
||||
} label: {
|
||||
Label(NSLocalizedString(item.title, comment: "Custom menu item"), systemImage: item.image)
|
||||
Label(item.title, systemImage: item.image)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,6 +16,15 @@ struct AccountsPhotoView: View {
|
|||
public enum ListType: Hashable {
|
||||
case trending
|
||||
case search(query: String)
|
||||
|
||||
public var title: LocalizedStringKey {
|
||||
switch self {
|
||||
case .trending:
|
||||
return "trendingAccounts.navigationBar.title"
|
||||
case .search:
|
||||
return "trendingAccounts.navigationBar.title"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EnvironmentObject var applicationState: ApplicationState
|
||||
|
@ -29,7 +38,7 @@ struct AccountsPhotoView: View {
|
|||
|
||||
var body: some View {
|
||||
self.mainBody()
|
||||
.navigationTitle("trendingAccounts.navigationBar.title")
|
||||
.navigationTitle(self.listType.title)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
|
|
|
@ -21,6 +21,25 @@ struct AccountsView: View {
|
|||
case blocks
|
||||
case mutes
|
||||
case search(query: String)
|
||||
|
||||
public var title: String {
|
||||
switch self {
|
||||
case .followers:
|
||||
return NSLocalizedString("accounts.navigationBar.followers", comment: "Followers")
|
||||
case .following:
|
||||
return NSLocalizedString("accounts.navigationBar.following", comment: "Following")
|
||||
case .favourited:
|
||||
return NSLocalizedString("accounts.navigationBar.favouritedBy", comment: "Favourited by")
|
||||
case .reblogged:
|
||||
return NSLocalizedString("accounts.navigationBar.reboostedBy", comment: "Reboosted by")
|
||||
case .blocks:
|
||||
return NSLocalizedString("accounts.navigationBar.blocked", comment: "Blocked")
|
||||
case .mutes:
|
||||
return NSLocalizedString("accounts.navigationBar.mutes", comment: "Mutes")
|
||||
case .search(let query):
|
||||
return query
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EnvironmentObject var applicationState: ApplicationState
|
||||
|
@ -35,7 +54,7 @@ struct AccountsView: View {
|
|||
|
||||
var body: some View {
|
||||
self.mainBody()
|
||||
.navigationTitle(self.getTitle())
|
||||
.navigationTitle(self.listType.title)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
|
@ -123,25 +142,6 @@ struct AccountsView: View {
|
|||
self.accounts.append(contentsOf: accountsFromApi)
|
||||
}
|
||||
|
||||
private func getTitle() -> String {
|
||||
switch self.listType {
|
||||
case .followers:
|
||||
return NSLocalizedString("accounts.navigationBar.followers", comment: "Followers")
|
||||
case .following:
|
||||
return NSLocalizedString("accounts.navigationBar.following", comment: "Following")
|
||||
case .favourited:
|
||||
return NSLocalizedString("accounts.navigationBar.favouritedBy", comment: "Favourited by")
|
||||
case .reblogged:
|
||||
return NSLocalizedString("accounts.navigationBar.reboostedBy", comment: "Reboosted by")
|
||||
case .blocks:
|
||||
return NSLocalizedString("accounts.navigationBar.blocked", comment: "Blocked")
|
||||
case .mutes:
|
||||
return NSLocalizedString("accounts.navigationBar.mutes", comment: "Mutes")
|
||||
case .search(let query):
|
||||
return query
|
||||
}
|
||||
}
|
||||
|
||||
private func loadFromApi(page: Int) async throws -> [Account] {
|
||||
switch self.listType {
|
||||
case .followers(let entityId):
|
||||
|
|
|
@ -16,6 +16,15 @@ struct HashtagsView: View {
|
|||
public enum ListType: Hashable {
|
||||
case trending
|
||||
case search(query: String)
|
||||
|
||||
public var title: LocalizedStringKey {
|
||||
switch self {
|
||||
case .trending:
|
||||
return "trendingTags.navigationBar.title"
|
||||
case .search:
|
||||
return "trendingTags.navigationBar.title"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EnvironmentObject var applicationState: ApplicationState
|
||||
|
@ -29,7 +38,7 @@ struct HashtagsView: View {
|
|||
|
||||
var body: some View {
|
||||
self.mainBody()
|
||||
.navigationTitle("trendingTags.navigationBar.title")
|
||||
.navigationTitle(self.listType.title)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
|
|
|
@ -20,10 +20,10 @@ struct MainView: View {
|
|||
@EnvironmentObject var routerPath: RouterPath
|
||||
@EnvironmentObject var tipsStore: TipsStore
|
||||
|
||||
@State private var navBarTitle: LocalizedStringKey = "mainview.tab.homeTimeline"
|
||||
@State private var navBarTitle: LocalizedStringKey = ViewMode.home.title
|
||||
@State private var viewMode: ViewMode = .home {
|
||||
didSet {
|
||||
self.navBarTitle = self.getViewTitle(viewMode: viewMode)
|
||||
self.navBarTitle = viewMode.title
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,15 +31,59 @@ struct MainView: View {
|
|||
|
||||
public enum ViewMode {
|
||||
case home, local, federated, profile, notifications, trendingPhotos, trendingTags, trendingAccounts, search
|
||||
|
||||
public var title: LocalizedStringKey {
|
||||
switch self {
|
||||
case .home:
|
||||
return "mainview.tab.homeTimeline"
|
||||
case .trendingPhotos:
|
||||
return "mainview.tab.trendingPhotos"
|
||||
case .trendingTags:
|
||||
return "mainview.tab.trendingTags"
|
||||
case .trendingAccounts:
|
||||
return "mainview.tab.trendingAccounts"
|
||||
case .local:
|
||||
return "mainview.tab.localTimeline"
|
||||
case .federated:
|
||||
return "mainview.tab.federatedTimeline"
|
||||
case .profile:
|
||||
return "mainview.tab.userProfile"
|
||||
case .notifications:
|
||||
return "mainview.tab.notifications"
|
||||
case .search:
|
||||
return "mainview.tab.search"
|
||||
}
|
||||
}
|
||||
|
||||
public var image: String {
|
||||
switch self {
|
||||
case .home:
|
||||
return "house"
|
||||
case .trendingPhotos:
|
||||
return "photo.stack"
|
||||
case .trendingTags:
|
||||
return "tag"
|
||||
case .trendingAccounts:
|
||||
return "person.3"
|
||||
case .local:
|
||||
return "building"
|
||||
case .federated:
|
||||
return "globe.europe.africa"
|
||||
case .profile:
|
||||
return "person.crop.circle"
|
||||
case .notifications:
|
||||
return "bell.badge"
|
||||
case .search:
|
||||
return "magnifyingglass"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
self.getMainView()
|
||||
.navigationMenu(menuPosition: $applicationState.menuPosition, onViewModeIconTap: { viewMode in
|
||||
.navigationMenuButtons(menuPosition: $applicationState.menuPosition) { viewMode in
|
||||
self.switchView(to: viewMode)
|
||||
}, menuItems: {
|
||||
self.navigationMenuContent()
|
||||
})
|
||||
}
|
||||
.navigationTitle(navBarTitle)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
|
@ -103,7 +147,9 @@ struct MainView: View {
|
|||
private func getPrincipalToolbar() -> some ToolbarContent {
|
||||
ToolbarItem(placement: .principal) {
|
||||
Menu {
|
||||
self.navigationMenuContent()
|
||||
MainNavigationOptions { viewMode in
|
||||
self.switchView(to: viewMode)
|
||||
}
|
||||
} label: {
|
||||
HStack {
|
||||
Text(navBarTitle, comment: "Navbar title")
|
||||
|
@ -165,101 +211,6 @@ struct MainView: View {
|
|||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func navigationMenuContent() -> some View {
|
||||
Button {
|
||||
self.switchView(to: .home)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(self.getViewTitle(viewMode: .home))
|
||||
Image(systemName: "house")
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
self.switchView(to: .local)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(self.getViewTitle(viewMode: .local))
|
||||
Image(systemName: "building")
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
self.switchView(to: .federated)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(self.getViewTitle(viewMode: .federated))
|
||||
Image(systemName: "globe.europe.africa")
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
self.switchView(to: .search)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(self.getViewTitle(viewMode: .search))
|
||||
Image(systemName: "magnifyingglass")
|
||||
}
|
||||
}
|
||||
|
||||
Divider()
|
||||
|
||||
Menu {
|
||||
Button {
|
||||
self.switchView(to: .trendingPhotos)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(self.getViewTitle(viewMode: .trendingPhotos))
|
||||
Image(systemName: "photo.stack")
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
self.switchView(to: .trendingTags)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(self.getViewTitle(viewMode: .trendingTags))
|
||||
Image(systemName: "tag")
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
self.switchView(to: .trendingAccounts)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(self.getViewTitle(viewMode: .trendingAccounts))
|
||||
Image(systemName: "person.3")
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
HStack {
|
||||
Text("mainview.tab.trending", comment: "Trending menu section")
|
||||
Image(systemName: "chart.line.uptrend.xyaxis")
|
||||
}
|
||||
}
|
||||
|
||||
Divider()
|
||||
|
||||
Button {
|
||||
self.switchView(to: .profile)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(self.getViewTitle(viewMode: .profile))
|
||||
Image(systemName: "person.crop.circle")
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
self.switchView(to: .notifications)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(self.getViewTitle(viewMode: .notifications))
|
||||
Image(systemName: "bell.badge")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func getAvatarImage(avatarUrl: URL?, avatarData: Data?) -> some View {
|
||||
if let avatarData,
|
||||
|
@ -286,29 +237,6 @@ struct MainView: View {
|
|||
}
|
||||
}
|
||||
|
||||
private func getViewTitle(viewMode: ViewMode) -> LocalizedStringKey {
|
||||
switch viewMode {
|
||||
case .home:
|
||||
return "mainview.tab.homeTimeline"
|
||||
case .trendingPhotos:
|
||||
return "mainview.tab.trendingPhotos"
|
||||
case .trendingTags:
|
||||
return "mainview.tab.trendingTags"
|
||||
case .trendingAccounts:
|
||||
return "mainview.tab.trendingAccounts"
|
||||
case .local:
|
||||
return "mainview.tab.localTimeline"
|
||||
case .federated:
|
||||
return "mainview.tab.federatedTimeline"
|
||||
case .profile:
|
||||
return "mainview.tab.userProfile"
|
||||
case .notifications:
|
||||
return "mainview.tab.notifications"
|
||||
case .search:
|
||||
return "mainview.tab.search"
|
||||
}
|
||||
}
|
||||
|
||||
private func switchView(to newViewMode: ViewMode) {
|
||||
HapticService.shared.fireHaptic(of: .tabSelection)
|
||||
|
||||
|
|
|
@ -15,6 +15,15 @@ struct PaginableStatusesView: View {
|
|||
public enum ListType: Hashable {
|
||||
case favourites
|
||||
case bookmarks
|
||||
|
||||
public var title: LocalizedStringKey {
|
||||
switch self {
|
||||
case .favourites:
|
||||
return "statuses.navigationBar.favourites"
|
||||
case .bookmarks:
|
||||
return "statuses.navigationBar.bookmarks"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EnvironmentObject private var applicationState: ApplicationState
|
||||
|
@ -32,7 +41,7 @@ struct PaginableStatusesView: View {
|
|||
|
||||
var body: some View {
|
||||
self.mainBody()
|
||||
.navigationTitle(self.getTitle())
|
||||
.navigationTitle(self.listType.title)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
|
@ -143,13 +152,4 @@ struct PaginableStatusesView: View {
|
|||
return try await self.client.accounts?.bookmarks(limit: self.defaultLimit, page: self.page) ?? []
|
||||
}
|
||||
}
|
||||
|
||||
private func getTitle() -> LocalizedStringKey {
|
||||
switch self.listType {
|
||||
case .favourites:
|
||||
return "statuses.navigationBar.favourites"
|
||||
case .bookmarks:
|
||||
return "statuses.navigationBar.bookmarks"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,21 @@ struct StatusesView: View {
|
|||
case favourites
|
||||
case bookmarks
|
||||
case hashtag(tag: String)
|
||||
|
||||
public var title: LocalizedStringKey {
|
||||
switch self {
|
||||
case .local:
|
||||
return "statuses.navigationBar.localTimeline"
|
||||
case .federated:
|
||||
return "statuses.navigationBar.federatedTimeline"
|
||||
case .favourites:
|
||||
return "statuses.navigationBar.favourites"
|
||||
case .bookmarks:
|
||||
return "statuses.navigationBar.bookmarks"
|
||||
case .hashtag(let tag):
|
||||
return "#\(tag)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EnvironmentObject private var applicationState: ApplicationState
|
||||
|
@ -38,7 +53,7 @@ struct StatusesView: View {
|
|||
|
||||
var body: some View {
|
||||
self.mainBody()
|
||||
.navigationTitle(self.getTitle())
|
||||
.navigationTitle(self.listType.title)
|
||||
.toolbar {
|
||||
// TODO: It seems like pixelfed is not supporting the endpoints.
|
||||
// self.getTrailingToolbar()
|
||||
|
@ -231,21 +246,6 @@ struct StatusesView: View {
|
|||
}
|
||||
}
|
||||
|
||||
private func getTitle() -> LocalizedStringKey {
|
||||
switch self.listType {
|
||||
case .local:
|
||||
return "statuses.navigationBar.localTimeline"
|
||||
case .federated:
|
||||
return "statuses.navigationBar.federatedTimeline"
|
||||
case .favourites:
|
||||
return "statuses.navigationBar.favourites"
|
||||
case .bookmarks:
|
||||
return "statuses.navigationBar.bookmarks"
|
||||
case .hashtag(let tag):
|
||||
return "#\(tag)"
|
||||
}
|
||||
}
|
||||
|
||||
@ToolbarContentBuilder
|
||||
private func getTrailingToolbar() -> some ToolbarContent {
|
||||
if case .hashtag(let hashtag) = self.listType {
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
//
|
||||
// https://mczachurski.dev
|
||||
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
||||
// Licensed under the Apache License 2.0.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct MainNavigationOptions: View {
|
||||
let onViewModeIconTap: (MainView.ViewMode) -> Void
|
||||
|
||||
var body: some View {
|
||||
Button {
|
||||
self.onViewModeIconTap(.home)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(MainView.ViewMode.home.title)
|
||||
Image(systemName: MainView.ViewMode.home.image)
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
self.onViewModeIconTap(.local)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(MainView.ViewMode.local.title)
|
||||
Image(systemName: MainView.ViewMode.local.image)
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
self.onViewModeIconTap(.federated)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(MainView.ViewMode.federated.title)
|
||||
Image(systemName: MainView.ViewMode.federated.image)
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
self.onViewModeIconTap(.search)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(MainView.ViewMode.search.title)
|
||||
Image(systemName: MainView.ViewMode.search.image)
|
||||
}
|
||||
}
|
||||
|
||||
Divider()
|
||||
|
||||
Menu {
|
||||
Button {
|
||||
self.onViewModeIconTap(.trendingPhotos)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(MainView.ViewMode.trendingPhotos.title)
|
||||
Image(systemName: MainView.ViewMode.trendingPhotos.image)
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
self.onViewModeIconTap(.trendingTags)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(MainView.ViewMode.trendingTags.title)
|
||||
Image(systemName: MainView.ViewMode.trendingTags.image)
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
self.onViewModeIconTap(.trendingAccounts)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(MainView.ViewMode.trendingAccounts.title)
|
||||
Image(systemName: MainView.ViewMode.trendingAccounts.image)
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
HStack {
|
||||
Text("mainview.tab.trending", comment: "Trending menu section")
|
||||
Image(systemName: "chart.line.uptrend.xyaxis")
|
||||
}
|
||||
}
|
||||
|
||||
Divider()
|
||||
|
||||
Button {
|
||||
self.onViewModeIconTap(.profile)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(MainView.ViewMode.profile.title)
|
||||
Image(systemName: MainView.ViewMode.profile.image)
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
self.onViewModeIconTap(.notifications)
|
||||
} label: {
|
||||
HStack {
|
||||
Text(MainView.ViewMode.notifications.title)
|
||||
Image(systemName: MainView.ViewMode.notifications.image)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue