Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Sources/OpenSwiftUI/View/LabelGroup/BodyLabelGroupStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// BodyLabelGroupStyle.swift
// OpenSwiftUI
//
// Audited for 6.5.4
// Status: Complete

// MARK: BodyLabelGroupStyle

struct BodyLabelGroupStyle: LabelGroupStyle_v0 {
func font(at level: Int) -> Font {
switch level {
case 0: .body
case 1: .subheadline
case 2: .footnote
default: .footnote
}
}

func foregroundStyle(at level: Int) -> HierarchicalShapeStyle {
switch level {
case 0: .primary
case 1, 2: .secondary
default: .tertiary
}
}
}
27 changes: 27 additions & 0 deletions Sources/OpenSwiftUI/View/LabelGroup/LabelGroup.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// LabelGroup.swift
// OpenSwiftUI
//
// Audited for 6.5.4
// Status: Complete

@_spi(Private)
@available(OpenSwiftUI_v4_0, *)
public struct LabelGroup<Content>: View where Content: View {
var content: Content

public init(@ViewBuilder content: () -> Content) {
self.content = content()
}

public var body: some View {
ResolvedLabelGroupStyle()
.viewAlias(LabelGroupStyleConfiguration.Content.self) {
content
}
}
}

@_spi(Private)
@available(*, unavailable)
extension LabelGroup: Sendable {}
85 changes: 85 additions & 0 deletions Sources/OpenSwiftUI/View/LabelGroup/LabelGroupStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// LabelGroupStyle.swift
// OpenSwiftUI
//
// Audited for 6.5.4
// Status: WIP
// ID: D603B70BAAC92B7EC91530E54167B115 (SwiftUI)

// MARK: - LabelGroupStyle_v0

@_spi(UIFrameworks)
@available(OpenSwiftUI_v6_0, *)
public protocol LabelGroupStyle_v0 {
associatedtype Foreground: ShapeStyle = HierarchicalShapeStyle

func font(at level: Int) -> Font

func foregroundStyle(at level: Int) -> Self.Foreground
}

// MARK: - View + labelGroupStyle_v0

@_spi(UIFrameworks)
@available(OpenSwiftUI_v6_0, *)
extension View {
nonisolated public func labelGroupStyle_v0(_ style: some LabelGroupStyle_v0) -> some View {
modifier(LabelGroupStyleModifier(style: style))
}
}

// MARK: - LabelGroupStyleConfiguration

struct LabelGroupStyleConfiguration {
struct Content: ViewAlias {}

let content: Content
}

// MARK: - LabelGroupStyleModifier

struct LabelGroupStyleModifier<S>: StyleModifier where S: LabelGroupStyle_v0 {
var style: S

init(style: S) {
self.style = style
}

func styleBody(configuration: LabelGroupStyleConfiguration) -> some View {
_VariadicView.Tree(StyleApplicator(style: style)) {
configuration.content
}
}
}

// MARK: - ResolvedLabelGroupStyle

struct ResolvedLabelGroupStyle: StyleableView {
static let defaultStyleModifier: LabelGroupStyleModifier<BodyLabelGroupStyle> = .init(style: .init())

var configuration: LabelGroupStyleConfiguration { .init(content: .init()) }
}

// MARK: - StyleApplicator [WIP]

private struct StyleApplicator<S>: _VariadicView.MultiViewRoot where S: LabelGroupStyle_v0 {

struct EnumeratedView {
var view: _VariadicView.Children.Element
var offset: Int
}

var style: S

func body(children: _VariadicView.Children) -> some View {
ForEach(
children.enumerated().map { EnumeratedView(view: $0.element, offset: $0.offset) },
id: \.view.id
) { view in
view.view
// defaultForegroundStyle
// font
// platformItem
}
}
}