Skip to content

Commit

Permalink
Removed ListRowSeparatorStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
zmian committed Feb 1, 2024
1 parent 40412ef commit ca042b7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 112 deletions.
34 changes: 34 additions & 0 deletions Sources/Xcore/SwiftUI/Components/List/List+RowInsets.swift
Original file line number Diff line number Diff line change
@@ -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))
}
}
18 changes: 1 addition & 17 deletions Sources/Xcore/SwiftUI/Components/List/List+RowStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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)
}
}
}
90 changes: 0 additions & 90 deletions Sources/Xcore/SwiftUI/Components/List/List+Separator.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,13 @@ 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,
dim: dim,
alignment: alignment,
spacing: spacing
))
.unwrap(separatorStyle) {
$0.listRowSeparatorStyle($1)
}
}
}

0 comments on commit ca042b7

Please sign in to comment.