mirror of
https://github.com/yattee/yattee.git
synced 2025-01-09 06:17:10 +00:00
Add scrollbars in video details and button to scroll comments to top
Added player settings to disable scroll to top button Fix #439
This commit is contained in:
parent
55517fd44d
commit
3779b7ed1f
@ -136,6 +136,10 @@ extension Defaults.Keys {
|
|||||||
static let seekGestureSpeed = Key<Double>("seekGestureSpeed", default: 0.5)
|
static let seekGestureSpeed = Key<Double>("seekGestureSpeed", default: 0.5)
|
||||||
static let seekGestureSensitivity = Key<Double>("seekGestureSensitivity", default: 30.0)
|
static let seekGestureSensitivity = Key<Double>("seekGestureSensitivity", default: 30.0)
|
||||||
static let showKeywords = Key<Bool>("showKeywords", default: false)
|
static let showKeywords = Key<Bool>("showKeywords", default: false)
|
||||||
|
#if !os(tvOS)
|
||||||
|
static let showScrollToTopInComments = Key<Bool>("showScrollToTopInComments", default: true)
|
||||||
|
#endif
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
static let expandVideoDescriptionDefault = Constants.isIPad
|
static let expandVideoDescriptionDefault = Constants.isIPad
|
||||||
#else
|
#else
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct CommentsView: View {
|
struct CommentsView: View {
|
||||||
var embedInScrollView = false
|
|
||||||
@State private var repliesID: Comment.ID?
|
@State private var repliesID: Comment.ID?
|
||||||
|
|
||||||
@ObservedObject private var comments = CommentsModel.shared
|
@ObservedObject private var comments = CommentsModel.shared
|
||||||
@ -16,7 +15,7 @@ struct CommentsView: View {
|
|||||||
PlaceholderProgressView()
|
PlaceholderProgressView()
|
||||||
} else {
|
} else {
|
||||||
let last = comments.all.last
|
let last = comments.all.last
|
||||||
let commentsStack = LazyVStack {
|
LazyVStack {
|
||||||
ForEach(comments.all) { comment in
|
ForEach(comments.all) { comment in
|
||||||
CommentView(comment: comment, repliesID: $repliesID)
|
CommentView(comment: comment, repliesID: $repliesID)
|
||||||
.onAppear {
|
.onAppear {
|
||||||
@ -25,15 +24,6 @@ struct CommentsView: View {
|
|||||||
.borderBottom(height: comment != last ? 0.5 : 0, color: Color("ControlsBorderColor"))
|
.borderBottom(height: comment != last ? 0.5 : 0, color: Color("ControlsBorderColor"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if embedInScrollView {
|
|
||||||
ScrollView(.vertical, showsIndicators: false) {
|
|
||||||
commentsStack
|
|
||||||
Color.clear.frame(height: 50)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
commentsStack
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(.horizontal)
|
.padding(.horizontal)
|
||||||
|
@ -4,6 +4,8 @@ import SDWebImageSwiftUI
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct VideoDetails: View {
|
struct VideoDetails: View {
|
||||||
|
static let pageMenuID = "pageMenu"
|
||||||
|
|
||||||
struct TitleView: View {
|
struct TitleView: View {
|
||||||
@ObservedObject private var model = PlayerModel.shared
|
@ObservedObject private var model = PlayerModel.shared
|
||||||
@State private var titleSize = CGSize.zero
|
@State private var titleSize = CGSize.zero
|
||||||
@ -170,12 +172,15 @@ struct VideoDetails: View {
|
|||||||
@Environment(\.colorScheme) private var colorScheme
|
@Environment(\.colorScheme) private var colorScheme
|
||||||
|
|
||||||
@ObservedObject private var accounts = AccountsModel.shared
|
@ObservedObject private var accounts = AccountsModel.shared
|
||||||
let comments = CommentsModel.shared
|
@ObservedObject private var comments = CommentsModel.shared
|
||||||
@ObservedObject private var player = PlayerModel.shared
|
@ObservedObject private var player = PlayerModel.shared
|
||||||
|
|
||||||
@Default(.enableReturnYouTubeDislike) private var enableReturnYouTubeDislike
|
@Default(.enableReturnYouTubeDislike) private var enableReturnYouTubeDislike
|
||||||
@Default(.playerSidebar) private var playerSidebar
|
@Default(.playerSidebar) private var playerSidebar
|
||||||
@Default(.showInspector) private var showInspector
|
@Default(.showInspector) private var showInspector
|
||||||
|
#if !os(tvOS)
|
||||||
|
@Default(.showScrollToTopInComments) private var showScrollToTopInComments
|
||||||
|
#endif
|
||||||
@Default(.expandVideoDescription) private var expandVideoDescription
|
@Default(.expandVideoDescription) private var expandVideoDescription
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@ -211,7 +216,10 @@ struct VideoDetails: View {
|
|||||||
.animation(nil, value: player.currentItem)
|
.animation(nil, value: player.currentItem)
|
||||||
.frame(minWidth: 0, maxWidth: .infinity)
|
.frame(minWidth: 0, maxWidth: .infinity)
|
||||||
|
|
||||||
|
ScrollViewReader { proxy in
|
||||||
pageView
|
pageView
|
||||||
|
.overlay(scrollToTopButton(proxy), alignment: .bottomTrailing)
|
||||||
|
}
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
.opacity(detailsVisibility ? 1 : 0)
|
.opacity(detailsVisibility ? 1 : 0)
|
||||||
#endif
|
#endif
|
||||||
@ -266,9 +274,10 @@ struct VideoDetails: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var pageView: some View {
|
var pageView: some View {
|
||||||
ScrollView(.vertical, showsIndicators: false) {
|
ScrollView(.vertical) {
|
||||||
LazyVStack {
|
LazyVStack {
|
||||||
pageMenu
|
pageMenu
|
||||||
|
.id(Self.pageMenuID)
|
||||||
.padding(5)
|
.padding(5)
|
||||||
|
|
||||||
switch page {
|
switch page {
|
||||||
@ -319,7 +328,6 @@ struct VideoDetails: View {
|
|||||||
.padding(.top, 20)
|
.padding(.top, 20)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(.bottom, 60)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
@ -338,12 +346,13 @@ struct VideoDetails: View {
|
|||||||
.padding(.horizontal)
|
.padding(.horizontal)
|
||||||
|
|
||||||
case .comments:
|
case .comments:
|
||||||
CommentsView(embedInScrollView: false)
|
CommentsView()
|
||||||
.onAppear {
|
.onAppear {
|
||||||
comments.loadIfNeeded()
|
comments.loadIfNeeded()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.padding(.bottom, 60)
|
||||||
}
|
}
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
.onAppear {
|
.onAppear {
|
||||||
@ -365,6 +374,30 @@ struct VideoDetails: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ViewBuilder func scrollToTopButton(_ proxy: ScrollViewProxy) -> some View {
|
||||||
|
#if !os(tvOS)
|
||||||
|
if showScrollToTopInComments,
|
||||||
|
page == .comments,
|
||||||
|
comments.loaded,
|
||||||
|
comments.all.count > 3
|
||||||
|
{
|
||||||
|
Button {
|
||||||
|
withAnimation {
|
||||||
|
proxy.scrollTo(Self.pageMenuID)
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
|
Label("Scroll to top", systemImage: "arrow.up")
|
||||||
|
.padding(8)
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.background(Circle().opacity(0.8).foregroundColor(.accentColor))
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
.labelStyle(.iconOnly)
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
var descriptionHeader: some View {
|
var descriptionHeader: some View {
|
||||||
HStack {
|
HStack {
|
||||||
Text("Description".localized())
|
Text("Description".localized())
|
||||||
|
@ -8,6 +8,9 @@ struct PlayerSettings: View {
|
|||||||
@Default(.playerSidebar) private var playerSidebar
|
@Default(.playerSidebar) private var playerSidebar
|
||||||
|
|
||||||
@Default(.showKeywords) private var showKeywords
|
@Default(.showKeywords) private var showKeywords
|
||||||
|
#if !os(tvOS)
|
||||||
|
@Default(.showScrollToTopInComments) private var showScrollToTopInComments
|
||||||
|
#endif
|
||||||
@Default(.expandVideoDescription) private var expandVideoDescription
|
@Default(.expandVideoDescription) private var expandVideoDescription
|
||||||
@Default(.pauseOnHidingPlayer) private var pauseOnHidingPlayer
|
@Default(.pauseOnHidingPlayer) private var pauseOnHidingPlayer
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
@ -86,6 +89,11 @@ struct PlayerSettings: View {
|
|||||||
|
|
||||||
if !accounts.isEmpty {
|
if !accounts.isEmpty {
|
||||||
keywordsToggle
|
keywordsToggle
|
||||||
|
|
||||||
|
#if !os(tvOS)
|
||||||
|
showScrollToTopInCommentsToggle
|
||||||
|
#endif
|
||||||
|
|
||||||
#if !os(tvOS)
|
#if !os(tvOS)
|
||||||
expandVideoDescriptionToggle
|
expandVideoDescriptionToggle
|
||||||
#endif
|
#endif
|
||||||
@ -160,6 +168,12 @@ struct PlayerSettings: View {
|
|||||||
.modifier(SettingsPickerModifier())
|
.modifier(SettingsPickerModifier())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !os(tvOS)
|
||||||
|
private var showScrollToTopInCommentsToggle: some View {
|
||||||
|
Toggle("Show scroll to top button in comments", isOn: $showScrollToTopInComments)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
private var keywordsToggle: some View {
|
private var keywordsToggle: some View {
|
||||||
Toggle("Show keywords", isOn: $showKeywords)
|
Toggle("Show keywords", isOn: $showKeywords)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user