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 1 commit
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)
}))
}
.destinationStyle(.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)
.destinationStyle(.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 = "destinationListStyle"
// 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 = "destinationListStyle"
// 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(destinationListStyle).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 DestinationListStyleKey: EnvironmentKey {
xiaoyu0722 marked this conversation as resolved.
Show resolved Hide resolved
static let defaultValue: any ListStyle = .automatic
}

extension EnvironmentValues {
/// destinationListStyle environment value.
var destinationListStyle: any ListStyle {
get { self[DestinationListStyleKey.self] }
set { self[DestinationListStyleKey.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 destinationStyle(_ style: any ListStyle) -> some View {
xiaoyu0722 marked this conversation as resolved.
Show resolved Hide resolved
self.environment(\.destinationListStyle, 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(\.destinationListStyle) var destinationListStyle

@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(\.destinationListStyle) var destinationListStyle
@Environment(\.listBackground) var listBackground

let _key: Key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public struct SearchableListView<CancelActionView: View, DoneActionView: View> {
@Environment(\.cancelActionModifier) private var cancelActionModifier
@Environment(\.doneActionModifier) private var doneActionModifier
@Environment(\.listBackground) var listBackground
@Environment(\.destinationListStyle) var destinationListStyle
@Environment(\.presentationMode) var presentationMode

let _cancelAction: CancelActionView
Expand Down