Remove legacy tvOS list layout

This commit is contained in:
Arkadiusz Fal
2021-09-27 00:28:42 +02:00
parent 994f1f9215
commit 17291b47e0
15 changed files with 27 additions and 160 deletions

View File

@@ -12,7 +12,6 @@ struct VideoView: View {
@Environment(\.horizontalCells) private var horizontalCells
var video: Video
var layout: ListingLayout
var body: some View {
Group {
@@ -26,27 +25,23 @@ struct VideoView: View {
}
}
}
.modifier(ButtonStyleModifier(layout: layout))
.buttonStyle(.plain)
.contentShape(RoundedRectangle(cornerRadius: 12))
.contextMenu { VideoContextMenuView(video: video) }
}
var content: some View {
VStack {
if layout == .cells {
#if os(iOS)
if verticalSizeClass == .compact, !horizontalCells {
horizontalRow
.padding(.vertical, 4)
} else {
verticalRow
}
#else
#if os(iOS)
if verticalSizeClass == .compact, !horizontalCells {
horizontalRow
.padding(.vertical, 4)
} else {
verticalRow
#endif
} else {
horizontalRow
}
}
#else
verticalRow
#endif
}
#if os(macOS)
.background()
@@ -222,7 +217,7 @@ struct VideoView: View {
.background(.gray)
.mask(RoundedRectangle(cornerRadius: 12))
#if os(tvOS)
.frame(minHeight: layout == .cells ? 320 : 200)
.frame(minHeight: 320)
#endif
.modifier(AspectRatioModifier())
}
@@ -248,22 +243,4 @@ struct VideoView: View {
}
}
}
struct ButtonStyleModifier: ViewModifier {
var layout: ListingLayout
func body(content: Content) -> some View {
Section {
#if os(tvOS)
if layout == .cells {
content.buttonStyle(.plain)
} else {
content
}
#else
content.buttonStyle(.plain)
#endif
}
}
}
}

View File

@@ -13,7 +13,7 @@ struct VideosCellsHorizontal: View {
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(spacing: 20) {
ForEach(videos) { video in
VideoView(video: video, layout: .cells)
VideoView(video: video)
.environment(\.horizontalCells, true)
#if os(tvOS)
.frame(width: 580)

View File

@@ -13,7 +13,7 @@ struct VideosCellsVertical: View {
ScrollView(.vertical, showsIndicators: scrollViewShowsIndicators) {
LazyVGrid(columns: items, alignment: .center) {
ForEach(videos) { video in
VideoView(video: video, layout: .cells)
VideoView(video: video)
#if os(tvOS)
.padding(.horizontal)
#endif
@@ -35,6 +35,10 @@ struct VideosCellsVertical: View {
#endif
}
.edgesIgnoringSafeArea(.horizontal)
#if os(macOS)
.background()
.frame(minWidth: 360)
#endif
}
var items: [GridItem] {
@@ -68,9 +72,9 @@ struct VideosCellsVertical: View {
}
}
struct VideoCellsView_Previews: PreviewProvider {
struct VideoCellsVertical_Previews: PreviewProvider {
static var previews: some View {
VideosView(videos: Video.allFixtures)
VideosCellsVertical(videos: Video.allFixtures)
.frame(minWidth: 1000)
.environmentObject(NavigationModel())
}

View File

@@ -1,36 +0,0 @@
import Defaults
import SwiftUI
struct VideosListView: View {
var videos: [Video]
var body: some View {
Section {
ScrollViewReader { scrollView in
List {
ForEach(videos) { video in
VideoView(video: video, layout: .list)
.listRowInsets(EdgeInsets())
}
.onChange(of: videos) { videos in
#if !os(tvOS)
guard let video = videos.first else {
return
}
scrollView.scrollTo(video.id, anchor: .top)
#endif
}
}
}
.listStyle(.grouped)
}
}
}
struct VideosListView_Previews: PreviewProvider {
static var previews: some View {
VideosListView(videos: Video.allFixtures)
}
}

View File

@@ -1,30 +0,0 @@
import Defaults
import SwiftUI
struct VideosView: View {
@EnvironmentObject<NavigationModel> private var navigation
#if os(tvOS)
@Default(.layout) private var layout
#endif
var videos: [Video]
var body: some View {
VStack {
#if os(tvOS)
if layout == .cells {
VideosCellsVertical(videos: videos)
} else {
VideosListView(videos: videos)
}
#else
VideosCellsVertical(videos: videos)
#endif
}
#if os(macOS)
.background()
.frame(minWidth: 360)
#endif
}
}