Skip to content

Commit

Permalink
Focusable Loading Card.
Browse files Browse the repository at this point in the history
  • Loading branch information
JPKribs committed Feb 26, 2025
1 parent a7f6019 commit acbe3a1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import JellyfinAPI
import SwiftUI

extension SeriesEpisodeSelector {

struct EpisodeContent: View {

@Default(.accentColor)
private var accentColor

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ extension SeriesEpisodeSelector {
case let .error(error):
ErrorHStack(viewModel: viewModel, error: error, focusedEpisodeID: $focusedEpisodeID)
case .initial, .refreshing:
LoadingHStack()
LoadingHStack(focusedEpisodeID: $focusedEpisodeID)
}
}
.padding(.bottom, 45)
Expand All @@ -95,7 +95,7 @@ extension SeriesEpisodeSelector {
case .error:
focusedEpisodeID = "ErrorCard"
case .initial, .refreshing:
focusedEpisodeID = lastFocusedEpisodeID
focusedEpisodeID = "LoadingCard"
}
},
top: "seasons"
Expand Down Expand Up @@ -168,12 +168,15 @@ extension SeriesEpisodeSelector {

struct LoadingHStack: View {

let focusedEpisodeID: FocusState<String?>.Binding

var body: some View {
CollectionHStack(
count: Int.random(in: 2 ..< 5),
count: 1,
columns: 3.5
) { _ in
SeriesEpisodeSelector.LoadingCard()
.focused(focusedEpisodeID, equals: "LoadingCard")
.padding(.horizontal, 4)
}
.allowScrolling(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension SeriesEpisodeSelector {
.opacity(0.75)
.posterStyle(.landscape)
.overlay {
Image(systemName: "arrow.clockwise.circle.fill")
Image(systemName: "arrow.clockwise")
.font(.system(size: 40))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,34 @@ import SwiftUI

struct SeriesEpisodeSelector: View {

// MARK: - Observed & Environment Objects

@ObservedObject
var viewModel: SeriesItemViewModel

@EnvironmentObject
private var parentFocusGuide: FocusGuide

// MARK: - State Variables

@State
private var didSelectPlayButtonSeason = false
@State
private var selection: SeasonItemViewModel.ID?

// MARK: - Focus States

@FocusState
private var focusedSection: String?

// MARK: - Calculated Variables

private var selectionViewModel: SeasonItemViewModel? {
viewModel.seasons.first(where: { $0.id == selection })
}

// MARK: - Body

var body: some View {
VStack(spacing: 0) {
SeasonsHStack(viewModel: viewModel, selection: $selection)
Expand All @@ -36,7 +49,9 @@ struct SeriesEpisodeSelector: View {
EpisodeHStack(viewModel: selectionViewModel, playButtonItem: viewModel.playButtonItem)
.environmentObject(parentFocusGuide)
} else {
LoadingHStack()
LoadingHStack(focusedEpisodeID: $focusedSection)
.environmentObject(parentFocusGuide)
.focused($focusedSection, equals: "LoadingCard")
}
}
.onReceive(viewModel.playButtonItem.publisher) { newValue in
Expand Down

0 comments on commit acbe3a1

Please sign in to comment.