1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 05:40:32 +05:30

Improve controls overlays performance

This commit is contained in:
Arkadiusz Fal 2022-08-08 19:31:13 +02:00
parent 33d52aeed3
commit fb40f42c6c

View File

@ -39,7 +39,7 @@ struct PlayerControls: View {
OpeningStream()
NetworkState()
Group {
if model.presentingControls && !model.presentingOverlays {
VStack(spacing: 4) {
buttonsBar
@ -80,9 +80,10 @@ struct PlayerControls: View {
}
.padding(.top, 2)
.padding(.horizontal, 2)
.transition(.opacity)
}
.opacity(model.presentingOverlays ? 0 : model.presentingControls ? 1 : 0)
}
.frame(maxHeight: .infinity)
}
#if os(tvOS)
.onChange(of: model.presentingControls) { _ in
@ -98,30 +99,36 @@ struct PlayerControls: View {
.background(controlsBackground)
#endif
if model.presentingControlsOverlay {
ControlsOverlay()
.frame(height: overlayHeight)
.padding()
.modifier(ControlBackgroundModifier())
.clipShape(RoundedRectangle(cornerRadius: 4))
.opacity(model.presentingControlsOverlay ? 1 : 0)
.transition(.opacity)
}
if model.presentingDetailsOverlay {
VideoDetailsOverlay()
.frame(maxWidth: detailsWidth, maxHeight: detailsHeight)
.modifier(ControlBackgroundModifier())
.clipShape(RoundedRectangle(cornerRadius: 4))
.opacity(model.presentingDetailsOverlay ? 1 : 0)
.transition(.opacity)
}
if !model.presentingControls,
!model.presentingControls,
let segment = player.lastSkipped
{
Button {
player.restoreLastSkippedSegment()
} label: {
HStack(spacing: 10) {
if let segment = player.lastSkipped {
Image(systemName: "arrow.counterclockwise")
Text("Skipped \(segment.durationText) seconds of \(SponsorBlockAPI.categoryDescription(segment.category)?.lowercased() ?? "segment")")
.frame(alignment: .bottomLeading)
}
}
.padding(.vertical, 4)
.padding(.horizontal, 5)
.font(.system(size: 10))
@ -130,7 +137,15 @@ struct PlayerControls: View {
.clipShape(RoundedRectangle(cornerRadius: 2))
}
.buttonStyle(.plain)
.opacity(model.presentingControls || model.presentingOverlays ? 0 : player.lastSkipped.isNil ? 0 : 1)
.transition(.opacity)
}
}
.onChange(of: player.controls.presentingOverlays) { newValue in
if newValue {
player.backend.stopControlsUpdates()
} else {
player.backend.startControlsUpdates()
}
}
}