Skip to content

Commit

Permalink
fix: picker crash when no elements (#63) (#517)
Browse files Browse the repository at this point in the history
Co-authored-by: Vadim Kuznetsov <[email protected]>
  • Loading branch information
rnr and forgotvas authored Sep 30, 2024
1 parent a183f18 commit 61b3e37
Showing 1 changed file with 6 additions and 4 deletions.
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

0 comments on commit 61b3e37

Please sign in to comment.