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] New overrides structure #4705

Merged
merged 3 commits into from
Jan 27, 2025

Conversation

joshdholtz
Copy link
Member

@joshdholtz joshdholtz commented Jan 25, 2025

Motivation

Migrating overrides from a structured object to an array of override objects

Description

Previously

Overrides were a very structure object that had all of the different types of states/conditions that allowed base properties of a component to be overridden. However, this was not flexible when it came to multiple being activated as it was missing for cases when multiples types of conditions were being evaluated.

Now

Overrides is an array that has an array of conditions and properties. It will get applied in order from first to last IF all of the conditions are true.

This allows the FE/BE to determine the orders of overrides from lowest to higher priority so all of the SDKs/renderers don't need to duplicate that logic.

@joshdholtz joshdholtz changed the base branch from main to paywalls-v2/new-overrides-part-1-api January 25, 2025 17:08
@joshdholtz joshdholtz requested a review from a team January 25, 2025 17:08
@joshdholtz joshdholtz changed the base branch from paywalls-v2/new-overrides-part-1-api to main January 27, 2025 10:24
@joshdholtz joshdholtz changed the title [Paywalls V2] Apply new overrides [Paywalls V2] New overrides structure Jan 27, 2025
Copy link

emerge-tools bot commented Jan 27, 2025

1 build decreased size

Name Version Download Change Install Change Approval
Paywalls
com.revenuecat.PaywallsTester
1.0 (1) 10.7 MB ⬇️ 43.9 kB (-0.41%) 40.3 MB ⬇️ 176.5 kB (-0.44%) N/A

Paywalls 1.0 (1)
com.revenuecat.PaywallsTester

⚖️ Compare build
📦 Install build
⏱️ Analyze build performance

Total install size change: ⬇️ 176.5 kB (-0.44%)
Total download size change: ⬇️ 43.9 kB (-0.41%)

Largest size changes

Item Install Size Change
DYLD.String Table ⬇️ -39.9 kB
RevenueCatUI.TextComponentViewModel.TextComponentViewModel ⬇️ -14.4 kB
RevenueCatUI.ImageComponentViewModel.ImageComponentViewModel ⬇️ -12.2 kB
Code Signature ⬇️ -4.9 kB
DYLD.Exports ⬇️ -1.4 kB
View Treemap

Image of diff


🛸 Powered by Emerge Tools

Comment trigger: Size diff threshold of 100.00kB exceeded

@joshdholtz joshdholtz marked this pull request as ready for review January 27, 2025 10:29
@joshdholtz joshdholtz requested a review from a team January 27, 2025 10:29
Comment on lines +63 to +68
for presentedOverride in presentedOverrides where self.shouldApply(
for: presentedOverride.conditions,
state: state,
activeCondition: condition,
isEligibleForIntroOffer: isEligibleForIntroOffer) {
presentedPartial = Self.combine(presentedPartial, with: presentedOverride.properties)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where the overrides are iterated from lowest to higher priority (in the order they are given) and will only combine them if all the conditions are true

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean!

Comment on lines +74 to +96
private static func shouldApply(
for conditions: [PaywallComponent.Condition],
state: ComponentViewState,
activeCondition: ScreenCondition,
isEligibleForIntroOffer: Bool
) -> Bool {
// Early return when any condition evaluates to false
for condition in conditions {
switch condition {
case .compact, .medium, .expanded:
if !activeCondition.applicableConditions.contains(condition) {
return false
}
case .introOffer:
if !isEligibleForIntroOffer {
return false
}
case .selected:
if state != .selected {
return false
}
case .unsupported:
return false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic for determining if all the conditions are true

Comment on lines +46 to +47
// For unknown cases
case unsupported
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a case for unsupported so that the decoding wouldn't fail for multiple_intro_offers or if any other new ones where added

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

Copy link
Member

@JayShortway JayShortway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! 🙌

Comment on lines +63 to +68
for presentedOverride in presentedOverrides where self.shouldApply(
for: presentedOverride.conditions,
state: state,
activeCondition: condition,
isEligibleForIntroOffer: isEligibleForIntroOffer) {
presentedPartial = Self.combine(presentedPartial, with: presentedOverride.properties)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean!

}

return true
}

}

private extension ScreenCondition {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not suggesting or requesting any changes, especially not in this PR, but do we still need ScreenCondition? Can we not make do with just PaywallComponent.Condition?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhhhhh, this is a good point! I think we can totally merge the two in a follow up PR 👍

Comment on lines +46 to +47
// For unknown cases
case unsupported
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

@joshdholtz joshdholtz merged commit a6736b4 into main Jan 27, 2025
10 checks passed
@joshdholtz joshdholtz deleted the paywalls-v2/new-overrides-part-2-ui branch January 27, 2025 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants