Skip to content

Commit

Permalink
Add hasDividers to ListStyle protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
diskzero committed Jul 27, 2020
1 parent 3ee995b commit 05378b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion Sources/TokamakCore/Styles/ListStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
// Created by Carson Katri on 7/5/20.
//

public protocol ListStyle {}
public protocol ListStyle {
var hasDividers: Bool { get }
}

/// A protocol implemented on the renderer to create platform-specific list styles.
public protocol ListStyleDeferredToRenderer {
func listBody<ListBody>(_ content: ListBody) -> AnyView where ListBody: View
Expand Down Expand Up @@ -51,22 +54,27 @@ public extension ListStyleDeferredToRenderer {
public typealias DefaultListStyle = PlainListStyle

public struct PlainListStyle: ListStyle {
public var hasDividers = true
public init() {}
}

public struct GroupedListStyle: ListStyle {
public var hasDividers = true
public init() {}
}

public struct InsetListStyle: ListStyle {
public var hasDividers = true
public init() {}
}

public struct InsetGroupedListStyle: ListStyle {
public var hasDividers = true
public init() {}
}

public struct SidebarListStyle: ListStyle {
public var hasDividers = false
public init() {}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/TokamakCore/Views/Containers/List.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public struct _ListRow {
public static func listRow<V: View>(_ view: V, _ style: ListStyle, isLast: Bool) -> some View {
(style as? ListStyleDeferredToRenderer)?.listRow(view) ??
AnyView(view.padding([.trailing, .top, .bottom]))
if !isLast && style as? SidebarListStyle == nil {
if !isLast && style.hasDividers {
Divider()
}
}
Expand Down

0 comments on commit 05378b9

Please sign in to comment.