Skip to content

Commit

Permalink
Merge pull request #126 from tisfeng/feat-load-default-acknow
Browse files Browse the repository at this point in the history
feat: load default acknow list when init AcknowListSwiftUIView
  • Loading branch information
vtourraine authored Jan 6, 2025
2 parents 0144297 + 920cf5f commit 972d00a
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 3.3.0 (work in progress)

- Add initializer to `AcknowListSwiftUI` to load default acknow list, by Tisfeng (@tisfeng)


## 3.2.0 (11 June 2024)

- Add visionOS support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
031D428A2CDA828C00C803B8 /* Package.resolved in Resources */ = {isa = PBXBuildFile; fileRef = 031D42892CDA828C00C803B8 /* Package.resolved */; };
BB29000228230B37002FF5C4 /* Package-version-1.resolved in Resources */ = {isa = PBXBuildFile; fileRef = BB29000128230B37002FF5C4 /* Package-version-1.resolved */; };
D7527E2125CADE4E00378FB8 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7527E2025CADE4E00378FB8 /* AppDelegate.swift */; };
D7527E2325CADE4E00378FB8 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7527E2225CADE4E00378FB8 /* SceneDelegate.swift */; };
Expand All @@ -18,6 +19,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
031D42892CDA828C00C803B8 /* Package.resolved */ = {isa = PBXFileReference; lastKnownFileType = text; name = Package.resolved; path = "../../../Tests/AcknowListTests/Resources/Package.resolved"; sourceTree = "<group>"; };
BB29000128230B37002FF5C4 /* Package-version-1.resolved */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "Package-version-1.resolved"; path = "../../../Tests/AcknowListTests/Resources/Package-version-1.resolved"; sourceTree = "<group>"; };
D7527E1D25CADE4E00378FB8 /* AcknowExampleSPM.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AcknowExampleSPM.app; sourceTree = BUILT_PRODUCTS_DIR; };
D7527E2025CADE4E00378FB8 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -73,6 +75,7 @@
D7527E2B25CADE5000378FB8 /* LaunchScreen.storyboard */,
D7527E2E25CADE5000378FB8 /* Info.plist */,
BB29000128230B37002FF5C4 /* Package-version-1.resolved */,
031D42892CDA828C00C803B8 /* Package.resolved */,
);
path = AcknowExampleSPM;
sourceTree = "<group>";
Expand Down Expand Up @@ -146,6 +149,7 @@
buildActionMask = 2147483647;
files = (
D7527E2D25CADE5000378FB8 /* LaunchScreen.storyboard in Resources */,
031D428A2CDA828C00C803B8 /* Package.resolved in Resources */,
BB29000228230B37002FF5C4 /* Package-version-1.resolved in Resources */,
D7527E2A25CADE5000378FB8 /* Assets.xcassets in Resources */,
D7527E2825CADE4E00378FB8 /* Main.storyboard in Resources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ class ViewController: UIViewController {
}

@IBAction func presentAcknowledgementsSwiftUI(_ sender: AnyObject) {
let listViewController = AcknowListSwiftUIView(acknowledgements: [
Acknow(title: "Test", text: "Bla bla"),
Acknow(title: "Test URL", repository: URL(string: "https://developer.apple.com")),
Acknow(title: "Test GitHub", repository: URL(string: "https://github.com/vtourraine/AcknowList.git"))
])
// Load default acknowledgements from CocoaPods and Swift Package Manager
let listViewController = AcknowListSwiftUIView()
let viewController = UIHostingController(rootView: listViewController)
let navigationController = UINavigationController(rootViewController: viewController)
present(navigationController, animated: true, completion: nil)
Expand Down
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ let package = Package(
.copy("Resources/RegexTesting-GroundTruth-TPKeyboardAvoiding.txt"),
.copy("Resources/RegexTesting-GroundTruth-pop.txt"),
.copy("Resources/Package-version-1.resolved"),
.copy("Resources/Package-version-2.resolved")]
.copy("Resources/Package-version-2.resolved"),
.copy("Resources/Package.resolved"),
]
),
],
swiftLanguageVersions: [.v5]
Expand Down
37 changes: 25 additions & 12 deletions Sources/AcknowList/AcknowListSwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import SwiftUI

extension Acknow: Identifiable {
public var id: String {
get {
title
}
title
}
}

Expand All @@ -44,6 +42,19 @@ public struct AcknowListSwiftUIView: View {
/// Footer text to be displayed below the list of the acknowledgements.
public var footerText: String?

public init() {
if let acknowList = AcknowParser.defaultAcknowList() {
self.init(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: [])
}
}

public init(acknowList: AcknowList) {
acknowledgements = acknowList.acknowledgements
headerText = acknowList.headerText
Expand Down Expand Up @@ -88,25 +99,25 @@ public struct AcknowListSwiftUIView: View {
}

public var body: some View {
#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS)
List {
Section(header: HeaderFooter(text: headerText), footer: HeaderFooter(text: footerText)) {
ForEach (acknowledgements) { acknowledgement in
ForEach(acknowledgements) { acknowledgement in
AcknowListRowSwiftUIView(acknowledgement: acknowledgement)
}
}
}
.listStyle(GroupedListStyle())
.navigationBarTitle(Text(AcknowLocalization.localizedTitle()))
#else
#else
List {
Section(header: HeaderFooter(text: headerText), footer: HeaderFooter(text: footerText)) {
ForEach (acknowledgements) { acknowledgement in
ForEach(acknowledgements) { acknowledgement in
AcknowListRowSwiftUIView(acknowledgement: acknowledgement)
}
}
}
#endif
#endif
}
}

Expand Down Expand Up @@ -170,9 +181,11 @@ struct AcknowListSwiftUI_Previews: PreviewProvider {
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
static let acks = [Acknow(title: "Title 1", text: license),
Acknow(title: "Title 2", text: license),
Acknow(title: "Title 3", text: license)]
static let acks = [
Acknow(title: "Title 1", text: license),
Acknow(title: "Title 2", text: license),
Acknow(title: "Title 3", text: license),
]

static var previews: some View {
NavigationView {
Expand All @@ -184,7 +197,7 @@ struct AcknowListSwiftUI_Previews: PreviewProvider {
AcknowListSwiftUIView(acknowledgements: acks, headerText: "Test Header", footerText: "Test Footer")
}
.previewDevice(PreviewDevice(rawValue: "iPhone 12"))

NavigationView {
AcknowListSwiftUIView(acknowledgements: acks, headerText: "Test Header", footerText: "Test Footer")
}
Expand Down
61 changes: 61 additions & 0 deletions Tests/AcknowListTests/Resources/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"object": {
"pins": [
{
"package": "AcknowList",
"repositoryURL": "https://github.com/vtourraine/AcknowList.git",
"state": {
"branch": null,
"revision": "e66b9541c1902ced4979b3c214a5def2cf96f015",
"version": "2.1.0"
}
},
{
"package": "AMGAppButton",
"repositoryURL": "https://github.com/studioamanga/AMGAppButton.git",
"state": {
"branch": null,
"revision": "6044b277a3a4281afb1fdf6f651fa4829109d7d9",
"version": "1.1.0"
}
},
{
"package": "SVProgressHUD",
"repositoryURL": "https://github.com/epitonium/SVProgressHUD.git",
"state": {
"branch": null,
"revision": "3580cb55f351d83f861f52362aa38305f663f88d",
"version": "1.0.0"
}
},
{
"package": "TrackupCore",
"repositoryURL": "https://github.com/vtourraine/Trackup.git",
"state": {
"branch": null,
"revision": "513e0bf40b6d005354c844446e8e2334c450a863",
"version": "0.1.0"
}
},
{
"package": "TrackupVersionHistory",
"repositoryURL": "https://github.com/vtourraine/TrackupVersionHistory.git",
"state": {
"branch": null,
"revision": "7916b78a3cd5392b5807220277f3aa1d561c1658",
"version": "0.2.0"
}
},
{
"package": "VTAppButton",
"repositoryURL": "https://github.com/vtourraine/VTAppButton.git",
"state": {
"branch": null,
"revision": "3eeb59199d563d7e0ac35ebb0bf967defa878391",
"version": "1.1.0"
}
}
]
},
"version": 1
}

0 comments on commit 972d00a

Please sign in to comment.