-
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
A SwiftUI component for configuration criteria of performing sorting and filter. SortFilterMenu and SortFilterFullCFG are provided. ✅ Closes: 1
- Loading branch information
1 parent
24ca365
commit c37aeea
Showing
55 changed files
with
4,049 additions
and
28 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
80 changes: 80 additions & 0 deletions
80
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,80 @@ | ||
import FioriSwiftUICore | ||
import SwiftUI | ||
|
||
struct SortFilterExample: View { | ||
@State private var items: [[SortFilterItem]] = [[ | ||
.picker(item: .init(value: [0], valueOptions: ["Received", "Started", "Hold", "Transfer", "Completed", "Pending Review", "Accepted", "Rejected"], name: "JIRA Status", allowsMultipleSelection: true, allowsEmptySelection: true, icon: "clock"), isShownOnMenu: true), | ||
.picker(item: .init(value: [0], valueOptions: ["High", "Medium", "Low"], name: "Priority", allowsMultipleSelection: true, allowsEmptySelection: true, icon: "filemenu.and.cursorarrow"), isShownOnMenu: true), | ||
.filterfeedback(item: .init(value: [0], valueOptions: ["Ascending", "Descending"], name: "Sort Order", allowsMultipleSelection: false, allowsEmptySelection: false, icon: "checkmark")), | ||
.slider(item: .init(value: 10, minimumValue: 0, maximumValue: 100, name: "Number of User Stories", icon: "number"), isShownOnMenu: true), | ||
.slider(item: .init(value: nil, minimumValue: 0, maximumValue: 100, name: "Number of Tasks"), isShownOnMenu: true), | ||
.datetime(item: .init(value: Date(), name: "Start Date", icon: "calendar"), isShownOnMenu: true), | ||
.datetime(item: .init(value: nil, name: "Completion Date"), isShownOnMenu: true), | ||
.switch(item: .init(name: "Favorite", value: true, icon: "heart.fill"), isShownOnMenu: true), | ||
.switch(item: .init(name: "Tagged", value: nil, icon: "tag"), isShownOnMenu: false) | ||
]] | ||
|
||
@State private var isShowingFullCFG: Bool = false | ||
@State private var sortFilterList: [String] = [] | ||
@State private var sortFilterButtonLabel: String = "Sort & Filter" | ||
|
||
var body: some View { | ||
VStack { | ||
SortFilterMenu(items: $items, onUpdate: performSortAndFilter) | ||
// .trailingFullConfigurationMenuItem(icon: "command") | ||
// .leadingFullConfigurationMenuItem(icon: "command") | ||
// .leadingFullConfigurationMenuItem(name: "All") | ||
// .sortFilterMenuItemStyle(font: .subheadline, foregroundColorSelected: .red, strokeColorSelected: .red, cornerRadius: 25) | ||
|
||
List { | ||
ForEach(sortFilterList, id: \.self) { line in | ||
Text(line) | ||
} | ||
} | ||
.listStyle(PlainListStyle()) | ||
|
||
Button("Print") { | ||
for line in sortFilterList { | ||
print(line) | ||
} | ||
} | ||
} | ||
.navigationTitle("Sort & Filter") | ||
.toolbar { | ||
Button(sortFilterButtonLabel) { | ||
isShowingFullCFG.toggle() | ||
} | ||
} | ||
.sheet(isPresented: $isShowingFullCFG) { | ||
SortFilterFullCFG( | ||
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("Non-SortFilterCFG: element \(i + 1)") | ||
} | ||
return self.sortFilterList.count | ||
} | ||
|
||
func performSortAndFilter() { | ||
self.sortFilterList = self.items.joined().map { value(of: $0) } | ||
self.sortFilterButtonLabel = "Sort & Filter (\(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/View+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: PickerItem) -> String { | ||
"SortFilterCFG: {name: \(item.name), value: \(item.value)}" | ||
} | ||
|
||
func json(item: SliderItem) -> String { | ||
"SortFilterCFG: {name: \(item.name), value: \(String(describing: item.value))}" | ||
} | ||
|
||
func json(item: DateTimeItem) -> String { | ||
"SortFilterCFG: {name: \(item.name), value: \(String(describing: item.value))}" | ||
} | ||
|
||
func json(item: SwitchItem) -> String { | ||
"SortFilterCFG: {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
109 changes: 109 additions & 0 deletions
109
Sources/FioriSwiftUICore/Components/CancellableResettableForm.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,109 @@ | ||
import Foundation | ||
import SwiftUI | ||
|
||
struct CancellableResettableDialogForm<Title: View, CancelAction: View, ResetAction: View, ApplyAction: View, Components: View>: View { | ||
let title: Title | ||
|
||
let components: Components | ||
|
||
var cancelAction: CancelAction | ||
var resetAction: ResetAction | ||
var applyAction: ApplyAction | ||
|
||
public init(@ViewBuilder title: () -> Title, | ||
@ViewBuilder cancelAction: () -> CancelAction, | ||
@ViewBuilder resetAction: () -> ResetAction, | ||
@ViewBuilder applyAction: () -> ApplyAction, | ||
@ViewBuilder components: () -> Components) | ||
{ | ||
self.title = title() | ||
self.cancelAction = cancelAction() | ||
self.resetAction = resetAction() | ||
self.applyAction = applyAction() | ||
self.components = components() | ||
} | ||
|
||
var body: some View { | ||
VStack(spacing: UIDevice.current.userInterfaceIdiom == .pad ? 8 : 16) { | ||
HStack { | ||
cancelAction | ||
Spacer() | ||
title | ||
Spacer() | ||
resetAction | ||
} | ||
components | ||
applyAction | ||
} | ||
.frame(minWidth: 375) | ||
.padding(UIDevice.current.userInterfaceIdiom == .pad ? 13 : 16) | ||
} | ||
} | ||
|
||
// fileprivate extension View { | ||
// func readHeight() -> some View { | ||
// self.modifier(ReadHeightModifier()) | ||
// } | ||
// } | ||
// | ||
// private struct ReadHeightModifier: ViewModifier { | ||
// private var sizeView: some View { | ||
// GeometryReader { geometry in | ||
// Color.clear.preference(key: HeightPreferenceKey.self, value: geometry.size.height) | ||
// } | ||
// } | ||
// | ||
// func body(content: Content) -> some View { | ||
// content.background(sizeView) | ||
// } | ||
// } | ||
// | ||
// | ||
|
||
struct ApplyButtonStyle: PrimitiveButtonStyle { | ||
func makeBody(configuration: Configuration) -> some View { | ||
// GeometryReader { geometry in | ||
// HStack { | ||
// Spacer() | ||
configuration.label | ||
.frame(minWidth: 375, maxWidth: .infinity) | ||
// Spacer() | ||
// } | ||
.onTapGesture { | ||
configuration.trigger() | ||
} | ||
.padding(15) | ||
.font(.system(size: 16, weight: .bold)) | ||
.background(RoundedRectangle(cornerRadius: 5).fill(Color.preferredColor(.tintColor))) | ||
.foregroundColor(.white) | ||
} | ||
|
||
// } | ||
} | ||
|
||
#Preview { | ||
VStack { | ||
Spacer() | ||
CancellableResettableDialogForm { | ||
Text("Date of Completion") | ||
} cancelAction: { | ||
Action(actionText: "Cancel", didSelectAction: nil) | ||
} resetAction: { | ||
Action(actionText: "Reset", didSelectAction: nil) | ||
} applyAction: { | ||
Button {} label: { | ||
Text("Apply") | ||
.frame(width: 375) | ||
} | ||
// Action(actionText: "Apply", didSelectAction: nil) | ||
// .buttonStyle(ApplyButtonStyle()) | ||
} components: { | ||
DatePicker( | ||
"date", | ||
selection: Binding<Date>(get: { Date() }, set: { print($0) }), | ||
displayedComponents: [.date] | ||
) | ||
.datePickerStyle(.graphical) | ||
} | ||
} | ||
} |
Oops, something went wrong.