-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 jira 2286 sort & filter for SwiftUI project (#606)
* feat: 🎸 jira 2286 sort & filter for SwiftUI project A SwiftUI component for configuration criteria of performing sorting and filter. SortFilterMenu and SortFilterFullCFG are provided. ✅ Closes: 1 * feat: 🎸 jira 2286 sort & filter for SwiftUI project A SwiftUI component for configuration criteria of performing sorting and filter. SortFilterMenu and SortFilterFullCFG are provided. ✅ Closes: 1 * feat: 🎸 jira 2286 sort & filter for SwiftUI project A SwiftUI component for configuration criteria of performing sorting and filter. SortFilterMenu and SortFilterFullCFG are provided. ✅ Closes: 1 * merge changes from upstream * refactor * Support disabled reset button and refactor * renaming * improvement for designer review * improvement for designer review 2 * refactor & review * refactor & review * refactor & review * refactor & review * refactor & review * refactor & review * refactor & review * refactor & review * refactor & review * refactor & review * refactor & review * refactor & review * feat: refactor & review --------- Co-authored-by: dyongxu <[email protected]>
- Loading branch information
1 parent
088aef8
commit 6b3eef6
Showing
159 changed files
with
4,088 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
Apps/Examples/Examples/FioriSwiftUICore/SortFilter/SortFilterExample.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import FioriSwiftUICore | ||
import SwiftUI | ||
|
||
struct SortFilterExample: View { | ||
@State private var items: [[SortFilterItem]] = [ | ||
[ | ||
.switch(item: .init(name: "Favorite", value: true, icon: "heart.fill"), showsOnFilterFeedbackBar: true), | ||
.switch(item: .init(name: "Tagged", value: nil, icon: "tag"), showsOnFilterFeedbackBar: false), | ||
.picker(item: .init(name: "JIRA Status", value: [0], valueOptions: ["Received", "Started", "Hold", "Transfer", "Completed", "Pending Review", "Accepted", "Rejected"], allowsMultipleSelection: true, allowsEmptySelection: true, icon: "clock"), showsOnFilterFeedbackBar: true) | ||
], | ||
[ | ||
.picker(item: .init(name: "Priority", value: [0], valueOptions: ["High", "Medium", "Low"], allowsMultipleSelection: true, allowsEmptySelection: true, icon: "filemenu.and.cursorarrow"), showsOnFilterFeedbackBar: true), | ||
.filterfeedback(item: .init(name: "Sort Order", value: [0], valueOptions: ["Ascending", "Descending"], allowsMultipleSelection: false, allowsEmptySelection: false, icon: "checkmark")) | ||
], | ||
[ | ||
.slider(item: .init(name: "User Stories", value: 10, minimumValue: 0, maximumValue: 100, formatter: "%2d Stories", icon: "number"), showsOnFilterFeedbackBar: true), | ||
.slider(item: .init(name: "Number of Tasks", value: nil, minimumValue: 0, maximumValue: 100), showsOnFilterFeedbackBar: true), | ||
.datetime(item: .init(name: "Start Date", value: Date(), formatter: "yyyy-MM-dd HH:mm",icon: "calendar"), showsOnFilterFeedbackBar: true) | ||
], | ||
[ | ||
.datetime(item: .init(name: "Completion Date", value: nil), showsOnFilterFeedbackBar: true) | ||
] | ||
] | ||
|
||
@State private var isShowingFullCFG: Bool = false | ||
@State private var isCustomStyle: Bool = false | ||
@State private var sortFilterList: [String] = [] | ||
@State private var sortFilterButtonLabel: String = "Sort & Filter" | ||
|
||
var body: some View { | ||
VStack { | ||
if isCustomStyle { | ||
FilterFeedbackBar(items: $items, onUpdate: performSortAndFilter) | ||
.filterFeedbackBarStyle(font: .subheadline, foregroundColorSelected: .red, strokeColorSelected: .red, cornerRadius: 25) | ||
.optionListPickerStyle(font: .footnote, foregroundColorUnselected: .green, strokeColorSelected: .black) | ||
// .trailingFullConfigurationMenuItem(icon: "command") | ||
// .leadingFullConfigurationMenuItem(icon: "command") | ||
// .leadingFullConfigurationMenuItem(name: "All") | ||
} else { | ||
FilterFeedbackBar(items: $items, onUpdate: performSortAndFilter) | ||
} | ||
|
||
List { | ||
ForEach(sortFilterList, id: \.self) { line in | ||
Text(line) | ||
} | ||
} | ||
.listStyle(PlainListStyle()) | ||
|
||
HStack { | ||
Toggle("Custom Style", isOn: $isCustomStyle) | ||
.fixedSize() | ||
.toggleStyle(FioriToggleStyle()) | ||
|
||
Button("Print") { | ||
for line in sortFilterList { | ||
print(line) | ||
} | ||
} | ||
} | ||
} | ||
.navigationTitle("Sort & Filter") | ||
.toolbar { | ||
Button(sortFilterButtonLabel) { | ||
isShowingFullCFG.toggle() | ||
} | ||
.popover(isPresented: $isShowingFullCFG, arrowEdge: .leading) { | ||
if isCustomStyle { | ||
SortFilterView( | ||
title: "Configuration", | ||
items: $items, | ||
onUpdate: performSortAndFilter | ||
) | ||
.optionListPickerStyle(font: .footnote, foregroundColorUnselected: .green, strokeColorSelected: .black) | ||
} else { | ||
SortFilterView( | ||
title: "Configuration", | ||
items: $items, | ||
onUpdate: performSortAndFilter | ||
) | ||
} | ||
} | ||
} | ||
.onAppear { | ||
performSortAndFilter() | ||
} | ||
} | ||
|
||
func numberOfItems() -> Int { | ||
// randomly padding result to mimic impact of filterring | ||
for i in 0 ... Int.random(in: 0 ... 5) { | ||
self.sortFilterList.append("padding element \(i + 1)") | ||
} | ||
return self.sortFilterList.count | ||
} | ||
|
||
func performSortAndFilter() { | ||
self.sortFilterList = self.items.joined().map { value(of: $0) } | ||
self.sortFilterButtonLabel = "CFG (\(self.numberOfItems()))" | ||
} | ||
} | ||
|
||
#if DEBUG | ||
@available(iOS 16.0, *) | ||
struct SortFilterExample_Previews: PreviewProvider { | ||
static var previews: some View { | ||
SortFilterExample() | ||
} | ||
} | ||
#endif |
35 changes: 35 additions & 0 deletions
35
Apps/Examples/Examples/FioriSwiftUICore/SortFilter/SortFilterView+Extensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import FioriSwiftUICore | ||
import SwiftUI | ||
|
||
extension View { | ||
func value(of item: SortFilterItem) -> String { | ||
switch item { | ||
case .picker(let v, _): | ||
return self.json(item: v) | ||
case .filterfeedback(let v): | ||
return self.json(item: v) | ||
case .slider(let v, _): | ||
return self.json(item: v) | ||
case .datetime(let v, _): | ||
return self.json(item: v) | ||
case .switch(let v, _): | ||
return self.json(item: v) | ||
} | ||
} | ||
|
||
func json(item: SortFilterItem.PickerItem) -> String { | ||
"{name: \(item.name), value: \(item.value)}" | ||
} | ||
|
||
func json(item: SortFilterItem.SliderItem) -> String { | ||
"{name: \(item.name), value: \(String(describing: item.value))}" | ||
} | ||
|
||
func json(item: SortFilterItem.DateTimeItem) -> String { | ||
"{name: \(item.name), value: \(String(describing: item.value))}" | ||
} | ||
|
||
func json(item: SortFilterItem.SwitchItem) -> String { | ||
"{name: \(item.name), value: \(String(describing: item.value))}" | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...mples/Examples/Preview Content/Preview Assets.xcassets/iconfromapp.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "icon.png", | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+934 Bytes
.../Examples/Preview Content/Preview Assets.xcassets/iconfromapp.imageset/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.