Skip to content

Commit

Permalink
feat: 馃幐 [JIRA: HCPSDKFIORIUIKIT-2559] list style configurable (#674)
Browse files Browse the repository at this point in the history
* feat: 馃幐 [JIRA: HCPSDKFIORIUIKIT-2559] list style configurable

* feat: 馃幐 rename to listPickerListStyle
  • Loading branch information
xiaoyu0722 committed Apr 2, 2024
1 parent 51a4078 commit 376fdb1
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 7 deletions.
Expand Up @@ -127,6 +127,7 @@ struct ListPickerItemDataNonIdentifiableExample: View {
Text(framework.name)
}))
}
.listPickerListStyle(.inset)
.navigationBarTitle(Text("Form"))
}
}
Expand Down
Expand Up @@ -24,6 +24,8 @@ struct SearchableListViewExample: View {
Spacer()
NavigationLink {
self.pickerView(self.$selection1)
.listStyle(.insetGrouped)
.listPickerListStyle(.grouped)
.navigationTitle("Title: Pick One")
} label: {
let str = self.selectedValues(Array(self.selection1))
Expand Down
2 changes: 2 additions & 0 deletions Sources/FioriSwiftUICore/Models/ModelDefinitions.swift
Expand Up @@ -107,6 +107,7 @@ public protocol ActivityItemsModel: ActionItemsComponent {}

// sourcery: generated_component
// sourcery: add_env_props = "listBackground"
// sourcery: add_env_props = "listpickerListStyle"
// sourcery: virtualPropDestinationView = "var destinationView: AnyView? = nil"
public protocol ListPickerItemModel: KeyComponent, ValueComponent {}

Expand Down Expand Up @@ -365,6 +366,7 @@ public protocol DurationPickerModel: DurationPickerComponent {}
// sourcery: availableAttributeContent = "iOS 15.0, macOS 12.0, *"
// sourcery: add_env_props = "presentationMode"
// sourcery: add_env_props = "listBackground"
// sourcery: add_env_props = "listpickerListStyle"
// sourcery: virtualPropContentView = "var contentView: AnyView? = nil"
// sourcery: virtualPropIsTopLevel = "var isTopLevel: Bool = true"
// sourcery: virtualPropDataHandler = "var dataHandler: (() -> ())? = nil"
Expand Down
24 changes: 22 additions & 2 deletions Sources/FioriSwiftUICore/Views/ListPickerItem+View.swift
Expand Up @@ -29,7 +29,7 @@ extension Fiori {
extension ListPickerItem: View {
public var body: some View {
NavigationLink(
destination: destinationView?.environment(\.listBackground, listBackground),
destination: destinationView?.listStyle(listpickerListStyle).listPickerListStyle(listpickerListStyle).listBackground(listBackground).typeErased,
label: {
KeyValueItem {
key
Expand Down Expand Up @@ -188,7 +188,6 @@ extension ListPickerItemConfiguration {
searchFilter: searchFilter,
rowContent: rowContent,
rowBackground: rowBackground)
.listStyle(.plain)
.typeErased
}
}
Expand Down Expand Up @@ -234,3 +233,24 @@ extension ListPickerItem {
}
}
}

struct ListpickerListStyleKey: EnvironmentKey {
static let defaultValue: any ListStyle = .automatic
}

extension EnvironmentValues {
/// listpickerListStyle environment value.
var listpickerListStyle: any ListStyle {
get { self[ListpickerListStyleKey.self] }
set { self[ListpickerListStyleKey.self] = newValue }
}
}

public extension View {
/// List style for destination list in list picker.
/// - Parameter style: some `ListStyle`.
/// - Returns: New destination list style for list picker.
func listPickerListStyle(_ style: some ListStyle) -> some View {
self.environment(\.listpickerListStyle, style)
}
}
3 changes: 2 additions & 1 deletion Sources/FioriSwiftUICore/Views/SearchableListContent.swift
Expand Up @@ -6,7 +6,8 @@ import SwiftUI

struct SearchableListContent<Data: RandomAccessCollection, ID: Hashable, RowContent: View, RowBackground: View>: View {
@Environment(\.listBackground) var listBackground

@Environment(\.listpickerListStyle) var listpickerListStyle

@State var searchText = ""
@State var selectionBuffer: Set<ID>

Expand Down
Expand Up @@ -34,7 +34,6 @@ extension SearchableListView: View {
public var body: some View {
if let contentView {
contentView
.listStyle(.plain)
.environment(\.listBackground, listBackground)
.ifApply(isTopLevel) {
$0.toolbar {
Expand Down
Expand Up @@ -5,6 +5,7 @@ import SwiftUI
public struct ListPickerItem<Key: View, Value: View> {
@Environment(\.keyModifier) private var keyModifier
@Environment(\.valueModifier) private var valueModifier
@Environment(\.listpickerListStyle) var listpickerListStyle
@Environment(\.listBackground) var listBackground

let _key: Key
Expand Down
Expand Up @@ -5,9 +5,10 @@ import SwiftUI
@available(iOS 15.0, macOS 12.0, *)
public struct SearchableListView<CancelActionView: View, DoneActionView: View> {
@Environment(\.cancelActionModifier) private var cancelActionModifier
@Environment(\.doneActionModifier) private var doneActionModifier
@Environment(\.listBackground) var listBackground
@Environment(\.presentationMode) var presentationMode
@Environment(\.doneActionModifier) private var doneActionModifier
@Environment(\.listBackground) var listBackground
@Environment(\.listpickerListStyle) var listpickerListStyle
@Environment(\.presentationMode) var presentationMode

let _cancelAction: CancelActionView
let _doneAction: DoneActionView
Expand Down

0 comments on commit 376fdb1

Please sign in to comment.