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

[Paywalls] Add Badge Modifier #4596

Merged
merged 6 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions RevenueCat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@
4DBF1F372B4D572400D52354 /* LocalReceiptFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DBF1F352B4D572400D52354 /* LocalReceiptFetcher.swift */; };
4DC546272AD44BBE005CDB35 /* EncodedAppleReceipt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DC546262AD44BBE005CDB35 /* EncodedAppleReceipt.swift */; };
4DE3D5742CDB646900838110 /* MockPaywallEventsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FFFE6C52AA9465000B2955C /* MockPaywallEventsManager.swift */; };
4DEB9BC52D08CA1700D33E36 /* BadgeModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DEB9BC42D08CA1500D33E36 /* BadgeModifier.swift */; };
4F0201C42A13C85500091612 /* Assertions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F0201C32A13C85500091612 /* Assertions.swift */; };
4F05876F2A5DE03F00E9A834 /* PaywallDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F05876E2A5DE03F00E9A834 /* PaywallDataTests.swift */; };
4F062D322A85A11600A8A613 /* PaywallData+Localization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F062D312A85A11600A8A613 /* PaywallData+Localization.swift */; };
Expand Down Expand Up @@ -1690,6 +1691,7 @@
4DBC30952B1DFA97001D33C7 /* StoreKitVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreKitVersion.swift; sourceTree = "<group>"; };
4DBF1F352B4D572400D52354 /* LocalReceiptFetcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalReceiptFetcher.swift; sourceTree = "<group>"; };
4DC546262AD44BBE005CDB35 /* EncodedAppleReceipt.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EncodedAppleReceipt.swift; sourceTree = "<group>"; };
4DEB9BC42D08CA1500D33E36 /* BadgeModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BadgeModifier.swift; sourceTree = "<group>"; };
4F0201C32A13C85500091612 /* Assertions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assertions.swift; sourceTree = "<group>"; };
4F05876E2A5DE03F00E9A834 /* PaywallDataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaywallDataTests.swift; sourceTree = "<group>"; };
4F062D312A85A11600A8A613 /* PaywallData+Localization.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PaywallData+Localization.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2561,6 +2563,7 @@
2C7457872CEDF7AC004ACE52 /* BackgroundStyle.swift */,
77089F9D2CD39EC100848CD5 /* ShadowModifier.swift */,
4D6F4BCF2CF69DE300353AF6 /* ForegroundColorScheme.swift */,
4DEB9BC42D08CA1500D33E36 /* BadgeModifier.swift */,
2C91068D2CE2481800189565 /* SizeModifier.swift */,
2CAB87F62CAAB13200247013 /* Shape.swift */,
03C72F8C2D3311D500297FEC /* DisplayableColor.swift */,
Expand Down Expand Up @@ -6601,6 +6604,7 @@
3546355F2C391F4D001D7E85 /* PromotionalOfferView.swift in Sources */,
2C7457882CEDF7C0004ACE52 /* BackgroundStyle.swift in Sources */,
2C8EC6DD2CCC7C5B00D6CCF8 /* PackageValidator.swift in Sources */,
4DEB9BC52D08CA1700D33E36 /* BadgeModifier.swift in Sources */,
778360792CCA85E4000785B8 /* StickyFooterComponentViewModel.swift in Sources */,
2C7457482CEA66AB004ACE52 /* ComponentsView.swift in Sources */,
353756722C382C2800A1B8D6 /* URLUtilities.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct StackComponentView: View {
shadow: style.shadow,
background: style.backgroundStyle,
uiConfigProvider: self.viewModel.uiConfigProvider)
.stackBadge(style.badge)
.padding(style.margin)
}

Expand Down Expand Up @@ -528,7 +529,9 @@ fileprivate extension StackComponentViewModel {
try self.init(
component: component,
viewModels: viewModels,
uiConfigProvider: .init(uiConfig: PreviewUIConfig.make())
badgeViewModels: [],
uiConfigProvider: .init(uiConfig: PreviewUIConfig.make()),
localizationProvider: localizationProvider
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ class StackComponentViewModel {
private let presentedOverrides: PresentedOverrides<PresentedStackPartial>?

let viewModels: [PaywallComponentViewModel]
let badgeViewModels: [PaywallComponentViewModel]

init(
component: PaywallComponent.StackComponent,
viewModels: [PaywallComponentViewModel],
uiConfigProvider: UIConfigProvider
badgeViewModels: [PaywallComponentViewModel],
uiConfigProvider: UIConfigProvider,
localizationProvider: LocalizationProvider
) throws {
self.component = component
self.viewModels = viewModels
self.uiConfigProvider = uiConfigProvider

self.badgeViewModels = badgeViewModels
self.presentedOverrides = try self.component.overrides?.toPresentedOverrides { $0 }
}

Expand All @@ -55,6 +58,7 @@ class StackComponentViewModel {

let style = StackComponentStyle(
uiConfigProvider: self.uiConfigProvider,
badgeViewModels: self.badgeViewModels,
visible: partial?.visible ?? true,
dimension: partial?.dimension ?? self.component.dimension,
size: partial?.size ?? self.component.size,
Expand All @@ -64,7 +68,8 @@ class StackComponentViewModel {
margin: partial?.margin ?? self.component.margin,
shape: partial?.shape ?? self.component.shape,
border: partial?.border ?? self.component.border,
shadow: partial?.shadow ?? self.component.shadow
shadow: partial?.shadow ?? self.component.shadow,
badge: partial?.badge ?? self.component.badge
)

apply(style)
Expand Down Expand Up @@ -109,9 +114,11 @@ struct StackComponentStyle {
let shape: ShapeModifier.Shape?
let border: ShapeModifier.BorderInfo?
let shadow: ShadowModifier.ShadowInfo?
let badge: BadgeModifier.BadgeInfo?

init(
uiConfigProvider: UIConfigProvider,
badgeViewModels: [PaywallComponentViewModel],
visible: Bool,
dimension: PaywallComponent.Dimension,
size: PaywallComponent.Size,
Expand All @@ -121,7 +128,8 @@ struct StackComponentStyle {
margin: PaywallComponent.Padding,
shape: PaywallComponent.Shape?,
border: PaywallComponent.Border?,
shadow: PaywallComponent.Shadow?
shadow: PaywallComponent.Shadow?,
badge: PaywallComponent.Badge?
) {
self.visible = visible
self.dimension = dimension
Expand All @@ -133,6 +141,9 @@ struct StackComponentStyle {
self.shape = shape?.shape
self.border = border?.border(uiConfigProvider: uiConfigProvider)
self.shadow = shadow?.shadow(uiConfigProvider: uiConfigProvider)
self.badge = badge?.badge(stackShape: self.shape,
badgeViewModels: badgeViewModels,
uiConfigProvider: uiConfigProvider)
}

var vstackStrategy: StackStrategy {
Expand Down Expand Up @@ -168,7 +179,7 @@ struct StackComponentStyle {
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
private extension PaywallComponent.Shape {

var shape: ShapeModifier.Shape? {
var shape: ShapeModifier.Shape {
switch self {
case .rectangle(let cornerRadiuses):
let corners = cornerRadiuses.flatMap { cornerRadiuses in
Expand Down Expand Up @@ -213,4 +224,22 @@ private extension PaywallComponent.Shadow {

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
private extension PaywallComponent.Badge {

func badge(stackShape: ShapeModifier.Shape?,
badgeViewModels: [PaywallComponentViewModel],
uiConfigProvider: UIConfigProvider) -> BadgeModifier.BadgeInfo? {
BadgeModifier.BadgeInfo(
style: self.style,
alignment: self.alignment,
stack: self.stack,
badgeViewModels: badgeViewModels,
stackShape: stackShape,
uiConfigProvider: uiConfigProvider
)
}

}

#endif
Loading