Fix tvOS controls overlay buttons

This commit is contained in:
Arkadiusz Fal
2022-09-02 02:06:33 +02:00
parent f7dd88a6cb
commit eebca5ca59
4 changed files with 57 additions and 19 deletions

View File

@@ -91,6 +91,13 @@ struct ControlsOverlay: View {
#if os(tvOS)
.padding(.horizontal, 40)
#endif
#if os(tvOS)
Text("Press and hold remote button to open captions and quality menus")
.frame(maxWidth: 400)
.font(.caption)
.foregroundColor(.secondary)
#endif
}
.frame(maxHeight: overlayHeight)
#if os(tvOS)
@@ -105,7 +112,7 @@ struct ControlsOverlay: View {
private var overlayHeight: Double {
#if os(tvOS)
contentSize.height + 50.0
contentSize.height + 80.0
#else
contentSize.height
#endif
@@ -255,9 +262,7 @@ struct ControlsOverlay: View {
.modifier(ControlBackgroundModifier())
.mask(RoundedRectangle(cornerRadius: 3))
#else
Button {
presentingButtonHintAlert = true
} label: {
ControlsOverlayButton(focusedField: $focusedField, field: .qualityProfile) {
Text(player.qualityProfileSelection?.description ?? "Automatic")
.lineLimit(1)
.frame(maxWidth: 320)
@@ -309,7 +314,7 @@ struct ControlsOverlay: View {
.modifier(ControlBackgroundModifier())
.mask(RoundedRectangle(cornerRadius: 3))
#else
StreamControl(presentingButtonHintAlert: $presentingButtonHintAlert)
StreamControl(focusedField: $focusedField)
#endif
}
@@ -339,9 +344,7 @@ struct ControlsOverlay: View {
.modifier(ControlBackgroundModifier())
.mask(RoundedRectangle(cornerRadius: 3))
#else
Button {
presentingButtonHintAlert = true
} label: {
ControlsOverlayButton(focusedField: $focusedField, field: .captions) {
HStack(spacing: 8) {
Image(systemName: "text.bubble")
if let captions = captionsBinding.wrappedValue {

View File

@@ -1,14 +1,16 @@
import SwiftUI
struct StreamControl: View {
@Binding var presentingButtonHintAlert: Bool
#if os(tvOS)
var focusedField: FocusState<ControlsOverlay.Field?>.Binding?
init(focusedField: FocusState<ControlsOverlay.Field?>.Binding?) {
self.focusedField = focusedField
}
#endif
@EnvironmentObject<PlayerModel> private var player
init(presentingButtonHintAlert: Binding<Bool> = .constant(false)) {
_presentingButtonHintAlert = presentingButtonHintAlert
}
var body: some View {
Group {
#if !os(tvOS)
@@ -36,9 +38,7 @@ struct StreamControl: View {
.disabled(player.isLoadingAvailableStreams)
#endif
#else
Button {
presentingButtonHintAlert = true
} label: {
ControlsOverlayButton(focusedField: focusedField!, field: .stream) {
Text(player.streamSelection?.shortQuality ?? "loading")
.frame(maxWidth: 320)
}
@@ -51,7 +51,6 @@ struct StreamControl: View {
}
#endif
}
.transaction { t in t.animation = .none }
.onChange(of: player.streamSelection) { selection in
guard let selection = selection else { return }
@@ -72,7 +71,11 @@ struct StreamControl: View {
struct StreamControl_Previews: PreviewProvider {
static var previews: some View {
StreamControl()
.injectFixtureEnvironmentObjects()
#if os(tvOS)
StreamControl(focusedField: .none)
.injectFixtureEnvironmentObjects()
#else
StreamControl()
#endif
}
}