Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: picker crash when no elements #517

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Core/Core/View/Base/PickerMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public struct PickerMenu: View {
private let router: BaseRouter
private var idiom: UIUserInterfaceIdiom { UIDevice.current.userInterfaceIdiom }
private var selected: ((PickerItem) -> Void) = { _ in }
private let emptyKey: String = "--empty--"

public init(
items: [PickerItem],
Expand All @@ -50,18 +51,19 @@ public struct PickerMenu: View {

private var filteredItems: [PickerItem] {
if search.isEmpty {
return items
return items.isEmpty ? [PickerItem(key: emptyKey, value: "")] : items
} else {
return items.filter { $0.value.localizedCaseInsensitiveContains(search) }
let filteredItems = items.filter { $0.value.localizedCaseInsensitiveContains(search) }
return filteredItems.isEmpty ? [PickerItem(key: emptyKey, value: "")] : filteredItems
}
}

private var isSingleSelection: Bool {
return filteredItems.count == 1
return filteredItems.count == 1 && filteredItems.first?.key != emptyKey
}

private var isItemSelected: Bool {
return filteredItems.contains(selectedItem)
return filteredItems.contains(selectedItem) && selectedItem.key != emptyKey
}

private var acceptButtonDisabled: Bool {
Expand Down
Loading