Skip to content

Commit

Permalink
Paywalls: improved FooterView scaling (#2948)
Browse files Browse the repository at this point in the history
- Added `bold` parameter, necessary for upcoming template
- Avoid scaling beyond largest dynamic type sizes
- Scale separator view with dynamic type setting to ensure consistency
  • Loading branch information
NachoSoto committed Sep 8, 2023
1 parent 36dff3b commit f37570a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
3 changes: 3 additions & 0 deletions RevenueCatUI/Data/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ enum Constants {
static let defaultAnimation: Animation = .easeIn(duration: 0.2)
static let fastAnimation: Animation = .easeIn(duration: 0.1)

/// For UI elements that wouldn't make sense to keep scaling up forever
static let maximumDynamicTypeSize: DynamicTypeSize = .accessibility3

}
48 changes: 43 additions & 5 deletions RevenueCatUI/Views/FooterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ struct FooterView: View {

var configuration: PaywallData.Configuration
var color: Color
var bold: Bool
var purchaseHandler: PurchaseHandler

init(configuration: PaywallData.Configuration, color: Color, bold: Bool = true, purchaseHandler: PurchaseHandler) {
self.configuration = configuration
self.color = color
self.bold = bold
self.purchaseHandler = purchaseHandler
}

var body: some View {
HStack {
if self.configuration.displayRestorePurchases {
Expand Down Expand Up @@ -42,22 +50,42 @@ struct FooterView: View {
}
}
.foregroundColor(self.color)
.font(.caption.bold())
.font(Self.font.weight(self.fontWeight))
.padding(.horizontal)
.padding(.bottom, 5)
.dynamicTypeSize(...Constants.maximumDynamicTypeSize)
}

private var separator: some View {
Image(systemName: "circle.fill")
.font(.system(size: 5))
.accessibilityHidden(true)
SeparatorView(bold: self.bold)
}

private var hasTOS: Bool { self.configuration.termsOfServiceURL != nil }
private var hasPrivacy: Bool { self.configuration.privacyURL != nil }
private var fontWeight: Font.Weight { self.bold ? .bold : .regular }

private static let font: Font = .caption

}

@available(iOS 16.0, macOS 13.0, tvOS 16.0, *)
private struct SeparatorView: View {

var bold: Bool

var body: some View {
Image(systemName: "circle.fill")
.font(.system(size: self.bold ? self.boldSeparatorSize : self.separatorSize))
.accessibilityHidden(true)
}

@ScaledMetric(relativeTo: .caption)
private var separatorSize: CGFloat = 4

@ScaledMetric(relativeTo: .caption)
private var boldSeparatorSize: CGFloat = 5
}

@available(iOS 16.0, macOS 13.0, tvOS 16.0, *)
private struct RestorePurchasesButton: View {

Expand Down Expand Up @@ -154,12 +182,21 @@ struct Footer_Previews: PreviewProvider {
privacyURL: URL(string: "https://revenuecat.com/tos")!
)
.previewDisplayName("All")

Self.create(
displayRestorePurchases: true,
termsOfServiceURL: URL(string: "https://revenuecat.com/tos")!,
privacyURL: URL(string: "https://revenuecat.com/tos")!,
bold: false
)
.previewDisplayName("Not bold")
}

private static func create(
displayRestorePurchases: Bool = true,
termsOfServiceURL: URL? = nil,
privacyURL: URL? = nil
privacyURL: URL? = nil,
bold: Bool = true
) -> some View {
FooterView(
configuration: .init(
Expand All @@ -171,6 +208,7 @@ struct Footer_Previews: PreviewProvider {
privacyURL: privacyURL
),
color: TestData.colors.text1Color,
bold: bold,
purchaseHandler: PreviewHelpers.purchaseHandler
)
}
Expand Down
4 changes: 1 addition & 3 deletions RevenueCatUI/Views/PurchaseButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ struct PurchaseButton: View {
.controlSize(self.mode.buttonSize)
.buttonStyle(.borderedProminent)
.frame(maxWidth: .infinity)
.dynamicTypeSize(...Self.maximumDynamicTypeSize)
.dynamicTypeSize(...Constants.maximumDynamicTypeSize)
}

private static let maximumDynamicTypeSize: DynamicTypeSize = .accessibility3

}

@available(iOS 16.0, macOS 13.0, tvOS 16.0, *)
Expand Down

0 comments on commit f37570a

Please sign in to comment.