From 541264d297443431af0d764183ea01efbbbfc215 Mon Sep 17 00:00:00 2001 From: kingbri Date: Mon, 5 Sep 2022 12:42:01 -0400 Subject: [PATCH] Sources: Fix searchbar behavior Cancelling the search now actually cancels the search. Signed-off-by: kingbri --- Ferrite/Views/SourcesView.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Ferrite/Views/SourcesView.swift b/Ferrite/Views/SourcesView.swift index faf7388..6a99021 100644 --- a/Ferrite/Views/SourcesView.swift +++ b/Ferrite/Views/SourcesView.swift @@ -40,14 +40,13 @@ struct SourcesView: View { return tempSources } - @State private var viewTask: Task? = nil @State private var checkedForSources = false - - @State private var searchText: String = "" @State private var isEditing = false - @State var filteredUpdatedSources: [SourceJson] = [] - @State var filteredAvailableSources: [SourceJson] = [] + @State private var viewTask: Task? = nil + @State private var searchText: String = "" + @State private var filteredUpdatedSources: [SourceJson] = [] + @State private var filteredAvailableSources: [SourceJson] = [] var body: some View { NavView { @@ -128,6 +127,9 @@ struct SourcesView: View { .navigationSearchBar { SearchBar("Search", text: $searchText, isEditing: $isEditing) .showsCancelButton(isEditing) + .onCancel { + searchText = "" + } } .onChange(of: searchText) { newValue in filteredAvailableSources = sourceManager.availableSources.filter { searchText.isEmpty ? true : $0.name.contains(searchText) }