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

@@ -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
}
}