Skip to content

Instantly share code, notes, and snippets.

@Dimillian
Created May 29, 2020 06:52
Show Gist options
  • Save Dimillian/3eb6278f14f072fdd7799dbae93715a8 to your computer and use it in GitHub Desktop.
Save Dimillian/3eb6278f14f072fdd7799dbae93715a8 to your computer and use it in GitHub Desktop.
private var paymentButtons: some View {
VStack {
HStack(spacing: 0) {
sub.map{ sub in
makeBorderedButton(action: {
self.buttonAction(purchase: sub)
}, label: self.subscriptionManager.subscriptionStatus == .subscribed ?
"Thanks!" :
"\(formattedPrice(for: sub)) Monthly")
.opacity(subscriptionManager.inPaymentProgress ? 0.5 : 1.0)
.disabled(subscriptionManager.inPaymentProgress)
}
Spacer(minLength: 18)
yearlySub.map{ yearlySub in
makeBorderedButton(action: {
self.buttonAction(purchase: yearlySub)
}, label: self.subscriptionManager.subscriptionStatus == .subscribed ?
"Thanks!" :
"\(formattedPrice(for: yearlySub)) Yearly")
.opacity(subscriptionManager.inPaymentProgress ? 0.5 : 1.0)
.disabled(subscriptionManager.inPaymentProgress)
}
}.frame(maxWidth: 320)
lifetime.map{ lifetime in
makeBorderedButton(action: {
self.buttonAction(purchase: lifetime)
}, label: self.subscriptionManager.subscriptionStatus == .subscribed ?
"Thank you for your support!" :
"Buy lifetime AC Helper+ for \(formattedPrice(for: lifetime))")
.opacity(subscriptionManager.inPaymentProgress ? 0.5 : 1.0)
.disabled(subscriptionManager.inPaymentProgress)
.padding(.top, 16)
}.frame(maxWidth: 320)
}
}
private func buttonAction(purchase: Purchases.Package) {
if subscriptionManager.subscriptionStatus == .subscribed {
presentationMode.wrappedValue.dismiss()
} else {
subscriptionManager.purchase(source: self.source.rawValue,
product: purchase)
}
}
private func makeBorderedButton(action: @escaping () -> Void, label:
LocalizedStringKey) -> some View {
Button(action: action) {
Text(label)
.font(.headline)
.fontWeight(.bold)
.foregroundColor(.white)
.minimumScaleFactor(0.01)
.lineLimit(1)
.frame(maxWidth: .infinity,
maxHeight: 30)
}.buttonStyle(PlainRoundedButton()).accentColor(.acTabBarTint).safeHoverEffect()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment