Skip to content

ActivityAlertView Initializer #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 8, 2025
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
10 changes: 5 additions & 5 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

steps:
- name: Checkout Source
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Build (macOS)
run: swift build -v
Expand All @@ -27,20 +27,20 @@ jobs:
run: xcrun llvm-cov export -format="lcov" .build/debug/${{ env.PACKAGE_NAME }}PackageTests.xctest/Contents/MacOS/${{ env.PACKAGE_NAME }}PackageTests -instr-profile .build/debug/codecov/default.profdata > build/reports/coverage.lcov

- name: Upload Artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: test-results
path: |
build/reports/junit.xml
build/reports/coverage.lcov

- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/composite@v1
uses: EnricoMi/publish-unit-test-result-action/macos@v2
with:
files: build/reports/junit.xml

- name: Publish Code Coverage
uses: vebr/jest-lcov-reporter@v0.2.1
uses: lifeart/jest-lcov-reporter@v0.4.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
lcov-file: build/reports/coverage.lcov
Expand All @@ -51,7 +51,7 @@ jobs:

steps:
- name: Checkout Source
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Build (Ubuntu)
run: swift build -v
Expand Down
4 changes: 4 additions & 0 deletions .spi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: 1
builder:
configs:
- documentation_targets: [CodeQuickKit]
32 changes: 2 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,8 @@

A Swift library for simplifying some everyday tasks.

<p>
<img src="https://github.com/richardpiazza/CodeQuickKit/workflows/Swift/badge.svg?branch=main" />
<img src="https://img.shields.io/badge/Swift-5.5-orange.svg" />
<a href="https://twitter.com/richardpiazza">
<img src="https://img.shields.io/badge/twitter-@richardpiazza-blue.svg?style=flat" alt="Twitter: @richardpiazza" />
</a>
</p>

## 💻 Installation

This software is distributed using [Swift Package Manager](https://swift.org/package-manager).
You can add it using Xcode or by listing it as a dependency in your `Package.swift` manifest:

```swift
let package = Package(
...
dependencies: [
.package(url: "https://github.com/richardpiazza/CodeQuickKit", .upToNextMajor(from: "7.0.0")
],
...
targets: [
.target(
name: "MyPackage",
dependencies: [
"CodeQuickKit"
]
)
]
)
```
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Frichardpiazza%2FCodeQuickKit%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/richardpiazza/CodeQuickKit)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Frichardpiazza%2FCodeQuickKit%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/richardpiazza/CodeQuickKit)

## 📌 Features

Expand Down
31 changes: 25 additions & 6 deletions Sources/CodeQuickKit/SwiftUI/ActivityAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,35 @@ import SwiftUI
public struct ActivityAlertView: UIViewControllerRepresentable {

/// A binding to a Boolean value that determines whether to present the view.
@Binding public var isPresented: Bool
public let isPresented: Binding<Bool>
/// The header text of the presented alert
public let title: String?
public let title: Binding<String>?
/// The body text of the presented alert
public let message: String?
public let message: Binding<String>?
/// Inset values that should be used in place of defaults.
public var padding: EdgeInsets? = nil
public let padding: EdgeInsets?

public init(isPresented: Binding<Bool>, title: String?, message: String?, padding: EdgeInsets? = nil) {
self.isPresented = isPresented
self.title = (title != nil) ? .constant(title!) : nil
self.message = (message != nil) ? .constant(message!) : nil
self.padding = padding
}

public init(isPresented: Binding<Bool>, title: Binding<String>? = nil, message: Binding<String>? = nil, padding: EdgeInsets? = nil) {
self.isPresented = isPresented
self.title = title
self.message = message
self.padding = padding
}

public func makeCoordinator() -> UIAlertController {
var insets: UIEdgeInsets?
if let padding = padding {
insets = UIEdgeInsets(top: padding.top, left: padding.leading, bottom: padding.bottom, right: padding.trailing)
}

return UIAlertController.makeActivityAlert(title: title, message: message, padding: insets)
return UIAlertController.makeActivityAlert(title: title?.wrappedValue, message: message?.wrappedValue, padding: insets)
}

public func makeUIViewController(context: Context) -> some UIViewController {
Expand All @@ -31,9 +45,14 @@ public struct ActivityAlertView: UIViewControllerRepresentable {

public func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
let alertController = context.coordinator
switch (isPresented, uiViewController.presentedViewController) {
switch (isPresented.wrappedValue, uiViewController.presentedViewController) {
case (true, nil):
alertController.title = title?.wrappedValue
alertController.message = message?.wrappedValue
uiViewController.present(alertController, animated: true)
case (true, _):
alertController.title = title?.wrappedValue
alertController.message = message?.wrappedValue
case (false, alertController):
alertController.dismiss(animated: true)
default:
Expand Down
18 changes: 5 additions & 13 deletions Tests/CodeQuickKitTests/Foundation/DateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,14 @@ class DateTests: XCTestCase {
XCTAssertTrue(now.isSame(today))
}

func testLastWeek() {
func testLastWeek() throws {
let now = Date()
let lastWeek = Date.lastWeek

XCTAssertTrue(lastWeek.isBefore(now))

let offset = TimeZone.current.daylightSavingTimeOffset(for: lastWeek)
let minutesToToday = 10080 + Int(offset / 60)

guard let today = lastWeek.dateByAdding(minutes: minutesToToday) else {
XCTFail()
return
}
let minutesToToday = 60 * 24 * 7
let today = try XCTUnwrap(lastWeek.dateByAdding(minutes: minutesToToday))

XCTAssertTrue(today.isAfter(lastWeek))
XCTAssertTrue(now.isSame(today))
Expand Down Expand Up @@ -92,16 +87,13 @@ class DateTests: XCTestCase {
XCTAssertTrue(now.isSame(today))
}

func testNextWeek() {
func testNextWeek() throws {
let now = Date()
let nextWeek = Date.nextWeek

XCTAssertTrue(nextWeek.isAfter(now))

guard let today = nextWeek.dateByAdding(minutes: -10080) else {
XCTFail()
return
}
let today = try XCTUnwrap(nextWeek.dateByAdding(days: -7))

XCTAssertTrue(today.isBefore(nextWeek))
XCTAssertTrue(now.isSame(today))
Expand Down