-
-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Still VERY much a work in progress but I think this looks nice. The f…
…ilter drawer is "done" but the spacing needs work. Next work be adding the Filter views that pop up and allow you to select them. Currently, selecting anything except for "Reset" will just crash Swiftfin since the views don't go anywhere.
- Loading branch information
Showing
9 changed files
with
293 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
Swiftfin tvOS/Components/LeadingBarFilterDrawer/FilterDrawerButton.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// | ||
// Swiftfin is subject to the terms of the Mozilla Public | ||
// License, v2.0. If a copy of the MPL was not distributed with this | ||
// file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2025 Jellyfin & Jellyfin Contributors | ||
// | ||
|
||
import Defaults | ||
import SwiftUI | ||
|
||
extension LeadingBarFilterDrawer { | ||
|
||
struct FilterDrawerButton: View { | ||
|
||
// MARK: - Defaults | ||
|
||
@Default(.accentColor) | ||
private var accentColor | ||
|
||
// MARK: - Environment Variables | ||
|
||
@Environment(\.isSelected) | ||
private var isSelected | ||
|
||
// MARK: - Focus State | ||
|
||
@FocusState | ||
private var isFocused: Bool | ||
|
||
// MARK: - Button Variables | ||
|
||
private let systemName: String? | ||
private let title: String | ||
private var onSelect: () -> Void | ||
|
||
// MARK: - Collapsing Variables | ||
|
||
private let expandedWidth: CGFloat | ||
private let collapsedWidth: CGFloat = 75 | ||
|
||
// MARK: - Initializer | ||
|
||
init(systemName: String?, title: String, expandedWidth: CGFloat, onSelect: @escaping () -> Void) { | ||
self.systemName = systemName | ||
self.title = title | ||
self.expandedWidth = expandedWidth | ||
self.onSelect = onSelect | ||
} | ||
|
||
// MARK: - Body | ||
|
||
var body: some View { | ||
Button { | ||
onSelect() | ||
} label: { | ||
HStack(spacing: 8) { | ||
if let systemName = systemName { | ||
Image(systemName: systemName) | ||
.frame(width: collapsedWidth, alignment: .center) | ||
.focusable(false) | ||
} | ||
if isFocused { | ||
Text(title) | ||
.transition(.move(edge: .leading).combined(with: .opacity)) | ||
Spacer(minLength: 0) | ||
} | ||
} | ||
.font(.footnote.weight(.semibold)) | ||
.foregroundColor(isFocused ? .primary : .secondary) | ||
.frame( | ||
width: isFocused ? expandedWidth : collapsedWidth, | ||
height: collapsedWidth, | ||
alignment: .leading | ||
) | ||
.background { | ||
Capsule() | ||
.foregroundColor(isSelected ? accentColor : Color.secondarySystemFill) | ||
.brightness(isFocused ? 0.25 : 0) | ||
.opacity(0.5) | ||
} | ||
.overlay { | ||
Capsule() | ||
.stroke(isSelected ? accentColor : Color.secondarySystemFill, lineWidth: 1) | ||
.brightness(isFocused ? 0.25 : 0) | ||
} | ||
.animation(.easeInOut(duration: 0.25), value: isFocused) | ||
} | ||
.frame(width: collapsedWidth, height: collapsedWidth, alignment: .leading) | ||
.buttonStyle(.borderless) | ||
.focused($isFocused) | ||
} | ||
} | ||
} | ||
|
||
extension LeadingBarFilterDrawer.FilterDrawerButton { | ||
|
||
init(systemName: String, title: String) { | ||
self.init( | ||
systemName: systemName, | ||
title: title, | ||
expandedWidth: 200, | ||
onSelect: {} | ||
) | ||
} | ||
|
||
func onSelect(_ action: @escaping () -> Void) -> Self { | ||
copy(modifying: \.onSelect, with: action) | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
Swiftfin tvOS/Components/LeadingBarFilterDrawer/LeadingBarFilterDrawer.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// Swiftfin is subject to the terms of the Mozilla Public | ||
// License, v2.0. If a copy of the MPL was not distributed with this | ||
// file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2025 Jellyfin & Jellyfin Contributors | ||
// | ||
|
||
import Defaults | ||
import JellyfinAPI | ||
import SwiftUI | ||
|
||
struct LeadingBarFilterDrawer: View { | ||
|
||
@ObservedObject | ||
private var viewModel: FilterViewModel | ||
|
||
private var filterTypes: [ItemFilterType] | ||
private var onSelect: (FilterCoordinator.Parameters) -> Void | ||
|
||
var body: some View { | ||
VStack { | ||
if viewModel.currentFilters.hasFilters { | ||
FilterDrawerButton( | ||
systemName: "line.3.horizontal.decrease.circle.fill", | ||
title: L10n.reset | ||
) | ||
.onSelect { | ||
viewModel.send(.reset()) | ||
} | ||
.environment(\.isSelected, true) | ||
} | ||
|
||
ForEach(filterTypes, id: \.self) { type in | ||
FilterDrawerButton( | ||
systemName: type.systemImage, | ||
title: type.displayTitle | ||
) | ||
.onSelect { | ||
onSelect(.init(type: type, viewModel: viewModel)) | ||
} | ||
.environment( | ||
\.isSelected, | ||
viewModel.isFilterSelected(type: type) | ||
) | ||
} | ||
} | ||
.padding(.horizontal) | ||
.padding(.vertical, 1) | ||
} | ||
} | ||
|
||
extension LeadingBarFilterDrawer { | ||
|
||
init(viewModel: FilterViewModel, types: [ItemFilterType]) { | ||
self.init( | ||
viewModel: viewModel, | ||
filterTypes: types, | ||
onSelect: { _ in } | ||
) | ||
} | ||
|
||
func onSelect(_ action: @escaping (FilterCoordinator.Parameters) -> Void) -> Self { | ||
copy(modifying: \.onSelect, with: action) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Swiftfin tvOS/Extensions/View/Modifiers/LeadingBarFilterDrawerModifier.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Swiftfin is subject to the terms of the Mozilla Public | ||
// License, v2.0. If a copy of the MPL was not distributed with this | ||
// file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2025 Jellyfin & Jellyfin Contributors | ||
// | ||
|
||
import Defaults | ||
import SwiftUI | ||
|
||
struct LeadingBarFilterDrawerModifier<Filters: View>: ViewModifier { | ||
let filters: () -> Filters | ||
|
||
// Define collapsed and expanded widths | ||
private let collapsedWidth: CGFloat = 75 | ||
private let expandedWidth: CGFloat = 200 | ||
|
||
// Use @State to track focus state and determine current width | ||
@State private var isExpanded: Bool = false | ||
|
||
private var filterDrawerWidth: CGFloat { | ||
isExpanded ? expandedWidth : collapsedWidth | ||
} | ||
|
||
func body(content: Content) -> some View { | ||
ZStack(alignment: .leading) { | ||
content | ||
.padding(.leading, filterDrawerWidth + 10) | ||
|
||
filters() | ||
.padding(.leading, 10) | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.