@@ -8,21 +8,35 @@ import SwiftUI
8
8
public struct ActivityAlertView : UIViewControllerRepresentable {
9
9
10
10
/// 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 >
12
12
/// The header text of the presented alert
13
- public let title : String ?
13
+ public let title : Binding < String > ?
14
14
/// The body text of the presented alert
15
- public let message : String ?
15
+ public let message : Binding < String > ?
16
16
/// 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
+ }
18
32
19
33
public func makeCoordinator( ) -> UIAlertController {
20
34
var insets : UIEdgeInsets ?
21
35
if let padding = padding {
22
36
insets = UIEdgeInsets ( top: padding. top, left: padding. leading, bottom: padding. bottom, right: padding. trailing)
23
37
}
24
38
25
- return UIAlertController . makeActivityAlert ( title: title, message: message, padding: insets)
39
+ return UIAlertController . makeActivityAlert ( title: title? . wrappedValue , message: message? . wrappedValue , padding: insets)
26
40
}
27
41
28
42
public func makeUIViewController( context: Context ) -> some UIViewController {
@@ -31,9 +45,14 @@ public struct ActivityAlertView: UIViewControllerRepresentable {
31
45
32
46
public func updateUIViewController( _ uiViewController: UIViewControllerType , context: Context ) {
33
47
let alertController = context. coordinator
34
- switch ( isPresented, uiViewController. presentedViewController) {
48
+ switch ( isPresented. wrappedValue , uiViewController. presentedViewController) {
35
49
case ( true , nil ) :
50
+ alertController. title = title? . wrappedValue
51
+ alertController. message = message? . wrappedValue
36
52
uiViewController. present ( alertController, animated: true )
53
+ case ( true , _) :
54
+ alertController. title = title? . wrappedValue
55
+ alertController. message = message? . wrappedValue
37
56
case ( false , alertController) :
38
57
alertController. dismiss ( animated: true )
39
58
default :
0 commit comments