From bd0b6ff491b33088a4db55c495b8aab797f0b22a Mon Sep 17 00:00:00 2001 From: Shav Kinderlehrer Date: Mon, 25 Dec 2023 01:02:38 -0500 Subject: [PATCH] Fix searchBar jank --- Jel.xcodeproj/project.pbxproj | 4 +++ Jel/Models/ViewConditionalMethod.swift | 23 ++++++++++++++++ Jel/Views/Library/Item/ItemMovieView.swift | 1 + Jel/Views/Library/LibraryDetailView.swift | 32 ++++++++++++---------- 4 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 Jel/Models/ViewConditionalMethod.swift diff --git a/Jel.xcodeproj/project.pbxproj b/Jel.xcodeproj/project.pbxproj index be0a680..c01594c 100644 --- a/Jel.xcodeproj/project.pbxproj +++ b/Jel.xcodeproj/project.pbxproj @@ -36,6 +36,7 @@ 3D91FDCD2B2907E800919017 /* JellyfinDateFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D91FDCC2B2907E800919017 /* JellyfinDateFormatter.swift */; }; 3DAFA8E82B38AFED00D71AD1 /* ItemInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DAFA8E72B38AFED00D71AD1 /* ItemInfoView.swift */; }; 3DAFA8EA2B39039900D71AD1 /* JellyfinKitExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DAFA8E92B39039900D71AD1 /* JellyfinKitExtensions.swift */; }; + 3DAFA8EC2B394F9F00D71AD1 /* ViewConditionalMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DAFA8EB2B394F9F00D71AD1 /* ViewConditionalMethod.swift */; }; 3DC6BA2D2B2A422300416B9F /* SettingsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DC6BA2C2B2A422300416B9F /* SettingsController.swift */; }; 3DDD67932B293BC40026781E /* DashboardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DDD67922B293BC40026781E /* DashboardView.swift */; }; 3DDD67962B29E28B0026781E /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DDD67952B29E28B0026781E /* SettingsView.swift */; }; @@ -102,6 +103,7 @@ 3D91FDCC2B2907E800919017 /* JellyfinDateFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JellyfinDateFormatter.swift; sourceTree = ""; }; 3DAFA8E72B38AFED00D71AD1 /* ItemInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemInfoView.swift; sourceTree = ""; }; 3DAFA8E92B39039900D71AD1 /* JellyfinKitExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JellyfinKitExtensions.swift; sourceTree = ""; }; + 3DAFA8EB2B394F9F00D71AD1 /* ViewConditionalMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewConditionalMethod.swift; sourceTree = ""; }; 3DC0E5802B2832B9001CCE96 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 3DC6BA2C2B2A422300416B9F /* SettingsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsController.swift; sourceTree = ""; }; 3DDD67922B293BC40026781E /* DashboardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardView.swift; sourceTree = ""; }; @@ -169,6 +171,7 @@ 3D8AB2A42B36440D005BD7D0 /* BlurHashDecode.swift */, 3D13F9682B389FA300E91913 /* ViewOffsetKey.swift */, 3DAFA8E92B39039900D71AD1 /* JellyfinKitExtensions.swift */, + 3DAFA8EB2B394F9F00D71AD1 /* ViewConditionalMethod.swift */, ); path = Models; sourceTree = ""; @@ -439,6 +442,7 @@ 3D1015D92B27F57400F5C29A /* AddServerView.swift in Sources */, 3DAFA8EA2B39039900D71AD1 /* JellyfinKitExtensions.swift in Sources */, 3D13F9652B37EC7A00E91913 /* ItemHeaderView.swift in Sources */, + 3DAFA8EC2B394F9F00D71AD1 /* ViewConditionalMethod.swift in Sources */, 3D9063CB2B279A310063DD2A /* JelApp.swift in Sources */, 3D13F9692B389FA300E91913 /* ViewOffsetKey.swift in Sources */, 3D91FDCD2B2907E800919017 /* JellyfinDateFormatter.swift in Sources */, diff --git a/Jel/Models/ViewConditionalMethod.swift b/Jel/Models/ViewConditionalMethod.swift new file mode 100644 index 0000000..195a8dc --- /dev/null +++ b/Jel/Models/ViewConditionalMethod.swift @@ -0,0 +1,23 @@ +// +// ViewConditionalMethod.swift +// Jel +// +// Created by zerocool on 12/25/23. +// + +import SwiftUI + +extension View { + /// Applies the given transform if the given condition evaluates to `true`. + /// - Parameters: + /// - condition: The condition to evaluate. + /// - transform: The transform to apply to the source `View`. + /// - Returns: Either the original `View` or the modified `View` if the condition is `true`. + @ViewBuilder func `if`(_ condition: @autoclosure () -> Bool, transform: (Self) -> Content) -> some View { + if condition() { + transform(self) + } else { + self + } + } +} diff --git a/Jel/Views/Library/Item/ItemMovieView.swift b/Jel/Views/Library/Item/ItemMovieView.swift index 055a158..eed083e 100644 --- a/Jel/Views/Library/Item/ItemMovieView.swift +++ b/Jel/Views/Library/Item/ItemMovieView.swift @@ -44,6 +44,7 @@ struct ItemMovieView: View { Text(item.taglines?.count ?? 0 > 0 ? item.taglines?[0] ?? "" : "") .font(.headline) .frame(maxWidth: .infinity, alignment: .leading) + .padding(.bottom) Text(item.overview ?? "---") } diff --git a/Jel/Views/Library/LibraryDetailView.swift b/Jel/Views/Library/LibraryDetailView.swift index 9d4e46d..5d0e695 100644 --- a/Jel/Views/Library/LibraryDetailView.swift +++ b/Jel/Views/Library/LibraryDetailView.swift @@ -57,23 +57,25 @@ struct LibraryDetailView: View { } } } - .searchable(text: $searchText) - .onChange(of: searchText) { - Task { - let parameters = Paths.GetParameters( - userID: AuthStateController.shared.userId, - searchTerm: searchText.lowercased(), - parentID: library.id - ) - searchResultHints = await jellyfinClient.search(parameters: parameters) - - searchResultItems = items?.filter { item in - for hint in searchResultHints?.searchHints ?? [] { - if hint.name == item.name { - return true + .if(!loading) {view in + view.searchable(text: $searchText) + .onChange(of: searchText) { + Task { + let parameters = Paths.GetParameters( + userID: AuthStateController.shared.userId, + searchTerm: searchText.lowercased(), + parentID: library.id + ) + searchResultHints = await jellyfinClient.search(parameters: parameters) + + searchResultItems = items?.filter { item in + for hint in searchResultHints?.searchHints ?? [] { + if hint.name == item.name { + return true + } } + return false } - return false } } }