-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
368 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
106 changes: 106 additions & 0 deletions
106
podcasts/Cancel Subscription/Cancel Subscription/Plans View/CancelSubscriptionPlanRow.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import SwiftUI | ||
|
||
struct CancelSubscriptionPlanRow: View { | ||
@EnvironmentObject var theme: Theme | ||
|
||
let product: PlusPricingInfoModel.PlusProductPricingInfo | ||
var selected: Bool | ||
let onTap: (PlusPricingInfoModel.PlusProductPricingInfo) -> Void | ||
|
||
var body: some View { | ||
ZStack { | ||
Rectangle() | ||
.foregroundStyle(.clear) | ||
.background(theme.primaryUi01) | ||
.cornerRadius(8.0) | ||
.frame(height: 64) | ||
VStack(alignment: .leading, spacing: 0) { | ||
HStack(spacing: 0) { | ||
Text(product.planTitle) | ||
.font(size: 18.0, style: .body, weight: .bold) | ||
.foregroundStyle(theme.primaryText01) | ||
Spacer() | ||
if selected { | ||
ZStack { | ||
Circle() | ||
.fill(theme.primaryField03Active) | ||
.frame(width: 24, height: 24) | ||
Image("small-tick") | ||
.resizable() | ||
.frame(width: 24, height: 24) | ||
.foregroundColor(theme.primaryInteractive02) | ||
} | ||
} | ||
} | ||
HStack(spacing: 0) { | ||
Text(product.frequencyPrice) | ||
.font(size: 15.0, style: .body, weight: .regular) | ||
.foregroundStyle(theme.primaryText01) | ||
Spacer() | ||
} | ||
} | ||
.padding(.leading, 20.0) | ||
.padding(.trailing, 10.0) | ||
} | ||
.overlay( | ||
RoundedRectangle(cornerRadius: 8.0) | ||
.stroke(theme.primaryField03Active, | ||
lineWidth: selected ? 2 : 0) | ||
) | ||
.padding(.horizontal, 20.0) | ||
.onTapGesture { | ||
onTap(product) | ||
} | ||
} | ||
} | ||
|
||
extension PlusPricingInfoModel.PlusProductPricingInfo { | ||
fileprivate var planTitle: String { | ||
switch identifier { | ||
case .yearly, .yearlyReferral: | ||
return "Plus \(L10n.yearly.capitalized)" | ||
case .monthly: | ||
return "Plus \(L10n.monthly.capitalized)" | ||
case .patronMonthly: | ||
return "Patron \(L10n.monthly.capitalized)" | ||
case .patronYearly: | ||
return "Patron \(L10n.yearly.capitalized)" | ||
} | ||
} | ||
|
||
fileprivate var frequencyPrice: String { | ||
switch identifier { | ||
case .yearly, .yearlyReferral, .patronYearly: | ||
return L10n.plusYearlyFrequencyPricingFormat(rawPrice) | ||
case .monthly, .patronMonthly: | ||
return L10n.plusMonthlyFrequencyPricingFormat(rawPrice) | ||
} | ||
} | ||
} | ||
|
||
struct CancelSubscriptionPlanRow_Preview: PreviewProvider { | ||
static var previews: some View { | ||
VStack(spacing: 16.0) { | ||
CancelSubscriptionPlanRow( | ||
product: .init( | ||
identifier: .yearly, | ||
price: "", | ||
rawPrice: "$39.99", | ||
offer: nil), | ||
selected: true | ||
) { _ in } | ||
.environmentObject(Theme.sharedTheme) | ||
CancelSubscriptionPlanRow( | ||
product: .init( | ||
identifier: .monthly, | ||
price: "", | ||
rawPrice: "$3.99", | ||
offer: nil), | ||
selected: false | ||
) { _ in } | ||
.environmentObject(Theme.sharedTheme) | ||
} | ||
.background(.gray) | ||
.previewLayout(.fixed(width: 393, height: 250)) | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...asts/Cancel Subscription/Cancel Subscription/Plans View/CancelSubscriptionPlansView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import SwiftUI | ||
|
||
struct CancelSubscriptionPlansView: View { | ||
@EnvironmentObject var theme: Theme | ||
|
||
@ObservedObject var viewModel: CancelSubscriptionViewModel | ||
|
||
init(viewModel: CancelSubscriptionViewModel) { | ||
self.viewModel = viewModel | ||
} | ||
|
||
var body: some View { | ||
ZStack { | ||
switch viewModel.currentProductAvailability { | ||
case .loading: | ||
showLoading() | ||
default: | ||
closeButton | ||
mainView | ||
if viewModel.state == .purchasing { | ||
showLoading(fullScreen: true) | ||
} | ||
} | ||
} | ||
.onAppear { | ||
Task { | ||
await viewModel.loadCurrentProduct() | ||
} | ||
} | ||
.background(theme.primaryUi04) | ||
} | ||
|
||
var closeButton: some View { | ||
VStack { | ||
HStack { | ||
Spacer() | ||
Button(action: { | ||
viewModel.closePlans() | ||
}) { | ||
Image(systemName: "xmark") | ||
.font(.system(size: 14).weight(.bold)) | ||
.frame(width: 30, height: 30) | ||
.foregroundColor(theme.primaryIcon02Active) | ||
.background(theme.primaryUi05) | ||
.clipShape(Circle()) | ||
} | ||
} | ||
.padding(.trailing, 16.0) | ||
.padding(.top, 16.0) | ||
Spacer() | ||
} | ||
} | ||
|
||
var mainView: some View { | ||
VStack(spacing: 16.0) { | ||
Image("cs-app-icon") | ||
.frame(width: 100.0, height: 100.0) | ||
.padding(.top, 88.0) | ||
.padding(.bottom, 20.0) | ||
Text(L10n.cancelSubscriptionAvailablePlansTitle) | ||
.font(size: 28.0, style: .body, weight: .bold) | ||
.foregroundStyle(theme.primaryText01) | ||
.padding(.bottom, 24.0) | ||
ForEach(viewModel.pricingInfo.products, id: \.id) { product in | ||
CancelSubscriptionPlanRow(product: product, | ||
selected: product.identifier == viewModel.currentPricingProduct?.identifier) { selectedProduct in | ||
viewModel.purchase(product: selectedProduct) | ||
} | ||
} | ||
Spacer() | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
func showLoading(fullScreen: Bool = false) -> some View { | ||
if fullScreen { | ||
ZStack { | ||
theme.primaryUi05Selected | ||
.edgesIgnoringSafeArea(.all) | ||
.opacity(0.7) | ||
ProgressView() | ||
.tint(theme.primaryText01) | ||
} | ||
} else { | ||
ProgressView() | ||
.tint(theme.primaryUi01) | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
CancelSubscriptionPlansView(viewModel: CancelSubscriptionViewModel(navigationController: UINavigationController())) | ||
.environmentObject(Theme.sharedTheme) | ||
} |
Oops, something went wrong.