From 11c25648bff5c938483fd386e99c47123fa51fc3 Mon Sep 17 00:00:00 2001 From: Joe Date: Fri, 16 Aug 2024 12:30:15 -0600 Subject: [PATCH] [tvOS] Episode/Season Focus gets Stuck (#1185) * Focus on the first element if the lastFocusedEpisodeId isn't in the viewModel. * Performance Improvements: - Optimized Lookup: Used a Set for efficient checking of whether lastFocusedEpisodeID exists in viewModel.elements. - Single Pass: Reduced the number of passes needed to check for existence and set the focusedEpisodeID. * https://github.com/jellyfin/Swiftfin/pull/1185#pullrequestreview-2241625398 Suggestions --------- Co-authored-by: Joseph Kribs --- .../EpisodeSelector/Components/EpisodeHStack.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Swiftfin tvOS/Views/ItemView/Components/EpisodeSelector/Components/EpisodeHStack.swift b/Swiftfin tvOS/Views/ItemView/Components/EpisodeSelector/Components/EpisodeHStack.swift index 8c2861ea..e228d506 100644 --- a/Swiftfin tvOS/Views/ItemView/Components/EpisodeSelector/Components/EpisodeHStack.swift +++ b/Swiftfin tvOS/Views/ItemView/Components/EpisodeSelector/Components/EpisodeHStack.swift @@ -85,6 +85,11 @@ extension SeriesEpisodeSelector { guard let newValue else { return } lastFocusedEpisodeID = newValue } + .onChange(of: viewModel.state) { _, newValue in + if newValue == .content { + lastFocusedEpisodeID = viewModel.elements.first?.id + } + } } }