-
-
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.
Drawer -> Bar and attempts at spacing.
- Loading branch information
Showing
8 changed files
with
175 additions
and
216 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
153 changes: 0 additions & 153 deletions
153
Swiftfin tvOS/Components/LibraryFilters/FilterDrawer/Components/FilterDrawerButton.swift
This file was deleted.
Oops, something went wrong.
114 changes: 114 additions & 0 deletions
114
Swiftfin tvOS/Components/LibraryFilters/FilterViews/Components/FilterButton.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,114 @@ | ||
// | ||
// 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 FilterButton: 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) | ||
.foregroundColor(isFocused ? .black : .primary) | ||
.frame(width: collapsedWidth, alignment: .center) | ||
.focusable(false) | ||
} | ||
if isFocused { | ||
Text(title) | ||
.transition(.move(edge: .leading).combined(with: .opacity)) | ||
.shadow(radius: 3) | ||
Spacer(minLength: 0) | ||
} | ||
} | ||
.font(.footnote.weight(.semibold)) | ||
.foregroundColor(isFocused ? .black : .primary) | ||
.frame( | ||
width: isFocused ? expandedWidth : collapsedWidth, | ||
height: collapsedWidth, | ||
alignment: .leading | ||
) | ||
.background { | ||
Capsule() | ||
.foregroundColor(isSelected ? accentColor : Color.secondarySystemFill) | ||
.brightness(isFocused ? 0.25 : 0) | ||
.opacity(isFocused ? 1 : 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) | ||
.padding(0) | ||
.buttonStyle(.borderless) | ||
.focused($isFocused) | ||
} | ||
} | ||
|
||
extension FilterButton { | ||
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) | ||
} | ||
} |
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.