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] Implements Variables V2 #2099

Merged
merged 100 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
a0b0911
Fixes compilation of IconComponentView.
JayShortway Jan 22, 2025
fbb2cb6
ColorInfo.Alias has a ColorAlias value now.
JayShortway Jan 22, 2025
6357b73
Adds ColorStyles and a way to look them up.
JayShortway Jan 22, 2025
c0c801a
Adds UiConfig to StyleFactory and uses it to build StackComponentStyle.
JayShortway Jan 22, 2025
3dd6bf8
Adds PresentedStackPartialTests and a fix to ColorStyle.
JayShortway Jan 22, 2025
9946cc8
Adds ColorStyleTests
JayShortway Jan 22, 2025
ee91fd8
Merge branch 'main' into pw2-colorstyles
JayShortway Jan 22, 2025
d3e81c2
Updates documentation for a function.
JayShortway Jan 23, 2025
b148227
Renames a parameter.
JayShortway Jan 23, 2025
ab6a491
Fixes a compilation error.
JayShortway Jan 23, 2025
044b221
Fixes test compilation.
JayShortway Jan 23, 2025
8aeedbb
Adds ColorStyles to IconComponentStyle.
JayShortway Jan 23, 2025
ba778c0
Adds ColorStyles to IconComponentStyle.Background.
JayShortway Jan 23, 2025
0b36305
Adds PresentedIconPartialTests.
JayShortway Jan 23, 2025
fe11b77
Merge branch 'main' into pw2-colorstyles-icon
JayShortway Jan 23, 2025
f21353d
ImageComponentStyle.overlay is a ColorStyles now.
JayShortway Jan 23, 2025
240f508
Adds PresentedImagePartialTests.
JayShortway Jan 23, 2025
8e814c9
Changes ColorScheme properties to ColorStyles in TextComponentStyle.
JayShortway Jan 23, 2025
a733f8b
Adds more LocalizedTextPartialTests.
JayShortway Jan 23, 2025
89c5286
Introduces BorderStyles and adds it to StackComponentStyle.
JayShortway Jan 24, 2025
0b25b3b
Adds BorderStyles to IconComponentStyle.Background.
JayShortway Jan 24, 2025
7be4c38
Adds BorderStyles to ImageComponentStyle.
JayShortway Jan 24, 2025
7ab352b
Introduces ShadowStyles and adds it to StackComponentStyle.
JayShortway Jan 24, 2025
a508cf5
Adds ShadowStyles to IconComponentStyle.Background.
JayShortway Jan 24, 2025
da30ef7
Adds ShadowStyles to ImageComponentStyle.
JayShortway Jan 24, 2025
56e6b80
Adds BackgroundStyles and uses it for the main paywall.
JayShortway Jan 24, 2025
a7f46a8
Removes a bunch of functions that are not needed anymore.
JayShortway Jan 24, 2025
8b20983
Merge branch 'main' into pw2-colorstyles-icon
JayShortway Jan 24, 2025
27dd90f
Merge branch 'pw2-colorstyles-icon' into pw2-colorstyles-image
JayShortway Jan 24, 2025
199816c
Merge branch 'pw2-colorstyles-image' into pw2-colorstyles-text
JayShortway Jan 24, 2025
5300158
Merge branch 'pw2-colorstyles-text' into pw2-colorstyles-border
JayShortway Jan 24, 2025
967b4f0
Merge branch 'pw2-colorstyles-border' into pw2-colorstyles-shadow
JayShortway Jan 24, 2025
5891761
Merge branch 'pw2-colorstyles-shadow' into pw2-colorstyles-background
JayShortway Jan 24, 2025
e9a081f
Merge branch 'pw2-colorstyles-background' into pw2-color-alias-cleanup
JayShortway Jan 24, 2025
b5d90c1
Adds getResourceIdentifier() to ResourceProvider.
JayShortway Jan 27, 2025
44d9af5
Merge branch 'main' into pw2-colorstyles-background
JayShortway Jan 27, 2025
11eb74a
Re-reverts an unintended change.
JayShortway Jan 27, 2025
3ce1c66
Fixes a test.
JayShortway Jan 27, 2025
ae87952
Merge branch 'main' into pw2-colorstyles-background
JayShortway Jan 27, 2025
0ee2a8c
Merge branch 'pw2-colorstyles-background' into pw2-color-alias-cleanup
JayShortway Jan 27, 2025
24d01d6
Merge branch 'pw2-color-alias-cleanup' into pw2-fonts-uiconfig
JayShortway Jan 27, 2025
70cf708
Adds FontSpec.
JayShortway Jan 27, 2025
2388bd8
Adds fontAliases parameter to StyleFactory.
JayShortway Jan 27, 2025
36c3352
Adds fontAliases parameter to StyleFactory.
JayShortway Jan 27, 2025
926775f
StyleFactory resolves FontSpecs.
JayShortway Jan 27, 2025
841357e
Merge branch 'main' into pw2-fonts-uiconfig
JayShortway Jan 27, 2025
31a43ad
TextComponent.fontName is a FontAlias now.
JayShortway Jan 27, 2025
4ac6a5f
Adds FontSpec to TextComponentStyle and LocalizedTextPartial.
JayShortway Jan 27, 2025
ad309de
Adds more tests to StyleFactoryTests.
JayShortway Jan 27, 2025
fc6cbf3
Deletes SystemFontFamily.
JayShortway Jan 27, 2025
d5791da
Fixes LocalizedTextPartialTests.
JayShortway Jan 27, 2025
6b31f04
Adds some LocalizedTextPartialTests.
JayShortway Jan 27, 2025
79e61f6
Renames FontSpec.Device to FontSpec.System.
JayShortway Jan 27, 2025
5874fc0
Adds some PaywallComponentDataValidationTests.
JayShortway Jan 27, 2025
1868c25
Merge branch 'main' into pw2-fonts-uiconfig
JayShortway Jan 28, 2025
9b7cb53
Fixes FontFamily not getting applied in the Markdown composable.
JayShortway Jan 28, 2025
6dc16a1
Adds custom font paywall to PaywallsTester.
JayShortway Jan 28, 2025
4779152
Removes passing the MockResourceProvider by default. Resolves a TODO.
JayShortway Jan 28, 2025
6c020e6
Adds a Google Font paywall to PaywallsTester.
JayShortway Jan 28, 2025
314b364
Merge branch 'main' into pw2-fonts-uiconfig
JayShortway Jan 28, 2025
1ba3c5b
Fixes compilation after merge.
JayShortway Jan 28, 2025
9a0ce39
Adds localizedPricePerDay() and localizedPricePerYear() to VariableDa…
JayShortway Jan 29, 2025
39566ae
Adds a new PaywallValidationError.
JayShortway Jan 29, 2025
488bf38
Adds StyleFactory and UiConfig convenience constructors for tests.
JayShortway Jan 29, 2025
aa7071d
Adds pricePerPeriod extensions.
JayShortway Jan 29, 2025
b87e977
Uses the new UiConfig and StyleFactory test helpers.
JayShortway Jan 30, 2025
54089c1
Adds ComposeLocale.toJavaLocale().
JayShortway Jan 30, 2025
bb56c91
Adds variableLocalizationKeysForEnUs() to PreviewHelpers.kt.
JayShortway Jan 30, 2025
64dc407
Adds Period.valueInDays.
JayShortway Jan 30, 2025
552c32f
Uses previewTextComponentStyle in more places.
JayShortway Jan 30, 2025
2561714
Adds pricePerDay to StoreProduct.
JayShortway Jan 30, 2025
bf0fe56
TextComponentView processes variables with VariableProcessorV2.
JayShortway Jan 30, 2025
7529ab7
Adds a failing TextComponentViewVariablesTests.
JayShortway Jan 30, 2025
82f08dd
Fixes a few tests.
JayShortway Jan 30, 2025
57f7af0
Fixes another test.
JayShortway Jan 30, 2025
d4059ae
Passes Date around.
JayShortway Jan 30, 2025
d57fe0b
Fixes the final test.
JayShortway Jan 30, 2025
f0dfde4
Adds V2 variables to TextComponentViewTests.
JayShortway Jan 30, 2025
fdf5019
Adds a bunch more test cases.
JayShortway Jan 30, 2025
c722cd4
Adds a bunch more test cases, some failing.
JayShortway Jan 30, 2025
faa6184
Fixes tests.
JayShortway Jan 30, 2025
d42258a
TextComponentView longer processes V1 variables.
JayShortway Jan 30, 2025
6bd4cc9
Some cleanup.
JayShortway Jan 30, 2025
96dbfdd
Adds some tests.
JayShortway Jan 30, 2025
dbb2ac3
Some optimizations.
JayShortway Jan 30, 2025
89dbac0
Some cleanup.
JayShortway Jan 30, 2025
4343164
Merge branch 'main' into pw2-variables-v2
JayShortway Jan 30, 2025
307cbd5
Fixes previews.
JayShortway Jan 30, 2025
aba0a43
Adds StyleFactory and UiConfig convenience constructors for tests.
JayShortway Jan 30, 2025
707955a
Adds variableLocalizations to TextComponentStyle, and uses previewTex…
JayShortway Jan 30, 2025
6b027d5
Adds new price calculations needed for Variables V2.
JayShortway Jan 30, 2025
31ba3f7
Merge branch 'pw2-variables-v2-2' into pw2-variables-v2-3
JayShortway Jan 30, 2025
3c7056f
Attempts to fix broken previews.
JayShortway Jan 31, 2025
e295e57
Merge branch 'main' into pw2-variables-v2-3
JayShortway Jan 31, 2025
8c32df8
Merge branch 'main' into pw2-variables-v2-3
JayShortway Feb 4, 2025
523097d
Merge branch 'main' into pw2-variables-v2-3
JayShortway Feb 4, 2025
8189144
Fixes compilation.
JayShortway Feb 5, 2025
eb7529a
Adds tests for a lifetime product.
JayShortway Feb 5, 2025
f0c0e39
Corrects the lifetime product's description.
JayShortway Feb 5, 2025
6484ed8
Merge branch 'main' into pw2-variables-v2-3
JayShortway Feb 5, 2025
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
Prev Previous commit
Next Next commit
Adds FontSpec to TextComponentStyle and LocalizedTextPartial.
  • Loading branch information
