Skip to content

Commit

Permalink
Add row with footer modifier
Browse files Browse the repository at this point in the history
- iOS/tvOS: section adds footer, row renders as is
- macOS: section omits footer, row adds a description
  • Loading branch information
keeshux committed Nov 5, 2024
1 parent 833d717 commit d0dff1c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ extension ThemeSectionWithHeaderFooterModifier {
}
}

extension ThemeRowWithFooterModifier {
func body(content: Content) -> some View {
content
// omit footer on iOS/tvOS, use ThemeSectionWithHeaderFooterModifier
}
}

// MARK: - Views

extension ThemeTappableText {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,25 @@ extension ThemeSectionWithHeaderFooterModifier {
func body(content: Content) -> some View {
Section {
content
} header: {
header.map(Text.init)
}
// omit footer on macOS, use ThemeRowWithFooterModifier
}
}

extension ThemeRowWithFooterModifier {
func body(content: Content) -> some View {
VStack {
content
.frame(maxWidth: .infinity, alignment: .leading)

footer.map {
Text($0)
.foregroundStyle(.secondary)
.font(.callout)
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)
}
} header: {
header.map(Text.init)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ extension ThemeSectionWithHeaderFooterModifier {
}
}

extension ThemeRowWithFooterModifier {
func body(content: Content) -> some View {
content
// omit footer on iOS/tvOS, use ThemeSectionWithHeaderFooterModifier
}
}

// MARK: - Views

extension ThemeTextField {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ extension View {
modifier(ThemeSectionWithHeaderFooterModifier(header: header, footer: footer))
}

public func themeRow(footer: String? = nil) -> some View {
modifier(ThemeRowWithFooterModifier(footer: footer))
}

public func themeNavigationDetail() -> some View {
#if os(iOS)
navigationBarTitleDisplayMode(.inline)
Expand Down Expand Up @@ -290,6 +294,10 @@ struct ThemeSectionWithHeaderFooterModifier: ViewModifier {
let footer: String?
}

struct ThemeRowWithFooterModifier: ViewModifier {
let footer: String?
}

#if !os(tvOS)

struct ThemeWindowModifier: ViewModifier {
Expand Down

0 comments on commit d0dff1c

Please sign in to comment.