mirror of
https://github.com/yattee/yattee.git
synced 2025-08-06 18:54:11 +00:00
Multiplatform UI support fixes
This commit is contained in:
58
Shared/AppSidebarNavigation.swift
Normal file
58
Shared/AppSidebarNavigation.swift
Normal file
@@ -0,0 +1,58 @@
|
||||
import SwiftUI
|
||||
#if os(iOS)
|
||||
import Introspect
|
||||
#endif
|
||||
|
||||
struct AppSidebarNavigation: View {
|
||||
@EnvironmentObject<NavigationState> private var navigationState
|
||||
|
||||
@State private var didApplyPrimaryViewWorkAround = false
|
||||
|
||||
var body: some View {
|
||||
#if os(iOS)
|
||||
content.introspectViewController { viewController in
|
||||
// workaround for an empty supplementary view on launch
|
||||
// the supplementary view is determined by the default selection inside the
|
||||
// primary view, but the primary view is not loaded so its selection is not read
|
||||
// We work around that by briefly showing the primary view.
|
||||
if !didApplyPrimaryViewWorkAround, let splitVC = viewController.children.first as? UISplitViewController {
|
||||
UIView.performWithoutAnimation {
|
||||
splitVC.show(.primary)
|
||||
splitVC.hide(.primary)
|
||||
}
|
||||
didApplyPrimaryViewWorkAround = true
|
||||
}
|
||||
}
|
||||
#else
|
||||
content
|
||||
#endif
|
||||
}
|
||||
|
||||
var content: some View {
|
||||
NavigationView {
|
||||
sidebar
|
||||
|
||||
Text("Select section")
|
||||
.frame(maxWidth: 600)
|
||||
Text("Select video")
|
||||
}
|
||||
}
|
||||
|
||||
var sidebar: some View {
|
||||
List {
|
||||
NavigationLink(tag: TabSelection.subscriptions, selection: navigationState.tabSelectionOptionalBinding) {
|
||||
SubscriptionsView()
|
||||
}
|
||||
label: {
|
||||
Label("Subscriptions", systemImage: "star")
|
||||
}
|
||||
|
||||
NavigationLink(tag: TabSelection.popular, selection: navigationState.tabSelectionOptionalBinding) {
|
||||
PopularVideosView()
|
||||
}
|
||||
label: {
|
||||
Label("Popular", systemImage: "chart.bar")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,56 +1,26 @@
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct ContentView: View {
|
||||
@Default(.openChannel) var channel
|
||||
@Default(.showingVideoDetails) var showDetails
|
||||
@StateObject private var navigationState = NavigationState()
|
||||
|
||||
@State private var showingOptions = false
|
||||
#if os(iOS)
|
||||
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
|
||||
#endif
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
TabView(selection: tabSelection) {
|
||||
SubscriptionsView()
|
||||
.tabItem { Text("Subscriptions") }
|
||||
.tag(TabSelection.subscriptions)
|
||||
|
||||
PopularVideosView()
|
||||
.tabItem { Text("Popular") }
|
||||
.tag(TabSelection.popular)
|
||||
|
||||
if channel != nil {
|
||||
ChannelView(id: channel!.id)
|
||||
.tabItem { Text("\(channel!.name) Channel") }
|
||||
.tag(TabSelection.channel)
|
||||
Section {
|
||||
#if os(iOS)
|
||||
if horizontalSizeClass == .compact {
|
||||
AppTabNavigation()
|
||||
} else {
|
||||
AppSidebarNavigation()
|
||||
}
|
||||
|
||||
TrendingView()
|
||||
.tabItem { Text("Trending") }
|
||||
.tag(TabSelection.trending)
|
||||
|
||||
PlaylistsView()
|
||||
.tabItem { Text("Playlists") }
|
||||
.tag(TabSelection.playlists)
|
||||
|
||||
SearchView()
|
||||
.tabItem { Image(systemName: "magnifyingglass") }
|
||||
.tag(TabSelection.search)
|
||||
}
|
||||
.fullScreenCover(isPresented: $showingOptions) { OptionsView() }
|
||||
.onPlayPauseCommand { showingOptions.toggle() }
|
||||
.background(videoDetailsViewNavigationLink)
|
||||
}
|
||||
}
|
||||
|
||||
var tabSelection: Binding<TabSelection> {
|
||||
Binding(
|
||||
get: { Defaults[.tabSelection] },
|
||||
set: { Defaults[.tabSelection] = $0 }
|
||||
)
|
||||
}
|
||||
|
||||
var videoDetailsViewNavigationLink: some View {
|
||||
NavigationLink("", destination: VideoDetailsView(), isActive: $showDetails).hidden()
|
||||
#elseif os(macOS)
|
||||
AppSidebarNavigation()
|
||||
#elseif os(tvOS)
|
||||
TVNavigationView()
|
||||
#endif
|
||||
}.environmentObject(navigationState)
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2,15 +2,11 @@ import Defaults
|
||||
|
||||
extension Defaults.Keys {
|
||||
static let layout = Key<ListingLayout>("listingLayout", default: .cells)
|
||||
static let tabSelection = Key<TabSelection>("tabSelection", default: .subscriptions)
|
||||
static let searchQuery = Key<String>("searchQuery", default: "")
|
||||
static let openChannel = Key<Channel?>("openChannel")
|
||||
|
||||
static let searchSortOrder = Key<SearchSortOrder>("searchSortOrder", default: .relevance)
|
||||
static let searchDate = Key<SearchDate?>("searchDate")
|
||||
static let searchDuration = Key<SearchDuration?>("searchDuration")
|
||||
static let openVideoID = Key<String>("videoID", default: "")
|
||||
static let showingVideoDetails = Key<Bool>("showingVideoDetails", default: false)
|
||||
|
||||
static let selectedPlaylistID = Key<String?>("selectedPlaylistID")
|
||||
static let showingAddToPlaylist = Key<Bool>("showingAddToPlaylist", default: false)
|
||||
|
10
Shared/Pearvidious.entitlements
Normal file
10
Shared/Pearvidious.entitlements
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.app-sandbox</key>
|
||||
<true/>
|
||||
<key>com.apple.security.network.client</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
Reference in New Issue
Block a user