Skip to content

Commit

Permalink
fix: 馃悰 swift version check for serchable modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyu0722 committed Nov 9, 2022
1 parent f6b8ae4 commit adc2d75
Showing 1 changed file with 62 additions and 34 deletions.
96 changes: 62 additions & 34 deletions Sources/FioriSwiftUICore/Views/ListPickerItem+View.swift
Expand Up @@ -240,47 +240,75 @@ public struct SearchListView<Data: RandomAccessCollection,
}

public var body: some View {
List {
ForEach(data.filter { element in
searchFilter(element, searchText)
}, id: id) { element in
let row = rowContent(element)
let id_value = element[keyPath: id]
#if swift(>=5.5)
List {
ForEach(data.filter { element in
searchFilter(element, searchText)
}, id: id) { element in
let row = rowContent(element)
let id_value = element[keyPath: id]

if let children = children, let childrenData = element[keyPath: children] {
let configuration = ListPickerItemConfiguration(childrenData,
id: id,
children: children,
selection: !isTopLevel ? selection : $selectionBuffer,
isTopLevel: false,
searchFilter: searchFilter,
rowContent: rowContent)
ListPickerItem<RowContent, EmptyView>(key: {
row
}, value: {
EmptyView()
}, configuration: configuration)
} else {
ListPickerItem.Row(content: row, id: id_value, selection: !isTopLevel ? selection : $selectionBuffer)
if let children = children, let childrenData = element[keyPath: children] {
let configuration = ListPickerItemConfiguration(childrenData,
id: id,
children: children,
selection: !isTopLevel ? selection : $selectionBuffer,
isTopLevel: false,
searchFilter: searchFilter,
rowContent: rowContent)
ListPickerItem<RowContent, EmptyView>(key: {
row
}, value: {
EmptyView()
}, configuration: configuration)
} else {
ListPickerItem.Row(content: row, id: id_value, selection: !isTopLevel ? selection : $selectionBuffer)
}
}
}
}
.searchable(text: $searchText)
.ifApply(isTopLevel) {
$0.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button("Cancel") {
presentationMode.wrappedValue.dismiss()
.searchable(text: $searchText)
.ifApply(isTopLevel) {
$0.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button("Cancel") {
presentationMode.wrappedValue.dismiss()
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Button("Confirm") {
selection?.wrappedValue = selectionBuffer
presentationMode.wrappedValue.dismiss()
}
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Button("Confirm") {
selection?.wrappedValue = selectionBuffer
presentationMode.wrappedValue.dismiss()
.navigationBarBackButtonHidden(true)
}
#else
List {
ForEach(data.filter { element in
searchFilter(element, searchText)
}, id: id) { element in
let row = rowContent(element)
let id_value = element[keyPath: id]

if let children = children, let childrenData = element[keyPath: children] {
let configuration = ListPickerItemConfiguration(childrenData,
id: id,
children: children,
selection: !isTopLevel ? selection : $selectionBuffer,
isTopLevel: false,
searchFilter: searchFilter,
rowContent: rowContent)
ListPickerItem<RowContent, EmptyView>(key: {
row
}, value: {
EmptyView()
}, configuration: configuration)
} else {
ListPickerItem.Row(content: row, id: id_value, selection: !isTopLevel ? selection : $selectionBuffer)
}
}
}
.navigationBarBackButtonHidden(true)
}
#endif
}
}

0 comments on commit adc2d75

Please sign in to comment.