yattee/Shared/Subscriptions/SubscriptionsView.swift

76 lines
2.1 KiB
Swift
Raw Normal View History

import Defaults
2022-12-10 02:01:59 +00:00
import SwiftUI
struct SubscriptionsView: View {
enum Page: String, CaseIterable, Defaults.Serializable {
case feed
case channels
2022-12-10 02:01:59 +00:00
}
@Default(.subscriptionsViewPage) private var subscriptionsViewPage
2022-12-10 02:01:59 +00:00
var body: some View {
2022-12-10 21:37:14 +00:00
SignInRequiredView(title: "Subscriptions".localized()) {
switch subscriptionsViewPage {
case .feed:
FeedView()
case .channels:
ChannelsView()
#if os(tvOS)
.ignoresSafeArea(.all, edges: .horizontal)
#endif
}
}
2022-12-10 02:01:59 +00:00
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
subscriptionsMenu
}
}
#endif
}
2022-12-10 20:08:03 +00:00
#if os(iOS)
var subscriptionsMenu: some View {
Menu {
Picker("Page", selection: $subscriptionsViewPage) {
Label("Feed", systemImage: "film").tag(Page.feed)
Label("Channels", systemImage: "person.3.fill").tag(Page.channels)
2022-12-10 02:01:59 +00:00
}
2022-12-11 22:15:56 +00:00
Section {
SettingsButtons()
}
} label: {
HStack(spacing: 12) {
2022-12-11 22:40:08 +00:00
menuLabel
.foregroundColor(.primary)
Image(systemName: "chevron.down.circle.fill")
.foregroundColor(.accentColor)
.imageScale(.small)
2022-12-10 02:01:59 +00:00
}
.transaction { t in t.animation = nil }
2022-12-10 02:01:59 +00:00
}
}
2022-12-11 22:40:08 +00:00
var menuLabel: some View {
HStack {
Image(systemName: subscriptionsViewPage == .channels ? "person.3.fill" : "film")
Text(subscriptionsViewPage.rawValue.capitalized.localized())
.font(.headline)
}
2022-12-10 02:01:59 +00:00
}
#endif
2022-12-10 02:01:59 +00:00
}
struct SubscriptionsView_Previews: PreviewProvider {
2022-12-10 02:01:59 +00:00
static var previews: some View {
NavigationView {
SubscriptionsView()
}
2022-12-10 02:01:59 +00:00
}
}