Skip to content
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

[Customer Center] Improving customer center buttons #4165

Merged
merged 9 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
// https://opensource.org/licenses/MIT
//
// ManageSubscriptionsButtonStyle.swift
// ButtonStyles.swift
//
//
// Created by Cesar de la Vega on 28/5/24.
Expand All @@ -25,7 +25,7 @@ import SwiftUI
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
struct ManageSubscriptionsButtonStyle: PrimitiveButtonStyle {
struct ProminentButtonStyle: PrimitiveButtonStyle {

@Environment(\.appearance) private var appearance: CustomerCenterConfigData.Appearance
@Environment(\.colorScheme) private var colorScheme
Expand All @@ -37,24 +37,56 @@ struct ManageSubscriptionsButtonStyle: PrimitiveButtonStyle {
Button(action: { configuration.trigger() }, label: {
configuration.label.frame(maxWidth: .infinity)
})
.font(.body.weight(.medium))
.buttonStyle(.borderedProminent)
.controlSize(.large)
.buttonBorderShape(.roundedRectangle(radius: 16))
.applyIf(background != nil, apply: { $0.tint(background) })
.applyIf(textColor != nil, apply: { $0.foregroundColor(textColor) })
}

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
struct SubtleButtonStyle: PrimitiveButtonStyle {

@Environment(\.appearance) private var appearance: CustomerCenterConfigData.Appearance
@Environment(\.colorScheme) private var colorScheme

func makeBody(configuration: PrimitiveButtonStyleConfiguration) -> some View {
let background = color(from: appearance.buttonBackgroundColor, for: colorScheme)

Button(action: { configuration.trigger() }, label: {
configuration.label.frame(maxWidth: .infinity)
})
.font(.body.weight(.medium))
.controlSize(.large)
.padding(.vertical)
codykerns marked this conversation as resolved.
Show resolved Hide resolved
.applyIf(background != nil, apply: { $0.foregroundColor(background) })
codykerns marked this conversation as resolved.
Show resolved Hide resolved
}

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
codykerns marked this conversation as resolved.
Show resolved Hide resolved
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
struct ManageSubscriptionsButtonStyle_Previews: PreviewProvider {

static var previews: some View {
Button("Didn't receive purchase") {}
.buttonStyle(ManageSubscriptionsButtonStyle())
.environment(\.appearance, CustomerCenterConfigTestData.standardAppearance)
VStack(spacing: 16.0) {
Button("Didn't receive purchase") {}
.buttonStyle(ProminentButtonStyle())
.environment(\.appearance, CustomerCenterConfigTestData.standardAppearance)

Button("Cancel") {}
.buttonStyle(SubtleButtonStyle())
.environment(\.appearance, CustomerCenterConfigTestData.standardAppearance)

}.padding()
}

}
Expand Down
2 changes: 1 addition & 1 deletion RevenueCatUI/CustomerCenter/Views/FeedbackSurveyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct FeedbackSurveyButtonsView: View {
Text(option.title)
}
})
.buttonStyle(ManageSubscriptionsButtonStyle())
.buttonStyle(ProminentButtonStyle())
.disabled(self.loadingState != nil)
}
}
Expand Down
21 changes: 14 additions & 7 deletions RevenueCatUI/CustomerCenter/Views/ManageSubscriptionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import SwiftUI
@available(watchOS, unavailable)
struct ManageSubscriptionsView: View {

@Environment(\.dismiss)
var dismiss

@Environment(\.appearance)
private var appearance: CustomerCenterConfigData.Appearance
@Environment(\.localization)
Expand Down Expand Up @@ -107,6 +110,16 @@ struct ManageSubscriptionsView: View {
.task {
await loadInformationIfNeeded()
}
.toolbar {
codykerns marked this conversation as resolved.
Show resolved Hide resolved
ToolbarItem(placement: .topBarLeading) {
Button(role: .cancel) {
dismiss()
} label: {
Text(localization.commonLocalizedString(for: .dismiss))
}

}
}
.navigationTitle(self.viewModel.screen.title)
.navigationBarTitleDisplayMode(.inline)
}
Expand Down Expand Up @@ -319,7 +332,7 @@ struct ManageSubscriptionButton: View {
Text(path.title)
}
})
.buttonStyle(ManageSubscriptionsButtonStyle())
.buttonStyle(ProminentButtonStyle())
.disabled(self.viewModel.loadingPath != nil)
.restorePurchasesAlert(isPresented: self.$viewModel.showRestoreAlert)
.sheet(item: self.$viewModel.promotionalOfferData,
Expand All @@ -337,13 +350,11 @@ struct ManageSubscriptionButton: View {
}

#if DEBUG

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
struct ManageSubscriptionsView_Previews: PreviewProvider {

static var previews: some View {
let viewModelMonthlyRenewing = ManageSubscriptionsViewModel(
screen: CustomerCenterConfigTestData.customerCenterData.screens[.management]!,
Expand All @@ -354,12 +365,10 @@ struct ManageSubscriptionsView_Previews: PreviewProvider {
.previewDisplayName("Monthly renewing")
.environment(\.localization, CustomerCenterConfigTestData.customerCenterData.localization)
.environment(\.appearance, CustomerCenterConfigTestData.customerCenterData.appearance)

let viewModelYearlyExpiring = ManageSubscriptionsViewModel(
screen: CustomerCenterConfigTestData.customerCenterData.screens[.management]!,
subscriptionInformation: CustomerCenterConfigTestData.subscriptionInformationYearlyExpiring,
customerCenterActionHandler: nil)

ManageSubscriptionsView(viewModel: viewModelYearlyExpiring)
.previewDisplayName("Yearly expiring")
.environment(\.localization, CustomerCenterConfigTestData.customerCenterData.localization)
Expand All @@ -373,7 +382,6 @@ struct ManageSubscriptionsView_Previews: PreviewProvider {
@available(tvOS, unavailable)
@available(watchOS, unavailable)
struct SubscriptionDetailsView_Previews: PreviewProvider {

static var previews: some View {
SubscriptionDetailsView(
subscriptionInformation: CustomerCenterConfigTestData.subscriptionInformationMonthlyRenewing,
Expand All @@ -382,7 +390,6 @@ struct SubscriptionDetailsView_Previews: PreviewProvider {
)
.previewDisplayName("Subscription Details - Monthly")
.padding()

codykerns marked this conversation as resolved.
Show resolved Hide resolved
}
}
#endif
Expand Down
7 changes: 4 additions & 3 deletions RevenueCatUI/CustomerCenter/Views/NoSubscriptionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ struct NoSubscriptionsView: View {
showRestoreAlert = true
}
.restorePurchasesAlert(isPresented: $showRestoreAlert)
.buttonStyle(ManageSubscriptionsButtonStyle())
.buttonStyle(ProminentButtonStyle())

Button(localization.commonLocalizedString(for: .cancel)) {
Button(localization.commonLocalizedString(for: .dismiss)) {
codykerns marked this conversation as resolved.
Show resolved Hide resolved
dismiss()
}
.padding(.vertical)
.buttonStyle(SubtleButtonStyle())

}
.padding(.horizontal)
.applyIf(textColor != nil, apply: { $0.foregroundColor(textColor) })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ struct PromoOfferButtonView: View {
.font(.subheadline)
}
})
.buttonStyle(ManageSubscriptionsButtonStyle())
.buttonStyle(ProminentButtonStyle())
.padding(.horizontal)
}
}
Expand Down
14 changes: 14 additions & 0 deletions RevenueCatUI/CustomerCenter/Views/WrongPlatformView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ struct WrongPlatformView: View {
@State
private var store: Store?

@Environment(\.dismiss)
var dismiss

@Environment(\.localization)
private var localization: CustomerCenterConfigData.Localization
@Environment(\.appearance)
private var appearance: CustomerCenterConfigData.Appearance
@Environment(\.colorScheme)
Expand Down Expand Up @@ -58,6 +63,15 @@ struct WrongPlatformView: View {
systemImage: "exclamationmark.triangle.fill"
)

Spacer()

Button {
dismiss()
} label: {
Text(localization.commonLocalizedString(for: .dismiss))
}
.buttonStyle(SubtleButtonStyle())
codykerns marked this conversation as resolved.
Show resolved Hide resolved

}
.applyIf(textColor != nil, apply: { $0.foregroundColor(textColor) })
}
Expand Down