|
| 1 | +import SwiftUI |
| 2 | + |
| 3 | +/// Hosting controller that wraps the `StoreCreationSuccessView`. |
| 4 | +final class StoreCreationSuccessHostingController: UIHostingController<StoreCreationSuccessView> { |
| 5 | + private let onContinue: () -> Void |
| 6 | + |
| 7 | + init(siteURL: URL, |
| 8 | + onContinue: @escaping () -> Void) { |
| 9 | + self.onContinue = onContinue |
| 10 | + super.init(rootView: StoreCreationSuccessView(siteURL: siteURL)) |
| 11 | + |
| 12 | + rootView.onContinue = { [weak self] in |
| 13 | + self?.onContinue() |
| 14 | + } |
| 15 | + } |
| 16 | + |
| 17 | + @available(*, unavailable) |
| 18 | + required dynamic init?(coder aDecoder: NSCoder) { |
| 19 | + fatalError("init(coder:) has not been implemented") |
| 20 | + } |
| 21 | + |
| 22 | + override func viewDidLoad() { |
| 23 | + super.viewDidLoad() |
| 24 | + |
| 25 | + configureNavigationBarAppearance() |
| 26 | + } |
| 27 | + |
| 28 | + /// Shows a transparent navigation bar without a bottom border and with a close button to dismiss. |
| 29 | + func configureNavigationBarAppearance() { |
| 30 | + let appearance = UINavigationBarAppearance() |
| 31 | + appearance.configureWithTransparentBackground() |
| 32 | + appearance.backgroundColor = .systemBackground |
| 33 | + |
| 34 | + navigationItem.standardAppearance = appearance |
| 35 | + navigationItem.scrollEdgeAppearance = appearance |
| 36 | + navigationItem.compactAppearance = appearance |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +struct StoreCreationSuccessView: View { |
| 41 | + /// Set in the hosting controller. |
| 42 | + var onContinue: () -> Void = {} |
| 43 | + |
| 44 | + /// URL of the newly created site. |
| 45 | + let siteURL: URL |
| 46 | + |
| 47 | + // Tracks the scale of the view due to accessibility changes. |
| 48 | + @ScaledMetric private var scale: CGFloat = 1.0 |
| 49 | + |
| 50 | + @State private var isPresentingWebview: Bool = false |
| 51 | + |
| 52 | + var body: some View { |
| 53 | + ScrollView { |
| 54 | + VStack(alignment: .center, spacing: 33) { |
| 55 | + // Title label. |
| 56 | + Text(Localization.title) |
| 57 | + .fontWeight(.bold) |
| 58 | + .titleStyle() |
| 59 | + |
| 60 | + // Readonly webview for the new site. |
| 61 | + WebView(isPresented: .constant(true), url: siteURL) |
| 62 | + .frame(height: 400 * scale) |
| 63 | + .disabled(true) |
| 64 | + .border(Color(.systemBackground), width: 8) |
| 65 | + .cornerRadius(8) |
| 66 | + .shadow(color: Color(.secondaryLabel), radius: 26) |
| 67 | + .padding(.horizontal, insets: Layout.webviewHorizontalPadding) |
| 68 | + } |
| 69 | + .padding(Layout.contentPadding) |
| 70 | + } |
| 71 | + .safeAreaInset(edge: .bottom) { |
| 72 | + VStack(spacing: 0) { |
| 73 | + Divider() |
| 74 | + .frame(height: 1) |
| 75 | + .foregroundColor(Color(.separator)) |
| 76 | + |
| 77 | + VStack(spacing: 16) { |
| 78 | + // Continue button. |
| 79 | + Button(Localization.continueButtonTitle) { |
| 80 | + onContinue() |
| 81 | + } |
| 82 | + .buttonStyle(PrimaryButtonStyle()) |
| 83 | + |
| 84 | + // Preview button. |
| 85 | + Button(Localization.previewButtonTitle) { |
| 86 | + isPresentingWebview = true |
| 87 | + } |
| 88 | + .buttonStyle(SecondaryButtonStyle()) |
| 89 | + } |
| 90 | + .padding(insets: Layout.buttonContainerPadding) |
| 91 | + } |
| 92 | + .background(Color(.systemBackground)) |
| 93 | + } |
| 94 | + .safariSheet(isPresented: $isPresentingWebview, url: siteURL) |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +private extension StoreCreationSuccessView { |
| 99 | + enum Layout { |
| 100 | + static let contentPadding: EdgeInsets = .init(top: 38, leading: 16, bottom: 16, trailing: 16) |
| 101 | + static let buttonContainerPadding: EdgeInsets = .init(top: 16, leading: 16, bottom: 16, trailing: 16) |
| 102 | + static let webviewHorizontalPadding: EdgeInsets = .init(top: 0, leading: 44, bottom: 0, trailing: 44) |
| 103 | + } |
| 104 | + |
| 105 | + enum Localization { |
| 106 | + static let title = NSLocalizedString( |
| 107 | + "Your store has been created!", |
| 108 | + comment: "Title of the store creation success screen." |
| 109 | + ) |
| 110 | + static let continueButtonTitle = NSLocalizedString( |
| 111 | + "Manage My Store", |
| 112 | + comment: "Title of the primary button on the store creation success screen to continue to the newly created store." |
| 113 | + ) |
| 114 | + static let previewButtonTitle = NSLocalizedString( |
| 115 | + "Store Preview", |
| 116 | + comment: "Title of the secondary button on the store creation success screen to preview the newly created store." |
| 117 | + ) |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +struct StoreCreationSuccessView_Previews: PreviewProvider { |
| 122 | + static var previews: some View { |
| 123 | + StoreCreationSuccessView(siteURL: URL(string: "https://woocommerce.com")!) |
| 124 | + StoreCreationSuccessView(siteURL: URL(string: "https://woocommerce.com")!) |
| 125 | + .preferredColorScheme(.dark) |
| 126 | + } |
| 127 | +} |
0 commit comments