From a66b2191d1e1cabc67bfc8d72e098eea5647f5a0 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Fri, 17 Apr 2026 05:24:17 +0200 Subject: [PATCH] Keep focus on pressed tvOS channel tab button --- Yattee/Views/Channel/ChannelView.swift | 32 +++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Yattee/Views/Channel/ChannelView.swift b/Yattee/Views/Channel/ChannelView.swift index 03594bf0..547a4f3d 100644 --- a/Yattee/Views/Channel/ChannelView.swift +++ b/Yattee/Views/Channel/ChannelView.swift @@ -87,6 +87,12 @@ struct ChannelView: View { @State private var tvOSShowSearchTab = false @FocusState private var isSubscribeFocused: Bool @FocusState private var isTVSearchFieldFocused: Bool + @FocusState private var tvOSFocusedTab: TvOSChannelFocusTarget? + + private enum TvOSChannelFocusTarget: Hashable { + case tab(ChannelTab) + case searchTab + } #endif // Header configuration @@ -642,6 +648,7 @@ struct ChannelView: View { private var tvOSSearchTabButton: some View { let isSelected = tvOSShowSearchTab let action = { + tvOSFocusedTab = .searchTab if !tvOSShowSearchTab { tvOSShowSearchTab = true isSearchActive = true @@ -651,20 +658,17 @@ struct ChannelView: View { .fontWeight(isSelected ? .bold : .regular) .lineLimit(1) - if isSelected { - Button(action: action) { label } - .buttonStyle(.borderedProminent) - .tint(accentColor) - } else { - Button(action: action) { label } - .buttonStyle(.bordered) - } + Button(action: action) { label } + .buttonStyle(.borderedProminent) + .tint(isSelected ? accentColor : Color.gray.opacity(0.3)) + .focused($tvOSFocusedTab, equals: .searchTab) } @ViewBuilder private func tvOSTabButton(for tab: ChannelTab) -> some View { let isSelected = !tvOSShowSearchTab && selectedTab == tab let action = { + tvOSFocusedTab = .tab(tab) if tvOSShowSearchTab { tvOSShowSearchTab = false isSearchActive = false @@ -680,14 +684,10 @@ struct ChannelView: View { .fontWeight(isSelected ? .bold : .regular) .lineLimit(1) - if isSelected { - Button(action: action) { label } - .buttonStyle(.borderedProminent) - .tint(accentColor) - } else { - Button(action: action) { label } - .buttonStyle(.bordered) - } + Button(action: action) { label } + .buttonStyle(.borderedProminent) + .tint(isSelected ? accentColor : Color.gray.opacity(0.3)) + .focused($tvOSFocusedTab, equals: .tab(tab)) } private var tvOSRightColumn: some View {