Skip to content

Commit f410460

Browse files
committed
Public Initializers on ActivityAlertView
1 parent 2c355b1 commit f410460

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

Sources/CodeQuickKit/SwiftUI/ActivityAlertView.swift

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,35 @@ import SwiftUI
88
public struct ActivityAlertView: UIViewControllerRepresentable {
99

1010
/// A binding to a Boolean value that determines whether to present the view.
11-
@Binding public var isPresented: Bool
11+
public let isPresented: Binding<Bool>
1212
/// The header text of the presented alert
13-
public let title: String?
13+
public let title: Binding<String>?
1414
/// The body text of the presented alert
15-
public let message: String?
15+
public let message: Binding<String>?
1616
/// Inset values that should be used in place of defaults.
17-
public var padding: EdgeInsets? = nil
17+
public let padding: EdgeInsets?
18+
19+
public init(isPresented: Binding<Bool>, title: String?, message: String?, padding: EdgeInsets? = nil) {
20+
self.isPresented = isPresented
21+
self.title = (title != nil) ? .constant(title!) : nil
22+
self.message = (message != nil) ? .constant(message!) : nil
23+
self.padding = padding
24+
}
25+
26+
public init(isPresented: Binding<Bool>, title: Binding<String>? = nil, message: Binding<String>? = nil, padding: EdgeInsets? = nil) {
27+
self.isPresented = isPresented
28+
self.title = title
29+
self.message = message
30+
self.padding = padding
31+
}
1832

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

25-
return UIAlertController.makeActivityAlert(title: title, message: message, padding: insets)
39+
return UIAlertController.makeActivityAlert(title: title?.wrappedValue, message: message?.wrappedValue, padding: insets)
2640
}
2741

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

3246
public func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
3347
let alertController = context.coordinator
34-
switch (isPresented, uiViewController.presentedViewController) {
48+
switch (isPresented.wrappedValue, uiViewController.presentedViewController) {
3549
case (true, nil):
50+
alertController.title = title?.wrappedValue
51+
alertController.message = message?.wrappedValue
3652
uiViewController.present(alertController, animated: true)
53+
case (true, _):
54+
alertController.title = title?.wrappedValue
55+
alertController.message = message?.wrappedValue
3756
case (false, alertController):
3857
alertController.dismiss(animated: true)
3958
default:

Tests/CodeQuickKitTests/Foundation/DateTests.swift

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,14 @@ class DateTests: XCTestCase {
4444
XCTAssertTrue(now.isSame(today))
4545
}
4646

47-
func testLastWeek() {
47+
func testLastWeek() throws {
4848
let now = Date()
4949
let lastWeek = Date.lastWeek
5050

5151
XCTAssertTrue(lastWeek.isBefore(now))
5252

53-
let offset = TimeZone.current.daylightSavingTimeOffset(for: lastWeek)
54-
let minutesToToday = 10080 + Int(offset / 60)
55-
56-
guard let today = lastWeek.dateByAdding(minutes: minutesToToday) else {
57-
XCTFail()
58-
return
59-
}
53+
let minutesToToday = 60 * 24 * 7
54+
let today = try XCTUnwrap(lastWeek.dateByAdding(minutes: minutesToToday))
6055

6156
XCTAssertTrue(today.isAfter(lastWeek))
6257
XCTAssertTrue(now.isSame(today))
@@ -92,16 +87,13 @@ class DateTests: XCTestCase {
9287
XCTAssertTrue(now.isSame(today))
9388
}
9489

95-
func testNextWeek() {
90+
func testNextWeek() throws {
9691
let now = Date()
9792
let nextWeek = Date.nextWeek
9893

9994
XCTAssertTrue(nextWeek.isAfter(now))
10095

101-
guard let today = nextWeek.dateByAdding(minutes: -10080) else {
102-
XCTFail()
103-
return
104-
}
96+
let today = try XCTUnwrap(nextWeek.dateByAdding(days: -7))
10597

10698
XCTAssertTrue(today.isBefore(nextWeek))
10799
XCTAssertTrue(now.isSame(today))

0 commit comments

Comments
 (0)