-
Notifications
You must be signed in to change notification settings - Fork 54
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] Moves more state to PaywallState
#1988
Conversation
class Components( | ||
override val offering: Offering, | ||
val data: PaywallComponentsData, | ||
) : Loaded | ||
initialLocaleList: LocaleList = LocaleList.current, | ||
initialIsEligibleForIntroOffer: Boolean = false, | ||
initialSelectedPackage: Package? = null, | ||
) : Loaded { | ||
private var localeId by mutableStateOf(initialLocaleList.toLocaleId()) | ||
|
||
val localizationDictionary by derivedStateOf { data.componentsLocalizations.getValue(localeId) } | ||
val locale by derivedStateOf { localeId.toLocale() } | ||
|
||
var isEligibleForIntroOffer by mutableStateOf(initialIsEligibleForIntroOffer) | ||
private set | ||
var selectedPackage by mutableStateOf<Package?>(initialSelectedPackage) | ||
private set | ||
|
||
// TODO Actually determine this. | ||
val showZeroDecimalPlacePrices: Boolean = true | ||
val mostExpensivePricePerMonthMicros: Long? = offering.availablePackages.mostExpensivePricePerMonthMicros() | ||
|
||
fun update(localeList: FrameworkLocaleList? = null, isEligibleForIntroOffer: Boolean? = null) { | ||
if (localeList != null) localeId = LocaleList(localeList.toLanguageTags()).toLocaleId() | ||
if (isEligibleForIntroOffer != null) this.isEligibleForIntroOffer = isEligibleForIntroOffer | ||
} | ||
|
||
fun update(selectedPackage: Package?) { | ||
this.selectedPackage = selectedPackage | ||
} | ||
|
||
private fun LocaleList.toLocaleId(): LocaleId = | ||
// Configured locales take precedence over the default one. | ||
map { it.toLocaleId() }.plus(data.defaultLocaleIdentifier) | ||
// Find the first locale we have a LocalizationDictionary for. | ||
.first { id -> data.componentsLocalizations.containsKey(id) } | ||
|
||
private fun LocaleId.toLocale(): Locale = | ||
Locale(value.replace('_', '-')) | ||
|
||
private fun Locale.toLocaleId(): LocaleId = | ||
LocaleId(toLanguageTag().replace('-', '_')) | ||
|
||
private fun List<Package>.mostExpensivePricePerMonthMicros(): Long? = | ||
asSequence() | ||
.map { pkg -> pkg.product } | ||
.mapNotNull { product -> product.pricePerMonth() } | ||
.maxByOrNull { price -> price.amountMicros } | ||
?.amountMicros | ||
} |
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 the main change in this PR ☝️
# Conflicts: # ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/components/LoadedPaywallComponents.kt # ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/components/button/ButtonComponentView.kt # ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/components/stack/StackComponentView.kt # ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/components/text/TextComponentView.kt # ui/revenuecatui/src/test/kotlin/com/revenuecat/purchases/ui/revenuecatui/components/stack/StackComponentViewTests.kt # ui/revenuecatui/src/test/kotlin/com/revenuecat/purchases/ui/revenuecatui/components/text/TextComponentViewTests.kt
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1988 +/- ##
==========================================
- Coverage 81.90% 81.89% -0.02%
==========================================
Files 260 260
Lines 8505 8511 +6
Branches 1227 1227
==========================================
+ Hits 6966 6970 +4
- Misses 1039 1041 +2
Partials 500 500 ☔ 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.
Changes are ok but I'm just wondering about the architecture... We're still on time to change it if needed though, so will approve it.
ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/data/PaywallState.kt
Show resolved
Hide resolved
**This is an automatic release.** ## RevenueCat SDK ### 📦 Dependency Updates * Bump fastlane from 2.225.0 to 2.226.0 (#1973) via dependabot[bot] (@dependabot[bot]) * Bump fastlane-plugin-revenuecat_internal from `3b1e7cf` to `4ee8579` (#1980) via dependabot[bot] (@dependabot[bot]) ### 🔄 Other Changes * [Paywalls V2] Fixes previews of `ButtonComponentView`, `StackComponentView` and `TextComponentView` (#1992) via JayShortway (@JayShortway) * [Paywalls V2] Adds a `FLAG_PAYWALL_COMPONENTS` build flag (#1990) via JayShortway (@JayShortway) * [Paywalls V2] Moves more state to `PaywallState` (#1988) via JayShortway (@JayShortway) * [PaywallsV2] Improve `ButtonComponentView` to handle disabling the button and add `PurchasePackage` action (#1984) via Toni Rico (@tonidero) * [Paywalls V2] `TextComponentStyle` no longer needs a Composable context (#1986) via JayShortway (@JayShortway) * Make web redemption link APIs stable (#1985) via Toni Rico (@tonidero) * [WEB-1757] Handle new backend error codes that may show in the redemption endpoint (#1987) via Toni Rico (@tonidero) * [Paywalls V2] Stack background, borders and shadows update depending on the theme (#1982) via JayShortway (@JayShortway) * [Paywalls V2] Fixes `TextComponentView`'s font size (#1981) via JayShortway (@JayShortway) * [Paywalls V2] Various minor fixes (#1979) via JayShortway (@JayShortway) * [Paywalls V2] Adds support to PaywallsTester (#1978) via JayShortway (@JayShortway) * [Paywalls V2] Adds `PaywallComponentsData` to `Offering` (#1977) via JayShortway (@JayShortway) * Parse web redemption link strings more defensively (#1976) via Toni Rico (@tonidero) * Add web redemption parse method for strings to support hybrids (#1972) via Toni Rico (@tonidero) Co-authored-by: revenuecat-ops <[email protected]>
Description
In this PR we start making more use of
PaywallState.Loaded.Components
to drive.. you guessed it.. state! 😄 CurrentlyTextComponentView
is the most affected by this.Other changes
PackageContext
withPaywallState.Loaded.Components
, and deletes the former.LoadedPaywallComponentsLocaleTests
.localeChangingTest()
for easy testing of behavior under locale changes.VariableContextTests
toMostExpensivePricePerMonthMicrosTests
.