|
| 1 | +import SwiftUI |
| 2 | + |
| 3 | +/// Hosting controller wrapper for `StorePickerError` |
| 4 | +/// |
| 5 | +final class StorePickerErrorHostingController: UIHostingController<StorePickerError> { |
| 6 | + init() { |
| 7 | + super.init(rootView: StorePickerError()) |
| 8 | + } |
| 9 | + |
| 10 | + required dynamic init?(coder aDecoder: NSCoder) { |
| 11 | + fatalError("init(coder:) has not been implemented") |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | + |
| 16 | +/// Generic Store Picker error view that allows the user to contact support. |
| 17 | +/// |
| 18 | +struct StorePickerError: View { |
| 19 | + var body: some View { |
| 20 | + VStack(alignment: .center, spacing: Layout.mainVerticalSpacing) { |
| 21 | + // Title |
| 22 | + Text(Localization.title) |
| 23 | + .headlineStyle() |
| 24 | + |
| 25 | + // Main image |
| 26 | + Image(uiImage: .errorImage) |
| 27 | + |
| 28 | + // Body text |
| 29 | + Text(Localization.body) |
| 30 | + .multilineTextAlignment(.center) |
| 31 | + .bodyStyle() |
| 32 | + |
| 33 | + VStack(spacing: Layout.buttonsSpacing) { |
| 34 | + // Primary Button |
| 35 | + Button(Localization.troubleshoot) { |
| 36 | + print("Troubleshooting Tips tapped") |
| 37 | + } |
| 38 | + .buttonStyle(PrimaryButtonStyle()) |
| 39 | + |
| 40 | + // Secondary button |
| 41 | + Button(Localization.contact) { |
| 42 | + print("Contact support tapped") |
| 43 | + } |
| 44 | + .buttonStyle(SecondaryButtonStyle()) |
| 45 | + |
| 46 | + // Dismiss button |
| 47 | + Button(Localization.back) { |
| 48 | + print("Back to site") |
| 49 | + } |
| 50 | + .buttonStyle(LinkButtonStyle()) |
| 51 | + } |
| 52 | + } |
| 53 | + .padding([.leading, .trailing, .bottom]) |
| 54 | + .padding(.top, Layout.topPadding) |
| 55 | + .background(Color(.tertiarySystemBackground)) |
| 56 | + .cornerRadius(Layout.rounderCorners) |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +// MARK: Constant |
| 61 | + |
| 62 | +private extension StorePickerError { |
| 63 | + enum Localization { |
| 64 | + static let title = NSLocalizedString("We couldn't load your site", comment: "Title for the default store picker error screen") |
| 65 | + static let body = NSLocalizedString("Please try again or reach out to us and we'll be happy to assist you!", |
| 66 | + comment: "Body text for the default store picker error screen") |
| 67 | + static let troubleshoot = NSLocalizedString("Read our Troubleshooting Tips", |
| 68 | + comment: "Text for the button to navigate to troubleshooting tips from the store picker error screen") |
| 69 | + static let contact = NSLocalizedString("Contact Support", |
| 70 | + comment: "Text for the button to contact support from the store picker error screen") |
| 71 | + static let back = NSLocalizedString("Back to Sites", |
| 72 | + comment: "Text for the button to dismiss the store picker error screen") |
| 73 | + } |
| 74 | + |
| 75 | + enum Layout { |
| 76 | + static let rounderCorners: CGFloat = 10 |
| 77 | + static let mainVerticalSpacing: CGFloat = 25 |
| 78 | + static let buttonsSpacing: CGFloat = 15 |
| 79 | + static let topPadding: CGFloat = 30 |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +// MARK: Previews |
| 84 | + |
| 85 | +struct StorePickerError_Preview: PreviewProvider { |
| 86 | + static var previews: some View { |
| 87 | + VStack { |
| 88 | + StorePickerError() |
| 89 | + } |
| 90 | + .padding() |
| 91 | + .background(Color.gray) |
| 92 | + .previewLayout(.sizeThatFits) |
| 93 | + |
| 94 | + VStack { |
| 95 | + StorePickerError() |
| 96 | + } |
| 97 | + .padding() |
| 98 | + .background(Color.gray) |
| 99 | + .environment(\.colorScheme, .dark) |
| 100 | + .previewLayout(.sizeThatFits) |
| 101 | + } |
| 102 | +} |
0 commit comments