From 003348c1033457cc2a66d60ee4ad909141e6aa79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Fri, 23 Feb 2024 21:29:52 +0000 Subject: [PATCH] iap: add loading spinner to purchase actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apple In-app purchases do not respond immediately. This commit adds a loading spinner element, to improve the UX and avoid the appearance of a broken/unresponsive element. Testing -------- Device: iPhone 15 simulator iOS: 17.2 Damus: This commit Setup: - Using the sandbox environment - No tx to start with - IAP experimental support enabled on developer settings in Damus Steps: 1. Click "purchase" in any option on the damus purple screen 2. It should show a loading spinner while the purchase action is loading. PASS 3. On the confirmation screen, cancel the purchase. 4. Purchase buttons should show again. PASS Closes: https://github.com/damus-io/damus/issues/2020 Signed-off-by: Daniel D’Aquino Link: 20240223212945.37384-1-daniel@daquino.me Signed-off-by: William Casarin --- .../Purple/Detail/IAPProductStateView.swift | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/damus/Views/Purple/Detail/IAPProductStateView.swift b/damus/Views/Purple/Detail/IAPProductStateView.swift index 742e95b7..8764c009 100644 --- a/damus/Views/Purple/Detail/IAPProductStateView.swift +++ b/damus/Views/Purple/Detail/IAPProductStateView.swift @@ -21,20 +21,32 @@ extension DamusPurpleView { let subscribe: (Product) async throws -> Void @State var show_manage_subscriptions = false + @State var subscription_purchase_loading = false var body: some View { - switch self.products { - case .failed: - PurpleViewPrimitives.ProductLoadErrorView() - case .loaded(let products): - if let purchased { - PurchasedView(purchased) - } else { - ProductsView(products) - } - case .loading: + if subscription_purchase_loading { + HStack(spacing: 10) { + Text(NSLocalizedString("Purchasing", comment: "Loading label indicating the purchase action is in progress")) + .foregroundStyle(.white) ProgressView() .progressViewStyle(.circular) + .tint(.white) + } + } + else { + switch self.products { + case .failed: + PurpleViewPrimitives.ProductLoadErrorView() + case .loaded(let products): + if let purchased { + PurchasedView(purchased) + } else { + ProductsView(products) + } + case .loading: + ProgressView() + .progressViewStyle(.circular) + } } } @@ -107,7 +119,9 @@ extension DamusPurpleView { Button(action: { Task { @MainActor in do { + subscription_purchase_loading = true try await subscribe(product) + subscription_purchase_loading = false } catch { print(error.localizedDescription) }