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