@@ -3,8 +3,10 @@ import SwiftUI
33/// Hosting controller wrapper for `StorePickerError`
44///
55final class StorePickerErrorHostingController : UIHostingController < StorePickerError > {
6- init ( ) {
7- super. init ( rootView: StorePickerError ( ) )
6+ init ( troubleshootingAction: @escaping ( ) -> Void , contactSupportAction: @escaping ( ) -> Void , dismissAction: @escaping ( ) -> Void ) {
7+ super. init ( rootView: StorePickerError ( troubleshootingAction: troubleshootingAction,
8+ contactSupportAction: contactSupportAction,
9+ dismissAction: dismissAction) )
810 }
911
1012 required dynamic init ? ( coder aDecoder: NSCoder ) {
@@ -16,6 +18,19 @@ final class StorePickerErrorHostingController: UIHostingController<StorePickerEr
1618/// Generic Store Picker error view that allows the user to contact support.
1719///
1820struct StorePickerError : View {
21+
22+ /// Closure invoked when the "Troubleshooting" button is pressed
23+ ///
24+ let troubleshootingAction : ( ) -> Void
25+
26+ /// Closure invoked when the "Contact Support" button is pressed
27+ ///
28+ let contactSupportAction : ( ) -> Void
29+
30+ /// Closure invoked when the "Back To Sites" button is pressed
31+ ///
32+ let dismissAction : ( ) -> Void
33+
1934 var body : some View {
2035 VStack ( alignment: . center, spacing: Layout . mainVerticalSpacing) {
2136 // Title
@@ -32,22 +47,16 @@ struct StorePickerError: View {
3247
3348 VStack ( spacing: Layout . buttonsSpacing) {
3449 // Primary Button
35- Button ( Localization . troubleshoot) {
36- print ( " Troubleshooting Tips tapped " )
37- }
38- . buttonStyle ( PrimaryButtonStyle ( ) )
50+ Button ( Localization . troubleshoot, action: troubleshootingAction)
51+ . buttonStyle ( PrimaryButtonStyle ( ) )
3952
4053 // Secondary button
41- Button ( Localization . contact) {
42- print ( " Contact support tapped " )
43- }
44- . buttonStyle ( SecondaryButtonStyle ( ) )
54+ Button ( Localization . contact, action: contactSupportAction)
55+ . buttonStyle ( SecondaryButtonStyle ( ) )
4556
4657 // Dismiss button
47- Button ( Localization . back) {
48- print ( " Back to site " )
49- }
50- . buttonStyle ( LinkButtonStyle ( ) )
58+ Button ( Localization . back, action: dismissAction)
59+ . buttonStyle ( LinkButtonStyle ( ) )
5160 }
5261 }
5362 . padding ( [ . leading, . trailing, . bottom] )
@@ -85,14 +94,14 @@ private extension StorePickerError {
8594struct StorePickerError_Preview : PreviewProvider {
8695 static var previews : some View {
8796 VStack {
88- StorePickerError ( )
97+ StorePickerError ( troubleshootingAction : { } , contactSupportAction : { } , dismissAction : { } )
8998 }
9099 . padding ( )
91100 . background ( Color . gray)
92101 . previewLayout ( . sizeThatFits)
93102
94103 VStack {
95- StorePickerError ( )
104+ StorePickerError ( troubleshootingAction : { } , contactSupportAction : { } , dismissAction : { } )
96105 }
97106 . padding ( )
98107 . background ( Color . gray)
0 commit comments