@@ -7,48 +7,55 @@ final class StorePickerErrorHostingController: UIHostingController<StorePickerEr
77
88 /// Creates an `StorePickerErrorHostingController` with preconfigured button actions.
99 ///
10- static func createWithActions( presentingViewController: UIViewController ) -> StorePickerErrorHostingController {
11- . init(
12- troubleshootingAction: {
13- let safariViewController = SFSafariViewController ( url: WooConstants . URLs. troubleshootErrorLoadingData. asURL ( ) )
14- presentingViewController. present ( safariViewController, animated: true )
15- } ,
16- contactSupportAction: {
17- ZendeskManager . shared. showNewRequestIfPossible ( from: presentingViewController)
18- } ,
19- dismissAction: {
20- presentingViewController. dismiss ( animated: true )
10+ static func createWithActions( presenting: UIViewController ) -> StorePickerErrorHostingController {
11+ let viewController = StorePickerErrorHostingController ( )
12+ viewController. setActions ( troubleshootingAction: {
13+ let safariViewController = SFSafariViewController ( url: WooConstants . URLs. troubleshootErrorLoadingData. asURL ( ) )
14+ viewController. present ( safariViewController, animated: true )
15+ } ,
16+ contactSupportAction: {
17+ presenting. dismiss ( animated: true ) {
18+ ZendeskManager . shared. showNewRequestIfPossible ( from: presenting)
2119 }
22- )
20+ } ,
21+ dismissAction: {
22+ presenting. dismiss ( animated: true )
23+ } )
24+ return viewController
2325 }
2426
25- init ( troubleshootingAction: @escaping ( ) -> Void , contactSupportAction: @escaping ( ) -> Void , dismissAction: @escaping ( ) -> Void ) {
26- super. init ( rootView: StorePickerError ( troubleshootingAction: troubleshootingAction,
27- contactSupportAction: contactSupportAction,
28- dismissAction: dismissAction) )
27+ init ( ) {
28+ super. init ( rootView: StorePickerError ( ) )
2929 }
3030
3131 required dynamic init ? ( coder aDecoder: NSCoder ) {
3232 fatalError ( " init(coder:) has not been implemented " )
3333 }
34- }
3534
35+ /// Actions are set in a separate function because most of the time, they will require to access `self` to be able to present new view controllers.
36+ ///
37+ func setActions( troubleshootingAction: @escaping ( ) -> Void , contactSupportAction: @escaping ( ) -> Void , dismissAction: @escaping ( ) -> Void ) {
38+ self . rootView. troubleshootingAction = troubleshootingAction
39+ self . rootView. contactSupportAction = contactSupportAction
40+ self . rootView. dismissAction = dismissAction
41+ }
42+ }
3643
3744/// Generic Store Picker error view that allows the user to contact support.
3845///
3946struct StorePickerError : View {
4047
4148 /// Closure invoked when the "Troubleshooting" button is pressed
4249 ///
43- let troubleshootingAction : ( ) -> Void
50+ var troubleshootingAction : ( ) -> Void = { }
4451
4552 /// Closure invoked when the "Contact Support" button is pressed
4653 ///
47- let contactSupportAction : ( ) -> Void
54+ var contactSupportAction : ( ) -> Void = { }
4855
4956 /// Closure invoked when the "Back To Sites" button is pressed
5057 ///
51- let dismissAction : ( ) -> Void
58+ var dismissAction : ( ) -> Void = { }
5259
5360 var body : some View {
5461 VStack ( alignment: . center, spacing: Layout . mainVerticalSpacing) {
@@ -113,14 +120,14 @@ private extension StorePickerError {
113120struct StorePickerError_Preview : PreviewProvider {
114121 static var previews : some View {
115122 VStack {
116- StorePickerError ( troubleshootingAction : { } , contactSupportAction : { } , dismissAction : { } )
123+ StorePickerError ( )
117124 }
118125 . padding ( )
119126 . background ( Color . gray)
120127 . previewLayout ( . sizeThatFits)
121128
122129 VStack {
123- StorePickerError ( troubleshootingAction : { } , contactSupportAction : { } , dismissAction : { } )
130+ StorePickerError ( )
124131 }
125132 . padding ( )
126133 . background ( Color . gray)
0 commit comments