-
-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
267 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// 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) 2024 Jellyfin & Jellyfin Contributors | ||
// | ||
|
||
import Defaults | ||
import SwiftUI | ||
|
||
enum LetterPickerOrientation: String, CaseIterable, Defaults.Serializable, Displayable { | ||
|
||
case leading | ||
case trailing | ||
|
||
var displayTitle: String { | ||
switch self { | ||
case .leading: | ||
return L10n.left | ||
case .trailing: | ||
return L10n.right | ||
} | ||
} | ||
} |
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
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
55 changes: 55 additions & 0 deletions
55
Swiftfin/Components/LetterPickerBar/Components/LetterPickerButton.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,55 @@ | ||
// | ||
// 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) 2024 Jellyfin & Jellyfin Contributors | ||
// | ||
|
||
import Defaults | ||
import SwiftUI | ||
|
||
extension LetterPickerBar { | ||
|
||
struct LetterPickerButton: View { | ||
|
||
@Default(.accentColor) | ||
private var accentColor | ||
|
||
@Environment(\.isSelected) | ||
private var isSelected | ||
|
||
private let filterLetter: ItemLetter | ||
private let viewModel: FilterViewModel | ||
|
||
init(filterLetter: ItemLetter, viewModel: FilterViewModel) { | ||
self.filterLetter = filterLetter | ||
self.viewModel = viewModel | ||
} | ||
|
||
var body: some View { | ||
Button { | ||
if !viewModel.currentFilters.letter.contains(filterLetter) { | ||
viewModel.currentFilters.letter = [ItemLetter(stringLiteral: filterLetter.value)] | ||
} else { | ||
viewModel.currentFilters.letter = [] | ||
} | ||
} label: { | ||
Text( | ||
filterLetter.value | ||
) | ||
.environment(\.isSelected, viewModel.currentFilters.letter.contains(filterLetter)) | ||
.font(.headline) | ||
.frame(width: 15, height: 15) | ||
.foregroundStyle(isSelected ? accentColor.overlayColor : accentColor) | ||
.padding(.vertical, 2) | ||
.fixedSize(horizontal: false, vertical: true) | ||
.background { | ||
RoundedRectangle(cornerRadius: 5) | ||
.frame(width: 20, height: 20) | ||
.foregroundStyle(isSelected ? accentColor.opacity(0.5) : Color.clear) | ||
} | ||
} | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
Swiftfin/Components/LetterPickerBar/Components/LetterPickerOverflow.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,50 @@ | ||
// | ||
// 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) 2024 Jellyfin & Jellyfin Contributors | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
struct LetterPickerOverflow: ViewModifier { | ||
@State | ||
private var contentOverflow: Bool = false | ||
|
||
func body(content: Content) -> some View { | ||
GeometryReader { geometry in | ||
content | ||
.background( | ||
GeometryReader { contentGeometry in | ||
Color.clear.onAppear { | ||
contentOverflow = contentGeometry.size.height > geometry.size.height | ||
} | ||
} | ||
) | ||
.wrappedInScrollView(when: contentOverflow) | ||
} | ||
} | ||
} | ||
|
||
extension View { | ||
@ViewBuilder | ||
func wrappedInScrollView(when condition: Bool) -> some View { | ||
if condition { | ||
ScrollView(showsIndicators: false) { | ||
self | ||
} | ||
.frame(maxWidth: .infinity, alignment: .center) | ||
} else { | ||
self | ||
.frame(width: 30, alignment: .center) | ||
} | ||
} | ||
} | ||
|
||
extension View { | ||
func scrollOnOverflow() -> some View { | ||
modifier(LetterPickerOverflow()) | ||
} | ||
} |
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,37 @@ | ||
// | ||
// 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) 2024 Jellyfin & Jellyfin Contributors | ||
// | ||
|
||
import Defaults | ||
import SwiftUI | ||
|
||
struct LetterPickerBar: View { | ||
@ObservedObject | ||
private var viewModel: FilterViewModel | ||
|
||
init(viewModel: FilterViewModel) { | ||
self.viewModel = viewModel | ||
} | ||
|
||
@ViewBuilder | ||
var body: some View { | ||
VStack(spacing: 0) { | ||
Spacer() | ||
ForEach(ItemLetter.allCases, id: \.hashValue) { filterLetter in | ||
LetterPickerButton( | ||
filterLetter: filterLetter, | ||
viewModel: viewModel | ||
) | ||
.environment(\.isSelected, viewModel.currentFilters.letter.contains(filterLetter)) | ||
.frame(maxWidth: .infinity) | ||
} | ||
Spacer() | ||
} | ||
.scrollOnOverflow() | ||
.frame(width: 30, alignment: .center) | ||
} | ||
} |
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.