Skip to content

Commit

Permalink
Merge pull request #4 from teufelaudio/CustomTitle
Browse files Browse the repository at this point in the history
add ability to hide internal navigation title
  • Loading branch information
OguzYuuksel authored Oct 29, 2024
2 parents d90f089 + 9ea86f9 commit f83084a
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions Sources/AcknowList/AcknowListSwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extension Acknow: Identifiable {
/// View that displays a list of acknowledgements.
@available(iOS 13.0.0, macOS 10.15.0, watchOS 7.0.0, tvOS 13.0.0, *)
public struct AcknowListSwiftUIView: View {
@Environment(\._isAcknowListSwiftUIViewNavigationTitleHidden) private var isAcknowListSwiftUIViewNavigationTitleHidden

/// The represented array of `Acknow`.
public var acknowledgements: [Acknow] = []
Expand Down Expand Up @@ -81,19 +82,21 @@ public struct AcknowListSwiftUIView: View {

public var body: some View {
#if os(iOS) || os(tvOS)
List {

Section(header: HeaderFooter(text: headerText), footer: HeaderFooter(text: footerText)) {
ForEach (acknowledgements) { acknowledgement in
NavigationLink(destination: AcknowSwiftUIView(acknowledgement: acknowledgement)) {
Text(acknowledgement.title)
}
}
}
if isAcknowListSwiftUIViewNavigationTitleHidden {
list
.listStyle(GroupedListStyle())
} else {
list
.listStyle(GroupedListStyle())
.navigationBarTitle(Text(AcknowLocalization.localizedTitle()))
}
.listStyle(GroupedListStyle())
.navigationBarTitle(Text(AcknowLocalization.localizedTitle()))
#else
list
#endif
}

@ViewBuilder
private var list: some View {
List {
Section(header: HeaderFooter(text: headerText), footer: HeaderFooter(text: footerText)) {
ForEach (acknowledgements) { acknowledgement in
Expand All @@ -103,7 +106,11 @@ public struct AcknowListSwiftUIView: View {
}
}
}
#endif
}

@ViewBuilder
public func navigationTitle(isHidden: Bool) -> some View {
environment(\._isAcknowListSwiftUIViewNavigationTitleHidden, isHidden)
}
}

Expand Down Expand Up @@ -149,3 +156,15 @@ struct AcknowListSwiftUI_Previews: PreviewProvider {
.previewDevice(PreviewDevice(rawValue: "Mac"))
}
}

// MARK: - Style
private struct _IsAcknowListSwiftUIViewNavigationTitleHiddenEnvironmentKey: EnvironmentKey {
fileprivate static let defaultValue: Bool = false
}

extension EnvironmentValues {
fileprivate var _isAcknowListSwiftUIViewNavigationTitleHidden: Bool {
get { self[_IsAcknowListSwiftUIViewNavigationTitleHiddenEnvironmentKey.self] }
set { self[_IsAcknowListSwiftUIViewNavigationTitleHiddenEnvironmentKey.self] = newValue }
}
}

0 comments on commit f83084a

Please sign in to comment.