Skip to content
Closed
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
28 changes: 19 additions & 9 deletions Sources/AcknowList/AcknowListSwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ 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, visionOS 1.0.0, *)
public struct AcknowListSwiftUIView: View {

/// Navigation title
public var navigationTitle: String = AcknowLocalization.localizedTitle()

/// The represented array of `Acknow`.
public var acknowledgements: [Acknow] = []
Expand All @@ -43,35 +46,42 @@ public struct AcknowListSwiftUIView: View {
/// Footer text to be displayed below the list of the acknowledgements.
public var footerText: String?

public init() {
public init(navigationTitle: String = AcknowLocalization.localizedTitle()) {
if let acknowList = AcknowParser.defaultAcknowList() {
self.init(acknowList: acknowList)
self.init(navigationTitle: navigationTitle, acknowList: acknowList)
}
else {
print(
"** AcknowList Warning **\n" +
"No acknowledgements found.\n" +
"Please take a look at https://github.com/vtourraine/AcknowList for instructions.", terminator: "\n")
self.init(acknowledgements: [])
self.init(navigationTitle: navigationTitle, acknowledgements: [])
}
}

public init(acknowList: AcknowList) {
public init(navigationTitle: String = AcknowLocalization.localizedTitle(),
acknowList: AcknowList) {
self.navigationTitle = navigationTitle
acknowledgements = acknowList.acknowledgements
headerText = acknowList.headerText
footerText = acknowList.footerText
}

public init(acknowledgements: [Acknow], headerText: String? = nil, footerText: String? = nil) {
public init(navigationTitle: String = AcknowLocalization.localizedTitle(),
acknowledgements: [Acknow],
headerText: String? = nil,
footerText: String? = nil) {
self.navigationTitle = navigationTitle
self.acknowledgements = acknowledgements
self.headerText = headerText
self.footerText = footerText
}

public init(plistFileURL: URL) {
public init(navigationTitle: String = AcknowLocalization.localizedTitle(),
plistFileURL: URL) {
guard let data = try? Data(contentsOf: plistFileURL),
let acknowList = try? AcknowPodDecoder().decode(from: data) else {
self.init(acknowledgements: [], headerText: nil, footerText: nil)
self.init(navigationTitle: navigationTitle, acknowledgements: [], headerText: nil, footerText: nil)
return
}

Expand All @@ -83,7 +93,7 @@ public struct AcknowListSwiftUIView: View {
header = nil
}

self.init(acknowledgements: acknowList.acknowledgements, headerText: header, footerText: acknowList.footerText)
self.init(navigationTitle: navigationTitle, acknowledgements: acknowList.acknowledgements, headerText: header, footerText: acknowList.footerText)
}

struct HeaderFooter: View {
Expand Down Expand Up @@ -112,7 +122,7 @@ public struct AcknowListSwiftUIView: View {
public var body: some View {
#if os(iOS) || os(tvOS)
acknowListContent
.navigationBarTitle(Text(AcknowLocalization.localizedTitle()))
.navigationBarTitle(Text(navigationTitle))
#else
acknowListContent
#endif
Expand Down
Loading