JayShortway committed Jan 27, 2025
commit 4ac6a5f652fc4ccf6a9f8ea8b6ebde2d89deb386
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.revenuecat.purchases.ui.revenuecatui.components

import com.revenuecat.purchases.ColorAlias
import com.revenuecat.purchases.FontAlias
import com.revenuecat.purchases.paywalls.components.PartialTextComponent
import com.revenuecat.purchases.paywalls.components.common.LocaleId
import com.revenuecat.purchases.paywalls.components.properties.ColorScheme
import com.revenuecat.purchases.ui.revenuecatui.components.ktx.LocalizationDictionary
import com.revenuecat.purchases.ui.revenuecatui.components.ktx.stringForAllLocales
import com.revenuecat.purchases.ui.revenuecatui.components.properties.ColorStyles
import com.revenuecat.purchases.ui.revenuecatui.components.properties.FontSpec
import com.revenuecat.purchases.ui.revenuecatui.components.properties.getFontSpec
import com.revenuecat.purchases.ui.revenuecatui.components.properties.toColorStyles
import com.revenuecat.purchases.ui.revenuecatui.errors.PaywallValidationError
import com.revenuecat.purchases.ui.revenuecatui.helpers.NonEmptyList
import com.revenuecat.purchases.ui.revenuecatui.helpers.NonEmptyMap
import com.revenuecat.purchases.ui.revenuecatui.helpers.Result
import com.revenuecat.purchases.ui.revenuecatui.helpers.mapError
import com.revenuecat.purchases.ui.revenuecatui.helpers.nonEmptyListOf
import com.revenuecat.purchases.ui.revenuecatui.helpers.orSuccessfullyNull
import com.revenuecat.purchases.ui.revenuecatui.helpers.zipOrAccumulate
import dev.drewhamilton.poko.Poko
Expand All @@ -21,6 +26,7 @@ internal class LocalizedTextPartial private constructor(
@get:JvmSynthetic val texts: NonEmptyMap<LocaleId, String>?,
@get:JvmSynthetic val color: ColorStyles?,
@get:JvmSynthetic val backgroundColor: ColorStyles?,
@get:JvmSynthetic val fontSpec: FontSpec?,
@get:JvmSynthetic val partial: PartialTextComponent,
) : PresentedPartial<LocalizedTextPartial> {

Expand All @@ -35,18 +41,24 @@ internal class LocalizedTextPartial private constructor(
from: PartialTextComponent,
using: NonEmptyMap<LocaleId, LocalizationDictionary>,
aliases: Map<ColorAlias, ColorScheme>,
fontAliases: Map<FontAlias, FontSpec>,
): Result<LocalizedTextPartial, NonEmptyList<PaywallValidationError>> =
zipOrAccumulate(
first = from.text
?.let { localizationKey -> using.stringForAllLocales(localizationKey) }
.orSuccessfullyNull(),
second = from.color?.toColorStyles(aliases).orSuccessfullyNull(),
third = from.backgroundColor?.toColorStyles(aliases).orSuccessfullyNull(),
) { texts, color, backgroundColor ->
fourth = from.fontName
?.let { fontAliases.getFontSpec(it) }
.orSuccessfullyNull()
.mapError { nonEmptyListOf(it) },
) { texts, color, backgroundColor, fontSpec ->
LocalizedTextPartial(
texts = texts,
color = color,
backgroundColor = backgroundColor,
fontSpec = fontSpec,
partial = from,
)
}
Expand All @@ -61,6 +73,7 @@ internal class LocalizedTextPartial private constructor(
texts = with?.texts ?: texts,
color = with?.color ?: color,
backgroundColor = with?.backgroundColor ?: backgroundColor,
fontSpec = with?.fontSpec ?: fontSpec,
partial = PartialTextComponent(
visible = otherPartial?.visible ?: partial.visible,
text = otherPartial?.text ?: partial.text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private fun previewButtonComponentStyle(
),
fontSize = 15,
fontWeight = FontWeight.REGULAR.toFontWeight(),
fontFamily = null,
fontSpec = null,
textAlign = HorizontalAlignment.CENTER.toTextAlign(),
horizontalAlignment = HorizontalAlignment.CENTER.toAlignment(),
backgroundColor = ColorStyles(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import com.revenuecat.purchases.paywalls.components.properties.TwoDimensionalAli
import com.revenuecat.purchases.paywalls.components.properties.VerticalAlignment
import com.revenuecat.purchases.ui.revenuecatui.components.ComponentView
import com.revenuecat.purchases.ui.revenuecatui.components.PaywallAction
import com.revenuecat.purchases.ui.revenuecatui.components.SystemFontFamily
import com.revenuecat.purchases.ui.revenuecatui.components.ktx.toAlignment
import com.revenuecat.purchases.ui.revenuecatui.components.ktx.toFontWeight
import com.revenuecat.purchases.ui.revenuecatui.components.ktx.toHorizontalAlignmentOrNull
Expand All @@ -80,6 +79,7 @@ import com.revenuecat.purchases.ui.revenuecatui.components.modifier.size
import com.revenuecat.purchases.ui.revenuecatui.components.properties.BorderStyles
import com.revenuecat.purchases.ui.revenuecatui.components.properties.ColorStyle
import com.revenuecat.purchases.ui.revenuecatui.components.properties.ColorStyles
import com.revenuecat.purchases.ui.revenuecatui.components.properties.FontSpec
import com.revenuecat.purchases.ui.revenuecatui.components.properties.ShadowStyles
import com.revenuecat.purchases.ui.revenuecatui.components.properties.forCurrentTheme
import com.revenuecat.purchases.ui.revenuecatui.components.properties.rememberBorderStyle
Expand Down Expand Up @@ -905,7 +905,7 @@ private fun StackComponentView_Preview_ZLayer() {
),
fontSize = 15,
fontWeight = FontWeight.REGULAR.toFontWeight(),
fontFamily = null,
fontSpec = null,
textAlign = HorizontalAlignment.CENTER.toTextAlign(),
horizontalAlignment = HorizontalAlignment.CENTER.toAlignment(),
backgroundColor = ColorStyles(
Expand All @@ -925,7 +925,7 @@ private fun StackComponentView_Preview_ZLayer() {
),
fontSize = 15,
fontWeight = FontWeight.REGULAR.toFontWeight(),
fontFamily = null,
fontSpec = null,
textAlign = HorizontalAlignment.CENTER.toTextAlign(),
horizontalAlignment = HorizontalAlignment.CENTER.toAlignment(),
backgroundColor = ColorStyles(
Expand Down Expand Up @@ -1110,7 +1110,7 @@ private fun previewChildren() = listOf(
),
fontSize = 15,
fontWeight = FontWeight.REGULAR.toFontWeight(),
fontFamily = null,
fontSpec = null,
textAlign = HorizontalAlignment.CENTER.toTextAlign(),
horizontalAlignment = HorizontalAlignment.CENTER.toAlignment(),
backgroundColor = ColorStyles(
Expand All @@ -1129,7 +1129,7 @@ private fun previewChildren() = listOf(
),
fontSize = 15,
fontWeight = FontWeight.REGULAR.toFontWeight(),
fontFamily = null,
fontSpec = null,
textAlign = HorizontalAlignment.CENTER.toTextAlign(),
horizontalAlignment = HorizontalAlignment.CENTER.toAlignment(),
backgroundColor = ColorStyles(
Expand All @@ -1149,7 +1149,7 @@ private fun previewTextComponentStyle(
color: ColorStyles = ColorStyles(ColorStyle.Solid(Color.Black)),
fontSize: Int = 15,
fontWeight: FontWeight = FontWeight.REGULAR,
fontFamily: String? = null,
fontSpec: FontSpec? = null,
textAlign: HorizontalAlignment = HorizontalAlignment.CENTER,
horizontalAlignment: HorizontalAlignment = HorizontalAlignment.CENTER,
backgroundColor: ColorStyles? = null,
Expand All @@ -1163,7 +1163,7 @@ private fun previewTextComponentStyle(
color = color,
fontSize = fontSize,
fontWeight = weight,
fontFamily = fontFamily?.let { SystemFontFamily(it, weight) },
fontSpec = fontSpec,
textAlign = textAlign.toTextAlign(),
horizontalAlignment = horizontalAlignment.toAlignment(),
backgroundColor = backgroundColor,
Expand Down Expand Up @@ -1222,7 +1222,7 @@ private fun previewBadge(style: Badge.Style, alignment: TwoDimensionalAlignment,
),
fontSize = 15,
fontWeight = FontWeight.REGULAR.toFontWeight(),
fontFamily = null,
fontSpec = null,
textAlign = HorizontalAlignment.CENTER.toTextAlign(),
horizontalAlignment = HorizontalAlignment.CENTER.toAlignment(),
backgroundColor = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.revenuecat.purchases.ui.revenuecatui.components.style

import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.unit.dp
import com.revenuecat.purchases.FontAlias
import com.revenuecat.purchases.Offering
Expand Down Expand Up @@ -35,7 +34,6 @@ import com.revenuecat.purchases.ui.revenuecatui.components.ktx.toShape
import com.revenuecat.purchases.ui.revenuecatui.components.ktx.toTextAlign
import com.revenuecat.purchases.ui.revenuecatui.components.properties.FontSpec
import com.revenuecat.purchases.ui.revenuecatui.components.properties.getFontSpec
import com.revenuecat.purchases.ui.revenuecatui.components.properties.resolve
import com.revenuecat.purchases.ui.revenuecatui.components.properties.toBorderStyles
import com.revenuecat.purchases.ui.revenuecatui.components.properties.toColorStyles
import com.revenuecat.purchases.ui.revenuecatui.components.properties.toShadowStyles
Expand Down Expand Up @@ -225,7 +223,14 @@ internal class StyleFactory(
first = localizations.stringForAllLocales(component.text),
second = component.overrides
// Map all overrides to PresentedOverrides.
?.toPresentedOverrides { LocalizedTextPartial(from = it, using = localizations, aliases = colorAliases) }
?.toPresentedOverrides {
LocalizedTextPartial(
from = it,
using = localizations,
aliases = colorAliases,
fontAliases = fontAliases,
)
}
.orSuccessfullyNull()
.mapError { nonEmptyListOf(it) },
third = component.color.toColorStyles(colorAliases),
Expand All @@ -241,7 +246,7 @@ internal class StyleFactory(
color = color,
fontSize = component.fontSize,
fontWeight = weight,
fontFamily = fontSpec?.resolve(weight = weight, style = FontStyle.Normal),
fontSpec = fontSpec,
textAlign = component.horizontalAlignment.toTextAlign(),
horizontalAlignment = component.horizontalAlignment.toAlignment(),
backgroundColor = backgroundColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.revenuecat.purchases.ui.revenuecatui.components.style
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Immutable
import androidx.compose.ui.Alignment
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import com.revenuecat.purchases.Package
Expand All @@ -12,6 +11,7 @@ import com.revenuecat.purchases.paywalls.components.properties.Size
import com.revenuecat.purchases.ui.revenuecatui.components.LocalizedTextPartial
import com.revenuecat.purchases.ui.revenuecatui.components.PresentedOverrides
import com.revenuecat.purchases.ui.revenuecatui.components.properties.ColorStyles
import com.revenuecat.purchases.ui.revenuecatui.components.properties.FontSpec
import com.revenuecat.purchases.ui.revenuecatui.helpers.NonEmptyMap

@Suppress("LongParameterList")
Expand All @@ -26,7 +26,7 @@ internal class TextComponentStyle(
@get:JvmSynthetic
val fontWeight: FontWeight?,
@get:JvmSynthetic
val fontFamily: FontFamily?,
val fontSpec: FontSpec?,
@get:JvmSynthetic
val textAlign: TextAlign?,
@get:JvmSynthetic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.intl.Locale
import androidx.window.core.layout.WindowWidthSizeClass
import com.revenuecat.purchases.Package
import com.revenuecat.purchases.ui.revenuecatui.components.ComponentViewState
import com.revenuecat.purchases.ui.revenuecatui.components.ScreenCondition
import com.revenuecat.purchases.ui.revenuecatui.components.SystemFontFamily
import com.revenuecat.purchases.ui.revenuecatui.components.buildPresentedPartial
import com.revenuecat.purchases.ui.revenuecatui.components.ktx.toAlignment
import com.revenuecat.purchases.ui.revenuecatui.components.ktx.toFontWeight
import com.revenuecat.purchases.ui.revenuecatui.components.ktx.toLocaleId
import com.revenuecat.purchases.ui.revenuecatui.components.ktx.toPaddingValues
import com.revenuecat.purchases.ui.revenuecatui.components.ktx.toTextAlign
import com.revenuecat.purchases.ui.revenuecatui.components.properties.resolve
import com.revenuecat.purchases.ui.revenuecatui.components.style.TextComponentStyle
import com.revenuecat.purchases.ui.revenuecatui.composables.IntroOfferEligibility
import com.revenuecat.purchases.ui.revenuecatui.data.PaywallState
Expand Down Expand Up @@ -109,9 +111,13 @@ internal class TextComponentState(
@get:JvmSynthetic
val fontWeight by derivedStateOf { presentedPartial?.partial?.fontWeight?.toFontWeight() ?: style.fontWeight }

private val fontSpec by derivedStateOf {
presentedPartial?.fontSpec ?: style.fontSpec
}

@get:JvmSynthetic
val fontFamily by derivedStateOf {
presentedPartial?.partial?.fontName?.let { SystemFontFamily(it.value, fontWeight) } ?: style.fontFamily
fontSpec?.resolve(weight = fontWeight ?: FontWeight.Normal, style = FontStyle.Normal)
}

@get:JvmSynthetic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import com.revenuecat.purchases.paywalls.components.properties.Size
import com.revenuecat.purchases.paywalls.components.properties.SizeConstraint
import com.revenuecat.purchases.paywalls.components.properties.SizeConstraint.Fill
import com.revenuecat.purchases.paywalls.components.properties.SizeConstraint.Fit
import com.revenuecat.purchases.ui.revenuecatui.components.SystemFontFamily
import com.revenuecat.purchases.ui.revenuecatui.components.ktx.toAlignment
import com.revenuecat.purchases.ui.revenuecatui.components.ktx.toFontWeight
import com.revenuecat.purchases.ui.revenuecatui.components.ktx.toPaddingValues
Expand All @@ -48,6 +47,7 @@ import com.revenuecat.purchases.ui.revenuecatui.components.modifier.background
import com.revenuecat.purchases.ui.revenuecatui.components.modifier.size
import com.revenuecat.purchases.ui.revenuecatui.components.properties.ColorStyle
import com.revenuecat.purchases.ui.revenuecatui.components.properties.ColorStyles
import com.revenuecat.purchases.ui.revenuecatui.components.properties.FontSpec
import com.revenuecat.purchases.ui.revenuecatui.components.properties.forCurrentTheme
import com.revenuecat.purchases.ui.revenuecatui.components.properties.toColorStyle
import com.revenuecat.purchases.ui.revenuecatui.components.style.TextComponentStyle
Expand Down Expand Up @@ -215,7 +215,7 @@ private fun TextComponentView_Preview_SerifFont() {
style = previewTextComponentStyle(
text = "Hello, world",
color = ColorStyles(light = ColorStyle.Solid(Color.Black)),
fontFamily = "serif",
fontSpec = FontSpec.Generic.Serif,
size = Size(width = Fit, height = Fit),
),
state = previewEmptyState(),
Expand All @@ -229,7 +229,7 @@ private fun TextComponentView_Preview_SansSerifFont() {
style = previewTextComponentStyle(
text = "Hello, world",
color = ColorStyles(light = ColorStyle.Solid(Color.Black)),
fontFamily = "sans-serif",
fontSpec = FontSpec.Generic.SansSerif,
size = Size(width = Fit, height = Fit),
),
state = previewEmptyState(),
Expand All @@ -243,7 +243,7 @@ private fun TextComponentView_Preview_MonospaceFont() {
style = previewTextComponentStyle(
text = "Hello, world",
color = ColorStyles(light = ColorStyle.Solid(Color.Black)),
fontFamily = "monospace",
fontSpec = FontSpec.Generic.Monospace,
size = Size(width = Fit, height = Fit),
),
state = previewEmptyState(),
Expand All @@ -257,7 +257,7 @@ private fun TextComponentView_Preview_CursiveFont() {
style = previewTextComponentStyle(
text = "Hello, world",
color = ColorStyles(light = ColorStyle.Solid(Color.Black)),
fontFamily = "cursive",
fontSpec = FontSpec.Generic.Cursive,
size = Size(width = Fit, height = Fit),
),
state = previewEmptyState(),
Expand Down Expand Up @@ -407,7 +407,7 @@ private fun previewTextComponentStyle(
color: ColorStyles,
fontSize: Int = 15,
fontWeight: FontWeight = FontWeight.REGULAR,
fontFamily: String? = null,
fontSpec: FontSpec? = null,
textAlign: HorizontalAlignment = HorizontalAlignment.CENTER,
horizontalAlignment: HorizontalAlignment = HorizontalAlignment.CENTER,
backgroundColor: ColorStyles? = null,
Expand All @@ -421,7 +421,7 @@ private fun previewTextComponentStyle(
color = color,
fontSize = fontSize,
fontWeight = weight,
fontFamily = fontFamily?.let { SystemFontFamily(it, weight) },
fontSpec = fontSpec,
textAlign = textAlign.toTextAlign(),
horizontalAlignment = horizontalAlignment.toAlignment(),
backgroundColor = backgroundColor,
Expand Down
Loading