Skip to content

Commit

Permalink
Drawer -> Bar and attempts at spacing.
Browse files Browse the repository at this point in the history
  • Loading branch information
JPKribs committed Mar 2, 2025
1 parent 0be566a commit a752a40
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 216 deletions.
6 changes: 6 additions & 0 deletions Shared/Coordinators/SearchCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ final class SearchCoordinator: NavigationCoordinatable {
var item = makeItem
@Route(.modal)
var library = makeLibrary
@Route(.fullScreen)
var filter = makeFilter
#else
@Route(.push)
var item = makeItem
Expand All @@ -39,6 +41,10 @@ final class SearchCoordinator: NavigationCoordinatable {
func makeLibrary(viewModel: PagingLibraryViewModel<BaseItemDto>) -> NavigationViewCoordinator<LibraryCoordinator<BaseItemDto>> {
NavigationViewCoordinator(LibraryCoordinator(viewModel: viewModel))
}

func makeFilter(parameters: FilterCoordinator.Parameters) -> NavigationViewCoordinator<FilterCoordinator> {
NavigationViewCoordinator(FilterCoordinator(parameters: parameters))
}
#else
func makeItem(item: BaseItemDto) -> ItemCoordinator {
ItemCoordinator(item: item)
Expand Down

This file was deleted.

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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Defaults
import JellyfinAPI
import SwiftUI

struct FilterDrawer: View {
struct FilterBar: View {

// MARK: - Observed Object

Expand All @@ -27,7 +27,7 @@ struct FilterDrawer: View {
var body: some View {
VStack {
if viewModel.currentFilters.hasFilters {
FilterDrawerButton(
FilterButton(
systemName: "line.3.horizontal.decrease.circle.fill",
title: L10n.reset
)
Expand All @@ -38,7 +38,7 @@ struct FilterDrawer: View {
}

ForEach(filterTypes, id: \.self) { type in
FilterDrawerButton(
FilterButton(
systemName: type.systemImage,
title: type.displayTitle
)
Expand All @@ -56,7 +56,7 @@ struct FilterDrawer: View {
}
}

extension FilterDrawer {
extension FilterBar {
init(viewModel: FilterViewModel, types: [ItemFilterType]) {
self.init(
viewModel: viewModel,
Expand Down
Loading

0 comments on commit a752a40

Please sign in to comment.