Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 馃幐 [JIRA: HCPSDKFIORIUIKIT-2559] list style configurable #674

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ struct ListPickerItemDataNonIdentifiableExample: View {
Text(framework.name)
}))
}
.listPickerListStyle(.inset)
.navigationBarTitle(Text("Form"))
}
}
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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)
}
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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