@@ -26,35 +26,41 @@ public struct WidgetNavigator {
26
26
// dismissible functionality
27
27
28
28
/// Pushes the widget onto the navigation stack in a new UIWidgetHostController.
29
- public func push( widget: Widget , animated: Bool = true ) {
29
+ public func push( _ widget: Widget , animated: Bool = true ) {
30
30
let context = self . context. set ( presentation: . pushed)
31
31
let viewController = UIWidgetHostController ( widget, with: context)
32
32
navigationController? . pushViewController ( viewController, animated: animated)
33
33
}
34
34
35
35
/// Pushes the widget onto the navigation stack in a new UIWidgetHostController with a return value handler.
36
- public func push< ReturnType> ( widget: Widget , animated: Bool = true , onDismiss handler: @escaping WidgetDismissibleReturnHandler < ReturnType > ) {
36
+ public func push< ReturnType> ( _ widget: Widget , animated: Bool = true , onDismiss handler: @escaping WidgetDismissibleReturnHandler < ReturnType > ) {
37
37
let context = self . context. set ( presentation: . pushed)
38
38
let dismissible = WidgetDismissibleReturn < ReturnType > ( handler)
39
39
let viewController = UIWidgetHostController ( widget, with: context, dismissible: dismissible)
40
40
navigationController? . pushViewController ( viewController, animated: animated)
41
41
}
42
42
43
43
/// Presents a widget on the navigation stack in a new UIWidgetHostController.
44
- public func present( widget: Widget , animated: Bool = true ) {
44
+ public func present( _ widget: Widget , animated: Bool = true ) {
45
45
let context = self . context. set ( presentation: . presented)
46
46
let viewController = UIWidgetHostController ( widget, with: context)
47
47
navigationController? . present ( viewController, animated: animated, completion: nil )
48
48
}
49
49
50
50
/// Presents a widget on the navigation stack in a new UIWidgetHostController with a return value handler.
51
- public func present< ReturnType> ( widget: Widget , animated: Bool = true , onDismiss handler: @escaping WidgetDismissibleReturnHandler < ReturnType > ) {
51
+ public func present< ReturnType> ( _ widget: Widget , animated: Bool = true , onDismiss handler: @escaping WidgetDismissibleReturnHandler < ReturnType > ) {
52
52
let context = self . context. set ( presentation: . presented)
53
53
let dismissible = WidgetDismissibleReturn < ReturnType > ( handler)
54
54
let viewController = UIWidgetHostController ( widget, with: context, dismissible: dismissible)
55
55
navigationController? . present ( viewController, animated: animated, completion: nil )
56
56
}
57
57
58
+ public func present( _ widget: WidgetController , animated: Bool = true ) {
59
+ let context = self . context. set ( presentation: . alert)
60
+ let viewController = widget. build ( with: context)
61
+ navigationController? . present ( viewController, animated: animated, completion: nil )
62
+ }
63
+
58
64
/// Pops or dismisses the current view controller, returning a value that will be passed to the onDismiss handler.
59
65
public func dismiss< Value> ( returning value: Value , animated: Bool = true ) {
60
66
if let dimissible = context. dismissible as? WidgetDismissibleReturn < Value > {
@@ -69,7 +75,7 @@ public struct WidgetNavigator {
69
75
return
70
76
}
71
77
switch self . context. presentation {
72
- case . presented:
78
+ case . alert , . presented, . sheet :
73
79
viewController. dismiss ( animated: animated, completion: nil )
74
80
case . pushed:
75
81
viewController. navigationController? . popToViewController ( viewController, animated: false )
0 commit comments