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 V2] Update stack size spec #4467

Merged
merged 7 commits into from
Nov 11, 2024
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
23 changes: 17 additions & 6 deletions RevenueCat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
2C8EC6E12CCD7BA700D6CCF8 /* ComponentOverrides.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C8EC6E02CCD7BA300D6CCF8 /* ComponentOverrides.swift */; };
2C8EC71B2CCDD43900D6CCF8 /* ComponentViewState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C8EC71A2CCDD43500D6CCF8 /* ComponentViewState.swift */; };
2C8EC7202CCF276100D6CCF8 /* LocalizedPartials.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C8EC71F2CCF275E00D6CCF8 /* LocalizedPartials.swift */; };
2C91068A2CE22D3500189565 /* FlexVStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C9106892CE22D3500189565 /* FlexVStack.swift */; };
2C91068C2CE22D4F00189565 /* JustifyContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C91068B2CE22D4F00189565 /* JustifyContent.swift */; };
2C91068E2CE2481A00189565 /* SizeModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C91068D2CE2481800189565 /* SizeModifier.swift */; };
2C9106FF2CE29F1400189565 /* StoredEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FE6FEE42AA940B700780B45 /* StoredEvent.swift */; };
2CAB87F72CAAB13200247013 /* CornerBorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CAB87F62CAAB13200247013 /* CornerBorder.swift */; };
2CB8CF9327BF538F00C34DE3 /* PlatformInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CB8CF9227BF538F00C34DE3 /* PlatformInfo.swift */; };
2CC791552CC0452100FBE120 /* PurchaseButtonComponentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CC791522CC0452100FBE120 /* PurchaseButtonComponentViewModel.swift */; };
Expand Down Expand Up @@ -431,7 +435,6 @@
4FDF10F12A7262D8004F3680 /* SK2ProductFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FDF10EF2A7262D8004F3680 /* SK2ProductFetcher.swift */; };
4FE0685F2A5F54C500B8F56C /* PackageTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FE0685E2A5F54C500B8F56C /* PackageTypeTests.swift */; };
4FE6669F2A2F95A1004EEAFC /* PaywallExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FE6669E2A2F95A1004EEAFC /* PaywallExtensions.swift */; };
4FE6FEE52AA940B800780B45 /* StoredEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FE6FEE42AA940B700780B45 /* StoredEvent.swift */; };
4FE6FEEA2AA940E300780B45 /* PaywallEventStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FE6FEE72AA940E300780B45 /* PaywallEventStoreTests.swift */; };
4FE6FEEB2AA940E300780B45 /* PaywallEventSerializerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FE6FEE82AA940E300780B45 /* PaywallEventSerializerTests.swift */; };
4FEF41AB2B4F2F3400CD699F /* MapAppStoreDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FEF41AA2B4F2F3400CD699F /* MapAppStoreDetector.swift */; };
Expand Down Expand Up @@ -1018,13 +1021,13 @@
FDAADFD32BE2B99900BD1659 /* MockStoreKit2ObserverModePurchaseDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDAADFD22BE2B99900BD1659 /* MockStoreKit2ObserverModePurchaseDetector.swift */; };
FDAADFD42BE2B99900BD1659 /* MockStoreKit2ObserverModePurchaseDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDAADFD22BE2B99900BD1659 /* MockStoreKit2ObserverModePurchaseDetector.swift */; };
FDAADFD72BE2C67700BD1659 /* StoreKit2ObserverModePurchaseDetectorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDAADFD52BE2C67700BD1659 /* StoreKit2ObserverModePurchaseDetectorTests.swift */; };
FDC892D12CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDC892D02CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift */; };
FDC892D22CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDC892D02CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift */; };
FDAC7B532CD3D67600DFC0D9 /* WinBackOfferEligibilityCalculatorType.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDAC7B522CD3D67600DFC0D9 /* WinBackOfferEligibilityCalculatorType.swift */; };
FDAC7B552CD3D7A500DFC0D9 /* WinBackOfferEligibilityCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDAC7B542CD3D7A200DFC0D9 /* WinBackOfferEligibilityCalculator.swift */; };
FDAC7B572CD3FD8500DFC0D9 /* MockWinBackOfferEligibilityCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDAC7B562CD3FD8500DFC0D9 /* MockWinBackOfferEligibilityCalculator.swift */; };
FDAC7B582CD3FD8500DFC0D9 /* MockWinBackOfferEligibilityCalculator.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDAC7B562CD3FD8500DFC0D9 /* MockWinBackOfferEligibilityCalculator.swift */; };
FDAC7B5B2CD4085800DFC0D9 /* PurchasesWinBackOfferTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDAC7B5A2CD4085800DFC0D9 /* PurchasesWinBackOfferTests.swift */; };
FDC892D12CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDC892D02CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift */; };
FDC892D22CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDC892D02CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift */; };
FDC892FE2CD157F1000AEB9F /* WinBackOffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDC892FD2CD157F1000AEB9F /* WinBackOffer.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -1221,6 +1224,9 @@
2C8EC6E02CCD7BA300D6CCF8 /* ComponentOverrides.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComponentOverrides.swift; sourceTree = "<group>"; };
2C8EC71A2CCDD43500D6CCF8 /* ComponentViewState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComponentViewState.swift; sourceTree = "<group>"; };
2C8EC71F2CCF275E00D6CCF8 /* LocalizedPartials.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalizedPartials.swift; sourceTree = "<group>"; };
2C9106892CE22D3500189565 /* FlexVStack.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlexVStack.swift; sourceTree = "<group>"; };
2C91068B2CE22D4F00189565 /* JustifyContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JustifyContent.swift; sourceTree = "<group>"; };
2C91068D2CE2481800189565 /* SizeModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SizeModifier.swift; sourceTree = "<group>"; };
2CAB87F62CAAB13200247013 /* CornerBorder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CornerBorder.swift; sourceTree = "<group>"; };
2CB8CF9227BF538F00C34DE3 /* PlatformInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlatformInfo.swift; sourceTree = "<group>"; };
2CC7914B2CC0452100FBE120 /* PackageComponentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PackageComponentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2220,11 +2226,11 @@
FDAADFCE2BE2B84500BD1659 /* StoreKit2ObserverModePurchaseDetector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreKit2ObserverModePurchaseDetector.swift; sourceTree = "<group>"; };
FDAADFD22BE2B99900BD1659 /* MockStoreKit2ObserverModePurchaseDetector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockStoreKit2ObserverModePurchaseDetector.swift; sourceTree = "<group>"; };
FDAADFD52BE2C67700BD1659 /* StoreKit2ObserverModePurchaseDetectorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreKit2ObserverModePurchaseDetectorTests.swift; sourceTree = "<group>"; };
FDC892D02CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockStoreKit2PurchaseIntentListener.swift; sourceTree = "<group>"; };
FDAC7B522CD3D67600DFC0D9 /* WinBackOfferEligibilityCalculatorType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WinBackOfferEligibilityCalculatorType.swift; sourceTree = "<group>"; };
FDAC7B542CD3D7A200DFC0D9 /* WinBackOfferEligibilityCalculator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WinBackOfferEligibilityCalculator.swift; sourceTree = "<group>"; };
FDAC7B562CD3FD8500DFC0D9 /* MockWinBackOfferEligibilityCalculator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockWinBackOfferEligibilityCalculator.swift; sourceTree = "<group>"; };
FDAC7B5A2CD4085800DFC0D9 /* PurchasesWinBackOfferTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PurchasesWinBackOfferTests.swift; sourceTree = "<group>"; };
FDC892D02CCAD0EE000AEB9F /* MockStoreKit2PurchaseIntentListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockStoreKit2PurchaseIntentListener.swift; sourceTree = "<group>"; };
FDC892FD2CD157F1000AEB9F /* WinBackOffer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WinBackOffer.swift; sourceTree = "<group>"; };
FECF627761D375C8431EB866 /* StoreProduct.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreProduct.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -4512,6 +4518,7 @@
88AD01352C74196600AA1F2B /* Components */ = {
isa = PBXGroup;
children = (
2C91068D2CE2481800189565 /* SizeModifier.swift */,
2C08B3342CDD16550024857B /* PaywallComponentViewModel.swift */,
2C08B3162CDA443A0024857B /* ViewModelFactory.swift */,
2C8EC71F2CCF275E00D6CCF8 /* LocalizedPartials.swift */,
Expand Down Expand Up @@ -4574,7 +4581,9 @@
88B1BAEA2C813A3C001B7EE5 /* Stack */ = {
isa = PBXGroup;
children = (
2C91068B2CE22D4F00189565 /* JustifyContent.swift */,
2C08B3062CD55D590024857B /* FlexHStack.swift */,
2C9106892CE22D3500189565 /* FlexVStack.swift */,
88B1BAE82C813A3C001B7EE5 /* StackComponentView.swift */,
88B1BAE92C813A3C001B7EE5 /* StackComponentViewModel.swift */,
);
Expand Down Expand Up @@ -5533,6 +5542,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2C9106FF2CE29F1400189565 /* StoredEvent.swift in Sources */,
B3A36AAE26BC76340059EDEA /* CustomerInfoManager.swift in Sources */,
F5FCD3EA27DA0D0B003BDC04 /* PriceFormatterProvider.swift in Sources */,
B3083A132699334C007B5503 /* Offering.swift in Sources */,
Expand Down Expand Up @@ -5834,9 +5844,7 @@
5766C622282DAA700067D886 /* GetIntroEligibilityResponse.swift in Sources */,
35E840CC270FB70D00899AE2 /* ManageSubscriptionsHelper.swift in Sources */,
6E38843A0CAFD551013D0A3F /* StoreProduct.swift in Sources */,
4FE6FEE52AA940B800780B45 /* PaywallStoredEvent.swift in Sources */,
FD20467F2CB82F2000166727 /* StoreKit2PurchaseIntentListener.swift in Sources */,
4FE6FEE52AA940B800780B45 /* StoredEvent.swift in Sources */,
B34605BD279A6E380031CA74 /* CallbackCacheStatus.swift in Sources */,
42F1DF385E3C1F9903A07FBF /* ProductsFetcherSK1.swift in Sources */,
805B60C97993B311CEC93EAF /* ProductsFetcherSK2.swift in Sources */,
Expand Down Expand Up @@ -6233,6 +6241,7 @@
1E5F8F782C46BBD90041EECD /* CustomerCenterAction.swift in Sources */,
1ED4CA9F2CC25A5F0021AB8F /* SafariView.swift in Sources */,
887A60CC2C1D037000E1A461 /* PaywallFontProvider.swift in Sources */,
2C91068E2CE2481A00189565 /* SizeModifier.swift in Sources */,
887A60B82C1D037000E1A461 /* Template1View.swift in Sources */,
887A60C62C1D037000E1A461 /* LoadingPaywallView.swift in Sources */,
88B1BAF22C813A3C001B7EE5 /* SpacerComponentView.swift in Sources */,
Expand Down Expand Up @@ -6284,6 +6293,7 @@
2C2AEB0F2CA64E0E00A50F38 /* Template1Preview.swift in Sources */,
88EA80ED2C8771A7003E6675 /* TemplateComponentsView+Extensions.swift in Sources */,
88A543E32C37A4970039C6A5 /* Template7View.swift in Sources */,
2C91068C2CE22D4F00189565 /* JustifyContent.swift in Sources */,
887A60CB2C1D037000E1A461 /* TemplateBackgroundImageView.swift in Sources */,
353FDC112CA4472B0055F328 /* StoreProduct+Extensions.swift in Sources */,
C3AD12BA2C6EA61F00A4F86F /* CompatibilityNavigationStack.swift in Sources */,
Expand Down Expand Up @@ -6336,6 +6346,7 @@
357CEC702C5940CE00A80837 /* ColorFromAppearance.swift in Sources */,
887A60832C1D037000E1A461 /* VersionDetector.swift in Sources */,
88B1BAFC2C813A3C001B7EE5 /* ImageComponentView.swift in Sources */,
2C91068A2CE22D3500189565 /* FlexVStack.swift in Sources */,
887A60872C1D037000E1A461 /* ViewExtensions.swift in Sources */,
2C8EC6DB2CCC23B700D6CCF8 /* Template5Preview.swift in Sources */,
88B1BB022C813A3C001B7EE5 /* StackComponentView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct PackageComponentView_Previews: PreviewProvider {
margin: .zero
))
],
dimension: .vertical(.leading),
dimension: .vertical(.leading, .start),
spacing: 0,
backgroundColor: nil,
padding: .init(top: 10,
Expand Down
71 changes: 71 additions & 0 deletions RevenueCatUI/Templates/Components/SizeModifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// SizeModifier.swift
//
// Created by Josh Holtz on 11/11/24.

import RevenueCat
import SwiftUI

#if PAYWALL_COMPONENTS

struct SizeModifier: ViewModifier {

var size: PaywallComponent.Size

func body(content: Content) -> some View {
content
.applyWidth(size.width)
.applyHeight(size.height)
}

}

extension View {

@ViewBuilder
func applyWidth(_ sizeConstraint: PaywallComponent.SizeConstraint) -> some View {
switch sizeConstraint {
case .fit:
self
case .fill:
self
.frame(maxWidth: .infinity)
case .fixed(let value):
self
.frame(width: CGFloat(value))
}
}

@ViewBuilder
func applyHeight(_ sizeConstraint: PaywallComponent.SizeConstraint) -> some View {
switch sizeConstraint {
case .fit:
self
case .fill:
self
.frame(maxHeight: .infinity)
case .fixed(let value):
self
.frame(height: CGFloat(value))
}
}

}

extension View {

func size(_ size: PaywallComponent.Size) -> some View {
self.modifier(SizeModifier(size: size))
}

}

#endif
5 changes: 1 addition & 4 deletions RevenueCatUI/Templates/Components/Stack/FlexHStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ import SwiftUI

#if PAYWALL_COMPONENTS

enum JustifyContent {
case start, center, end, spaceBetween, spaceAround, spaceEvenly
}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
struct FlexHStack: View {

let alignment: VerticalAlignment
let justifyContent: JustifyContent
let spacing: CGFloat?
Expand Down
92 changes: 92 additions & 0 deletions RevenueCatUI/Templates/Components/Stack/FlexVStack.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// FlexVStack.swift
//
// Created by Josh Holtz on 11/1/24.

import SwiftUI

#if PAYWALL_COMPONENTS

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
struct FlexVStack: View {
let alignment: HorizontalAlignment
let justifyContent: JustifyContent
let spacing: CGFloat?
let componentViewModels: [PaywallComponentViewModel]

let onDismiss: () -> Void

init(
alignment: HorizontalAlignment,
spacing: CGFloat?,
justifyContent: JustifyContent,
componentViewModels: [PaywallComponentViewModel],
onDismiss: @escaping () -> Void
) {
self.alignment = alignment
self.spacing = spacing
self.justifyContent = justifyContent
self.componentViewModels = componentViewModels
self.onDismiss = onDismiss
}

var body: some View {
VStack(alignment: self.alignment, spacing: self.spacing) {
switch justifyContent {
case .start:
ForEach(0..<componentViewModels.count, id: \.self) { index in
ComponentsView(componentViewModels: [self.componentViewModels[index]], onDismiss: self.onDismiss)
}
Spacer()

case .center:
Spacer()
ForEach(0..<componentViewModels.count, id: \.self) { index in
ComponentsView(componentViewModels: [self.componentViewModels[index]], onDismiss: self.onDismiss)
}
Spacer()

case .end:
Spacer()
ForEach(0..<componentViewModels.count, id: \.self) { index in
ComponentsView(componentViewModels: [self.componentViewModels[index]], onDismiss: self.onDismiss)
}

case .spaceBetween:
ForEach(0..<componentViewModels.count, id: \.self) { index in
ComponentsView(componentViewModels: [self.componentViewModels[index]], onDismiss: self.onDismiss)
if index < self.componentViewModels.count - 1 {
Spacer()
}
}

case .spaceAround:
Spacer()
ForEach(0..<componentViewModels.count, id: \.self) { index in
ComponentsView(componentViewModels: [self.componentViewModels[index]], onDismiss: self.onDismiss)
if index < self.componentViewModels.count - 1 {
Spacer()
}
}
Spacer()

case .spaceEvenly:
ForEach(0..<componentViewModels.count, id: \.self) { index in
Spacer()
ComponentsView(componentViewModels: [self.componentViewModels[index]], onDismiss: self.onDismiss)
}
Spacer()
}
}
}
}

#endif
44 changes: 44 additions & 0 deletions RevenueCatUI/Templates/Components/Stack/JustifyContent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// JustifyContent.swift
//
// Created by Josh Holtz on 11/11/24.

import Foundation
import RevenueCat

#if PAYWALL_COMPONENTS

enum JustifyContent {
case start, center, end, spaceBetween, spaceAround, spaceEvenly
}

extension PaywallComponent.FlexDistribution {

var justifyContent: JustifyContent {
switch self {
case .start:
return .start
case .center:
return .center
case .end:
return .end
case .spaceBetween:
return .spaceBetween
case .spaceAround:
return .spaceAround
case .spaceEvenly:
return .spaceEvenly
}
}

}

#endif
Loading