Skip to content

Commit

Permalink
Disable embedded and playground while updating and loading, respectively
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-stripe committed Oct 23, 2024
1 parent dfdf88b commit 7c9831b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ import Foundation
import UIKit

class EmbeddedPlaygroundViewController: UIViewController {
var isLoading: Bool = false {
didSet {
if isLoading {
view.bringSubviewToFront(loadingIndicator)
loadingIndicator.startAnimating()
view.isUserInteractionEnabled = false
} else {
loadingIndicator.stopAnimating()
view.isUserInteractionEnabled = true
}
}
}
private let appearance: PaymentSheet.Appearance

private let configuration: EmbeddedPaymentElement.Configuration
Expand Down Expand Up @@ -119,7 +131,7 @@ class EmbeddedPlaygroundViewController: UIViewController {
scrollView.contentLayoutGuide.leadingAnchor.constraint(equalTo: stackView.leadingAnchor),
scrollView.contentLayoutGuide.trailingAnchor.constraint(equalTo: stackView.trailingAnchor),
scrollView.contentLayoutGuide.widthAnchor.constraint(equalTo: view.widthAnchor),
checkoutButton.heightAnchor.constraint(equalToConstant: 45)
checkoutButton.heightAnchor.constraint(equalToConstant: 45),
])
paymentOptionView.configure(with: embeddedPaymentElement.paymentOption, showMandate: !configuration.embeddedViewDisplaysMandateText)
}
Expand Down Expand Up @@ -226,7 +238,7 @@ private class EmbeddedPaymentOptionView: UIView {
verticalStackView.topAnchor.constraint(equalTo: self.topAnchor, constant: 15),
verticalStackView.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -15),
imageView.widthAnchor.constraint(equalToConstant: 25),
imageView.heightAnchor.constraint(equalToConstant: 25)
imageView.heightAnchor.constraint(equalToConstant: 25),
])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ extension PlaygroundController {
addressViewController = nil
paymentSheet = nil
lastPaymentResult = nil
embeddedPlaygroundViewController?.isLoading = true
isLoading = true
let settingsToLoad = self.settings

Expand Down Expand Up @@ -729,7 +730,8 @@ extension PlaygroundController {
}
case .embedded:
guard !shouldUpdateEmbeddedInsteadOfRecreating else {
// Update embedded rather than re-creating it
// Update embedded rather than re-creating it
self.embeddedPlaygroundViewController?.isLoading = false
self.updateEmbedded()
self.currentlyRenderedSettings = self.settings
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public final class EmbeddedPaymentElement {
public func update(
intentConfiguration: IntentConfiguration
) async -> UpdateResult {
embeddedPaymentMethodsView.isUserInteractionEnabled = false
// Cancel the old task and let it finish so that merchants receive update results in order
currentUpdateTask?.cancel()
_ = await currentUpdateTask?.value
Expand Down Expand Up @@ -158,7 +159,9 @@ public final class EmbeddedPaymentElement {
return .succeeded
}
self.currentUpdateTask = currentUpdateTask
return await currentUpdateTask.value
let updateResult = await currentUpdateTask.value
embeddedPaymentMethodsView.isUserInteractionEnabled = true
return updateResult
}

/// Completes the payment or setup.
Expand Down

0 comments on commit 7c9831b

Please sign in to comment.