Add Defaults library

This commit is contained in:
Arkadiusz Fal
2021-06-27 01:29:55 +02:00
parent 15bfaf7497
commit 7c4eee4a44
19 changed files with 125 additions and 111 deletions

View File

@@ -1,37 +1,38 @@
import Defaults
import SwiftUI
struct ContentView: View {
@ObservedObject private var state = AppState()
@ObservedObject private var profile = Profile()
@SceneStorage("tabSelection") var tabSelection = TabSelection.subscriptions
@Default(.tabSelection) var tabSelection
var body: some View {
NavigationView {
TabView(selection: $tabSelection) {
SubscriptionsView(tabSelection: $tabSelection)
SubscriptionsView()
.tabItem { Text("Subscriptions") }
.tag(TabSelection.subscriptions)
PopularVideosView(tabSelection: $tabSelection)
PopularVideosView()
.tabItem { Text("Popular") }
.tag(TabSelection.popular)
if state.showingChannel {
ChannelView(tabSelection: $tabSelection)
ChannelView()
.tabItem { Text("\(state.channel) Channel") }
.tag(TabSelection.channel)
}
TrendingView(tabSelection: $tabSelection)
TrendingView()
.tabItem { Text("Trending") }
.tag(TabSelection.trending)
PlaylistsView(tabSelection: $tabSelection)
PlaylistsView()
.tabItem { Text("Playlists") }
.tag(TabSelection.playlists)
SearchView(tabSelection: $tabSelection)
SearchView()
.tabItem { Image(systemName: "magnifyingglass") }
.tag(TabSelection.search)
}

6
Shared/Defaults.swift Normal file
View File

@@ -0,0 +1,6 @@
import Defaults
extension Defaults.Keys {
static let layout = Key<ListingLayout>("listingLayout", default: .cells)
static let tabSelection = Key<TabSelection>("tabSelection", default: .subscriptions)
}

View File

@@ -0,0 +1,14 @@
import Defaults
enum ListingLayout: String, CaseIterable, Defaults.Serializable {
case list, cells
var name: String {
switch self {
case .list:
return "List"
case .cells:
return "Cells"
}
}
}

View File

@@ -1,5 +1,6 @@
import Defaults
import Foundation
enum TabSelection: String {
enum TabSelection: String, DefaultsSerializable {
case subscriptions, popular, trending, playlists, channel, search
}