diff --git a/Sources/Xcore/SwiftUI/Components/List/List+RowInsets.swift b/Sources/Xcore/SwiftUI/Components/List/List+RowInsets.swift new file mode 100644 index 000000000..629e0508d --- /dev/null +++ b/Sources/Xcore/SwiftUI/Components/List/List+RowInsets.swift @@ -0,0 +1,34 @@ +// +// Xcore +// Copyright © 2021 Xcore +// MIT license, see LICENSE file for details +// + +import SwiftUI + +// MARK: - List Row Insets Environment + +extension EnvironmentValues { + private struct CustomListRowInsetsKey: EnvironmentKey { + static var defaultValue: EdgeInsets = .listRow + } + + var customListRowInsets: EdgeInsets { + get { self[CustomListRowInsetsKey.self] } + set { self[CustomListRowInsetsKey.self] = newValue } + } +} + +// MARK: - View Helpers + +extension View { + /// Applies an inset to the rows in a list. + public func customListRowInsets(_ insets: EdgeInsets) -> some View { + environment(\.customListRowInsets, insets) + } + + /// Applies an inset to the rows in a list. + public func customListRowInsets(_ edges: Edge.Set, _ length: CGFloat) -> some View { + customListRowInsets(.init(edges, length)) + } +} diff --git a/Sources/Xcore/SwiftUI/Components/List/List+RowStyle.swift b/Sources/Xcore/SwiftUI/Components/List/List+RowStyle.swift index 8f81ca43b..86797946f 100644 --- a/Sources/Xcore/SwiftUI/Components/List/List+RowStyle.swift +++ b/Sources/Xcore/SwiftUI/Components/List/List+RowStyle.swift @@ -7,14 +7,8 @@ import SwiftUI extension View { - public func listRowStyle() -> some View { + public func listRowStyle(insets: EdgeInsets? = nil) -> some View { modifier(ListRowModifier()) - } - - public func listRowStyle(insets: EdgeInsets? = nil, separator separatorStyle: ListRowSeparatorStyle) -> some View { - self - .listRowStyle() - .listRowSeparatorStyle(separatorStyle) .unwrap(insets) { content, insets in content .customListRowInsets(insets) @@ -34,7 +28,6 @@ private struct ListRowModifier: ViewModifier { private struct InternalBody: View { @Environment(\.theme) private var theme @Environment(\.defaultMinListRowHeight) private var minHeight - @Environment(\.listRowSeparatorStyle) private var separatorStyle @Environment(\.customListRowInsets) private var rowInsets let content: Content @@ -44,15 +37,6 @@ private struct ListRowModifier: ViewModifier { .frame(maxWidth: .infinity, minHeight: minHeight, alignment: .leading) .listRowInsets(.zero) .listRowBackground(Color.clear) - .listRowSeparator(.hidden) - .overlay(separator, alignment: .bottom) - .contentShape(.rect) - } - - private var separator: some View { - Separator() - .padding(separatorStyle.insets) - .hidden(separatorStyle == .hidden, remove: true) } } } diff --git a/Sources/Xcore/SwiftUI/Components/List/List+Separator.swift b/Sources/Xcore/SwiftUI/Components/List/List+Separator.swift deleted file mode 100644 index 39f955d48..000000000 --- a/Sources/Xcore/SwiftUI/Components/List/List+Separator.swift +++ /dev/null @@ -1,90 +0,0 @@ -// -// Xcore -// Copyright © 2021 Xcore -// MIT license, see LICENSE file for details -// - -import SwiftUI - -// MARK: - Separator Style - -public enum ListRowSeparatorStyle: Equatable { - case hidden - case line(EdgeInsets) - - public static var line: Self { - .line(.zero) - } - - public static var lineInset: Self { - .line(.listRow) - } - - var insets: EdgeInsets { - switch self { - case .hidden: - return .zero - case let .line(insets): - return EdgeInsets( - top: 0, - leading: insets.leading, - bottom: 0, - trailing: insets.trailing - ) - } - } -} - -// MARK: - List Row Separator Style Environment - -extension EnvironmentValues { - private struct ListRowSeparatorStyleKey: EnvironmentKey { - static var defaultValue: ListRowSeparatorStyle = .line - } - - public var listRowSeparatorStyle: ListRowSeparatorStyle { - get { self[ListRowSeparatorStyleKey.self] } - set { self[ListRowSeparatorStyleKey.self] = newValue } - } -} - -// MARK: - View Helpers - -extension View { - /// Applies an inset to the rows separator in a list. - public func listRowSeparatorInsets(_ insets: CGFloat) -> some View { - listRowSeparatorStyle(.line(EdgeInsets(insets))) - } - - /// Applies the given separator style to the rows separator in a list. - public func listRowSeparatorStyle(_ style: ListRowSeparatorStyle) -> some View { - environment(\.listRowSeparatorStyle, style) - } -} - -// MARK: - List Row Insets Environment - -extension EnvironmentValues { - private struct CustomListRowInsetsKey: EnvironmentKey { - static var defaultValue: EdgeInsets = .listRow - } - - var customListRowInsets: EdgeInsets { - get { self[CustomListRowInsetsKey.self] } - set { self[CustomListRowInsetsKey.self] = newValue } - } -} - -// MARK: - View Helpers - -extension View { - /// Applies an inset to the rows in a list. - public func customListRowInsets(_ insets: EdgeInsets) -> some View { - environment(\.customListRowInsets, insets) - } - - /// Applies an inset to the rows in a list. - public func customListRowInsets(_ edges: Edge.Set, _ length: CGFloat) -> some View { - customListRowInsets(.init(edges, length)) - } -} diff --git a/Sources/Xcore/SwiftUI/Components/XLabeledContent/XLabeledContentStyle.swift b/Sources/Xcore/SwiftUI/Components/XLabeledContent/XLabeledContentStyle.swift index f24b575a3..be90588dc 100644 --- a/Sources/Xcore/SwiftUI/Components/XLabeledContent/XLabeledContentStyle.swift +++ b/Sources/Xcore/SwiftUI/Components/XLabeledContent/XLabeledContentStyle.swift @@ -114,8 +114,7 @@ extension View { _ traits: XLabeledContentContentTraits = .none, dim: XLabeledContentDimContent = .none, alignment: VerticalAlignment = .center, - spacing: CGFloat? = .interItemHSpacing, - separator separatorStyle: ListRowSeparatorStyle? = nil + spacing: CGFloat? = .interItemHSpacing ) -> some View { xlabeledContentStyle(DefaultXLabeledContentStyle( traits: traits, @@ -123,8 +122,5 @@ extension View { alignment: alignment, spacing: spacing )) - .unwrap(separatorStyle) { - $0.listRowSeparatorStyle($1) - } } }