-
Notifications
You must be signed in to change notification settings - Fork 121
Add product: Show celebratory view when the first product is created #9790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
f736175
4bb3afa
7512de0
a48d241
488011e
7373cc7
a1910b7
e1e2c84
d996f32
47aeb4e
32784fb
c563c0b
7debb5f
699773e
022a58f
f335c3c
be7f1ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import ConfettiSwiftUI | ||
| import SwiftUI | ||
|
|
||
| final class FirstProductCreatedHostingController: UIHostingController<FirstProductCreatedView> { | ||
| init(productURL: URL) { | ||
| super.init(rootView: FirstProductCreatedView()) | ||
| rootView.onSharingProduct = { [weak self] in | ||
| guard let self else { return } | ||
| SharingHelper.shareURL(url: productURL, from: self.view, in: self) | ||
| ServiceLocator.analytics.track(.firstCreatedProductShareTapped) | ||
| } | ||
| } | ||
|
|
||
| @available(*, unavailable) | ||
| required dynamic init?(coder aDecoder: NSCoder) { | ||
| fatalError("init(coder:) has not been implemented") | ||
| } | ||
|
|
||
| override func viewDidLoad() { | ||
| super.viewDidLoad() | ||
| configureTransparentNavigationBar() | ||
| navigationItem.leftBarButtonItem = UIBarButtonItem(title: Localization.cancel, style: .plain, target: self, action: #selector(dismissView)) | ||
| ServiceLocator.analytics.track(.firstCreatedProductShown) | ||
| } | ||
|
|
||
| @objc | ||
| private func dismissView() { | ||
| dismiss(animated: true) | ||
| } | ||
| } | ||
|
|
||
| private extension FirstProductCreatedHostingController { | ||
| enum Localization { | ||
| static let cancel = NSLocalizedString("Cancel", comment: "Button to dismiss the first created product screen") | ||
|
||
| } | ||
| } | ||
|
|
||
| /// Celebratory screen after creating the first product 🎉 | ||
| /// | ||
| struct FirstProductCreatedView: View { | ||
| var onSharingProduct: () -> Void = {} | ||
| @State private var confettiCounter: Int = 0 | ||
|
|
||
| var body: some View { | ||
| GeometryReader { proxy in | ||
| ScrollableVStack(spacing: Constants.verticalSpacing) { | ||
| Spacer() | ||
| Text(Localization.title) | ||
| .titleStyle() | ||
| Image(uiImage: .welcomeImage) | ||
| Text(Localization.message) | ||
| .secondaryBodyStyle() | ||
| .multilineTextAlignment(.center) | ||
| Button(Localization.shareAction, | ||
| action: onSharingProduct) | ||
| .buttonStyle(PrimaryButtonStyle()) | ||
| .padding(.horizontal) | ||
| Spacer() | ||
| } | ||
| .padding() | ||
| .confettiCannon(counter: $confettiCounter, | ||
| num: Constants.confettiCount, | ||
| rainHeight: proxy.size.height, | ||
| radius: proxy.size.width) | ||
| } | ||
| .onAppear { | ||
| confettiCounter += 1 | ||
| } | ||
| .background(Color(uiColor: .systemBackground)) | ||
| } | ||
| } | ||
|
|
||
| private extension FirstProductCreatedView { | ||
| enum Constants { | ||
| static let verticalSpacing: CGFloat = 40 | ||
| static let confettiCount: Int = 100 | ||
| } | ||
| enum Localization { | ||
| static let title = NSLocalizedString( | ||
| "First product created 🎉", | ||
| comment: "Title of the celebratory screen after creating the first product" | ||
| ) | ||
| static let message = NSLocalizedString( | ||
| "Congratulations! You're one step closer to get the new store ready.", | ||
itsmeichigo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| comment: "Message on the celebratory screen after creating first product" | ||
| ) | ||
| static let shareAction = NSLocalizedString( | ||
| "Share Product", | ||
| comment: "Title of the action button to share the first created product" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| struct FirstProductCreatedView_Previews: PreviewProvider { | ||
| static var previews: some View { | ||
| FirstProductCreatedView() | ||
| .environment(\.colorScheme, .light) | ||
|
|
||
| FirstProductCreatedView() | ||
| .environment(\.colorScheme, .dark) | ||
| .previewInterfaceOrientation(.landscapeLeft) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Is it possible to pass
onCompletionblock toSharingHelperand dismiss this screen from it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't get a callback when the user submitted any content in the share sheet, so it's not technically possible to handle
onCompletion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, OK. I thought we could use the
onCompletionparameter. https://github.com/woocommerce/woocommerce-ios/blob/trunk/WooCommerce/Classes/Tools/SharingHelper.swift#L29