-
Notifications
You must be signed in to change notification settings - Fork 53
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] Adds a StyleFactory
#1965
Conversation
…ly build the StackComponentStyle and TextComponentStyle.
fun create(component: PaywallComponent): Result<ComponentStyle, NonEmptyList<PaywallValidationError>> = | ||
when (component) { | ||
is ButtonComponent -> TODO("ButtonComponentStyle is not yet implemented.") | ||
is ImageComponent -> TODO("ImageComponentStyle is not yet implemented.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not entirely true anymore, but I'd like to verify that this approach works before we add support for all the other ComponentStyle
s.
@@ -15,6 +15,7 @@ import com.revenuecat.purchases.ui.revenuecatui.errors.PaywallValidationError | |||
import com.revenuecat.purchases.ui.revenuecatui.extensions.createDefault | |||
import com.revenuecat.purchases.ui.revenuecatui.extensions.createDefaultForIdentifiers | |||
import com.revenuecat.purchases.ui.revenuecatui.extensions.defaultTemplate | |||
import kotlin.Result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was needed because the OfferingToStateMapper
is in the same package as the new Result
class, but it is using kotlin.Result
.
@@ -86,6 +86,7 @@ dependencies { | |||
testImplementation libs.coroutines.test | |||
testImplementation libs.kotlinx.serialization.json | |||
testImplementation libs.androidx.test.compose | |||
testImplementation libs.androidx.test.compose.manifest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests failed on CI due to a manifest merger issue.
This was already added as debugImplementation
, but we run tests for the release variant (as well), e.g. testDefaultsReleaseUnitTest
, so this makes sure we have it in any test variant, whether debug or release.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1965 +/- ##
=======================================
Coverage 81.87% 81.87%
=======================================
Files 260 260
Lines 8493 8493
Branches 1226 1226
=======================================
Hits 6954 6954
Misses 1041 1041
Partials 498 498 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this all makes sense! Just a couple questions
...evenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/components/ktx/Shape.kt
Show resolved
Hide resolved
...ui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/components/style/StyleFactory.kt
Outdated
Show resolved
Hide resolved
**This is an automatic release.** ## RevenueCatUI SDK ### 🐞 Bugfixes * Fix multi-tier template to allow optional header image (#1971) via Josh Holtz (@joshdholtz) ### 🔄 Other Changes * [Paywalls V2] Adds first version of `LoadedPaywallComponents` (#1970) via JayShortway (@JayShortway) * [Paywalls V2] Add `ButtonComponentView` (#1963) via Toni Rico (@tonidero) * [Paywalls V2] Adds `PaywallState.Loaded.Components` (#1969) via JayShortway (@JayShortway) * [Paywalls V2] Adds image background tests (#1967) via JayShortway (@JayShortway) * [Paywalls V2] `TextComponentView` updates when the theme changes (#1966) via JayShortway (@JayShortway) * [Paywalls V2] Adds a `StyleFactory` (#1965) via JayShortway (@JayShortway) * [EXTERNAL] fix: update polish translations (#1919) via @radko93 (#1964) via JayShortway (@JayShortway) * [Paywalls V2] Adds `ImageComponentView` (#1959) via Toni Rico (@tonidero) * WebPurchaseRedemption: Rename `AlreadyRedeemed` result to `PurchaseBelongsToOtherUser` (#1962) via Toni Rico (@tonidero) * [Paywalls V2] Extends support for blurred shadows to all Android versions (#1957) via JayShortway (@JayShortway) Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Description
This PR includes all the scaffolding needed to recursively build the tree of
ComponentStyle
s, and to validate that all components are correctly configured (e.g. all localizations are available). Any errors encountered are accumulated, so they can all be reported at once. (As opposed to failing fast, in which case only the first error would be reported.)Apologies for the size of this PR, but I think separating some of these changes would make it hard to see how they're used. So, take this 👇 map and let me guide you.
🗺️ Guide
purchases
In support of the main change
revenuecatui
. Data classes are made@Poko
s if they're public.Result
to explain the fact that it is duplicated inrevenuecatui
.revenuecatui
In support of the main change
Result
class frompurchases
is copied. A few extensions, mostly inspired by Arrow, are added. Most importantly:zipOrAccumulate
: takes multipleResult
s and either combines their successful values, or accumulates the errors.mapOrAccumulate
: takes aList<Result>
and turns it into aResult<List>
by mapping either its successful values, or accumulating the errors.NonEmptyList
class is added, also inspired by Arrow. This is useful for error accumulation. If we used a normalList
type for this, we could still end up in the invalid state of receiving anError
result with an empty list of errors. Using aNonEmptyList
, it is guaranteed we have at least 1 error in this case.Result
type.The main change
StyleFactory
that can createComponentStyle
s recursively to build a tree. It uses the newResult
class, the extensions, and theNonEmptyList
to accumulate any errors found. Its logic is loosely based on theViewModelFactory
and individual*ComponentViewModel
s in iOS.PackageContext
, based on the class of the same name in iOS.toShape()
, to be able to build theStackComponentStyle
.StyleFactoryTests
are added.VariableContextTests
are added. This is an inner class toPackageContext
containing the most logic.