mirror of
https://github.com/yattee/yattee.git
synced 2025-12-08 00:58:15 +00:00
Refactor player controls and improve custom controls visibility
Restructured PlayerControls view hierarchy by extracting controls content into a separate computed property for better code organization. Added shouldShowCustomControls property to VideoPlayerView to properly determine when custom controls should be shown vs system controls. Updated hover logic to only show/hide custom controls when appropriate.
This commit is contained in:
@@ -57,8 +57,33 @@ struct PlayerControls: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack(alignment: .topLeading) {
|
Group {
|
||||||
if showControls {
|
if showControls {
|
||||||
|
controlsContent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onChange(of: model.presentingOverlays) { newValue in
|
||||||
|
if newValue {
|
||||||
|
model.hide()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if os(tvOS)
|
||||||
|
.onReceive(model.reporter) { value in
|
||||||
|
guard player.presentingPlayer else { return }
|
||||||
|
if value == "swipe down", !model.presentingControls, !model.presentingOverlays {
|
||||||
|
withAnimation(Self.animation) {
|
||||||
|
controlsOverlayModel.hide()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
model.show()
|
||||||
|
}
|
||||||
|
model.resetTimer()
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
var controlsContent: some View {
|
||||||
|
ZStack(alignment: .topLeading) {
|
||||||
Seek()
|
Seek()
|
||||||
.zIndex(4)
|
.zIndex(4)
|
||||||
.transition(.opacity)
|
.transition(.opacity)
|
||||||
@@ -73,7 +98,6 @@ struct PlayerControls: View {
|
|||||||
#else
|
#else
|
||||||
.offset(y: 2)
|
.offset(y: 2)
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
VStack {
|
VStack {
|
||||||
ZStack {
|
ZStack {
|
||||||
@@ -87,7 +111,6 @@ struct PlayerControls: View {
|
|||||||
}
|
}
|
||||||
.offset(y: playerControlsLayout.osdVerticalOffset + 5)
|
.offset(y: playerControlsLayout.osdVerticalOffset + 5)
|
||||||
|
|
||||||
if showControls {
|
|
||||||
Section {
|
Section {
|
||||||
#if !os(tvOS)
|
#if !os(tvOS)
|
||||||
HStack {
|
HStack {
|
||||||
@@ -190,7 +213,6 @@ struct PlayerControls: View {
|
|||||||
.opacity(model.presentingControls && !player.availableStreams.isEmpty ? 1 : 0)
|
.opacity(model.presentingControls && !player.availableStreams.isEmpty ? 1 : 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
.frame(maxWidth: .infinity)
|
.frame(maxWidth: .infinity)
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
.onChange(of: model.presentingControls) { newValue in
|
.onChange(of: model.presentingControls) { newValue in
|
||||||
@@ -215,24 +237,6 @@ struct PlayerControls: View {
|
|||||||
.frame(maxHeight: .infinity, alignment: .top)
|
.frame(maxHeight: .infinity, alignment: .top)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onChange(of: model.presentingOverlays) { newValue in
|
|
||||||
if newValue {
|
|
||||||
model.hide()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#if os(tvOS)
|
|
||||||
.onReceive(model.reporter) { value in
|
|
||||||
guard player.presentingPlayer else { return }
|
|
||||||
if value == "swipe down", !model.presentingControls, !model.presentingOverlays {
|
|
||||||
withAnimation(Self.animation) {
|
|
||||||
controlsOverlayModel.hide()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
model.show()
|
|
||||||
}
|
|
||||||
model.resetTimer()
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var detailsWidth: Double {
|
var detailsWidth: Double {
|
||||||
|
|||||||
@@ -77,6 +77,10 @@ struct VideoPlayerView: View {
|
|||||||
|
|
||||||
@ObservedObject var controlsOverlayModel = ControlOverlaysModel.shared // swiftlint:disable:this swiftui_state_private
|
@ObservedObject var controlsOverlayModel = ControlOverlaysModel.shared // swiftlint:disable:this swiftui_state_private
|
||||||
|
|
||||||
|
var shouldShowCustomControls: Bool {
|
||||||
|
player.activeBackend == .mpv || !avPlayerUsesSystemControls || player.musicMode
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack(alignment: overlayAlignment) {
|
ZStack(alignment: overlayAlignment) {
|
||||||
videoPlayer
|
videoPlayer
|
||||||
@@ -245,7 +249,7 @@ struct VideoPlayerView: View {
|
|||||||
|
|
||||||
var content: some View {
|
var content: some View {
|
||||||
Group {
|
Group {
|
||||||
ZStack(alignment: .bottomLeading) {
|
ZStack(alignment: .topLeading) {
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
ZStack {
|
ZStack {
|
||||||
player.playerBackendView
|
player.playerBackendView
|
||||||
@@ -257,6 +261,7 @@ struct VideoPlayerView: View {
|
|||||||
.ignoresSafeArea()
|
.ignoresSafeArea()
|
||||||
#else
|
#else
|
||||||
GeometryReader { geometry in
|
GeometryReader { geometry in
|
||||||
|
VStack(spacing: 0) {
|
||||||
player.playerBackendView
|
player.playerBackendView
|
||||||
.modifier(
|
.modifier(
|
||||||
VideoPlayerSizeModifier(
|
VideoPlayerSizeModifier(
|
||||||
@@ -268,18 +273,21 @@ struct VideoPlayerView: View {
|
|||||||
)
|
)
|
||||||
.onHover { hovering in
|
.onHover { hovering in
|
||||||
hoveringPlayer = hovering
|
hoveringPlayer = hovering
|
||||||
|
// Only show/hide custom controls if they should be used
|
||||||
|
if shouldShowCustomControls {
|
||||||
if hovering {
|
if hovering {
|
||||||
player.controls.show()
|
player.controls.show()
|
||||||
} else {
|
} else {
|
||||||
player.controls.hide()
|
player.controls.hide()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
.gesture(player.controls.presentingOverlays ? nil : playerDragGesture)
|
.gesture(player.controls.presentingOverlays ? nil : playerDragGesture)
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
.onAppear {
|
.onAppear {
|
||||||
NSEvent.addLocalMonitorForEvents(matching: [.mouseMoved]) {
|
NSEvent.addLocalMonitorForEvents(matching: [.mouseMoved]) {
|
||||||
hoverThrottle.execute {
|
hoverThrottle.execute {
|
||||||
if !player.currentItem.isNil, hoveringPlayer {
|
if !player.currentItem.isNil, hoveringPlayer, shouldShowCustomControls {
|
||||||
player.controls.resetTimer()
|
player.controls.resetTimer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -297,10 +305,7 @@ struct VideoPlayerView: View {
|
|||||||
fullScreen: $fullScreenDetails,
|
fullScreen: $fullScreenDetails,
|
||||||
sidebarQueue: $sidebarQueue
|
sidebarQueue: $sidebarQueue
|
||||||
)
|
)
|
||||||
.modifier(VideoDetailsPaddingModifier(
|
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
|
||||||
playerSize: player.playerSize,
|
|
||||||
fullScreen: fullScreenDetails
|
|
||||||
))
|
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
// TODO: Check whether this is needed on macOS.
|
// TODO: Check whether this is needed on macOS.
|
||||||
.onDisappear {
|
.onDisappear {
|
||||||
@@ -317,6 +322,7 @@ struct VideoPlayerView: View {
|
|||||||
VStack {}
|
VStack {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
|
|||||||
Reference in New Issue
Block a user