Skip to content

Commit d200ee2

Browse files
committed
Support custom h1 font modification
1 parent 5472c2c commit d200ee2

File tree

41 files changed

+208
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+208
-16
lines changed

identity/src/main/java/com/stripe/android/identity/ui/IdentityTheme.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import androidx.compose.runtime.remember
1414
import androidx.compose.ui.platform.LocalContext
1515
import androidx.compose.ui.platform.LocalInspectionMode
1616
import androidx.compose.ui.platform.LocalLayoutDirection
17+
import androidx.compose.ui.text.TextStyle
1718
import com.google.accompanist.themeadapter.material.createMdcTheme
1819
import com.stripe.android.uicore.LocalColors
1920
import com.stripe.android.uicore.LocalShapes
@@ -75,7 +76,9 @@ internal fun AdoptForStripeTheme(
7576
val stripeTypography: StripeTypography = StripeThemeDefaults.typography.copy(
7677
body1FontFamily = hostingAppTypography.body1.fontFamily,
7778
body2FontFamily = hostingAppTypography.body2.fontFamily,
78-
h4FontFamily = hostingAppTypography.h4.fontFamily,
79+
h4 = TextStyle(
80+
fontFamily = hostingAppTypography.h4.fontFamily,
81+
),
7982
h5FontFamily = hostingAppTypography.h5.fontFamily,
8083
h6FontFamily = hostingAppTypography.h6.fontFamily,
8184
subtitle1FontFamily = hostingAppTypography.subtitle1.fontFamily,

paymentsheet/api/paymentsheet.api

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,12 +2373,15 @@ public final class com/stripe/android/paymentsheet/PaymentSheet$Typography : and
23732373
public static final field CREATOR Landroid/os/Parcelable$Creator;
23742374
public static final field Companion Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Companion;
23752375
public fun <init> (FLjava/lang/Integer;)V
2376+
public fun <init> (FLjava/lang/Integer;Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;)V
23762377
public final fun component1 ()F
23772378
public final fun component2 ()Ljava/lang/Integer;
2378-
public final fun copy (FLjava/lang/Integer;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;
2379-
public static synthetic fun copy$default (Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;FLjava/lang/Integer;ILjava/lang/Object;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;
2379+
public final fun component3 ()Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;
2380+
public final fun copy (FLjava/lang/Integer;Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;
2381+
public static synthetic fun copy$default (Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;FLjava/lang/Integer;Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;ILjava/lang/Object;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;
23802382
public final fun describeContents ()I
23812383
public fun equals (Ljava/lang/Object;)Z
2384+
public final fun getCustom ()Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;
23822385
public final fun getFontResId ()Ljava/lang/Integer;
23832386
public final fun getSizeScaleFactor ()F
23842387
public fun hashCode ()I
@@ -2398,6 +2401,64 @@ public final class com/stripe/android/paymentsheet/PaymentSheet$Typography$Creat
23982401
public synthetic fun newArray (I)[Ljava/lang/Object;
23992402
}
24002403

2404+
public final class com/stripe/android/paymentsheet/PaymentSheet$Typography$Custom : android/os/Parcelable {
2405+
public static final field $stable I
2406+
public static final field CREATOR Landroid/os/Parcelable$Creator;
2407+
public fun <init> ()V
2408+
public fun <init> (Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;)V
2409+
public synthetic fun <init> (Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
2410+
public final fun component1 ()Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;
2411+
public final fun copy (Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;
2412+
public static synthetic fun copy$default (Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;ILjava/lang/Object;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;
2413+
public final fun describeContents ()I
2414+
public fun equals (Ljava/lang/Object;)Z
2415+
public final fun getH1 ()Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;
2416+
public fun hashCode ()I
2417+
public fun toString ()Ljava/lang/String;
2418+
public final fun writeToParcel (Landroid/os/Parcel;I)V
2419+
}
2420+
2421+
public final class com/stripe/android/paymentsheet/PaymentSheet$Typography$Custom$Creator : android/os/Parcelable$Creator {
2422+
public fun <init> ()V
2423+
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;
2424+
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
2425+
public final fun newArray (I)[Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;
2426+
public synthetic fun newArray (I)[Ljava/lang/Object;
2427+
}
2428+
2429+
public final class com/stripe/android/paymentsheet/PaymentSheet$Typography$Font : android/os/Parcelable {
2430+
public static final field $stable I
2431+
public static final field CREATOR Landroid/os/Parcelable$Creator;
2432+
public fun <init> ()V
2433+
public fun <init> (Landroid/content/Context;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V
2434+
public synthetic fun <init> (Landroid/content/Context;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
2435+
public fun <init> (Ljava/lang/Integer;Ljava/lang/Float;Ljava/lang/Integer;Ljava/lang/Float;)V
2436+
public synthetic fun <init> (Ljava/lang/Integer;Ljava/lang/Float;Ljava/lang/Integer;Ljava/lang/Float;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
2437+
public final fun component1 ()Ljava/lang/Integer;
2438+
public final fun component2 ()Ljava/lang/Float;
2439+
public final fun component3 ()Ljava/lang/Integer;
2440+
public final fun component4 ()Ljava/lang/Float;
2441+
public final fun copy (Ljava/lang/Integer;Ljava/lang/Float;Ljava/lang/Integer;Ljava/lang/Float;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;
2442+
public static synthetic fun copy$default (Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;Ljava/lang/Integer;Ljava/lang/Float;Ljava/lang/Integer;Ljava/lang/Float;ILjava/lang/Object;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;
2443+
public final fun describeContents ()I
2444+
public fun equals (Ljava/lang/Object;)Z
2445+
public final fun getFontFamily ()Ljava/lang/Integer;
2446+
public final fun getFontSizeSp ()Ljava/lang/Float;
2447+
public final fun getFontWeight ()Ljava/lang/Integer;
2448+
public final fun getLetterSpacingSp ()Ljava/lang/Float;
2449+
public fun hashCode ()I
2450+
public fun toString ()Ljava/lang/String;
2451+
public final fun writeToParcel (Landroid/os/Parcel;I)V
2452+
}
2453+
2454+
public final class com/stripe/android/paymentsheet/PaymentSheet$Typography$Font$Creator : android/os/Parcelable$Creator {
2455+
public fun <init> ()V
2456+
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;
2457+
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
2458+
public final fun newArray (I)[Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;
2459+
public synthetic fun newArray (I)[Ljava/lang/Object;
2460+
}
2461+
24012462
public final class com/stripe/android/paymentsheet/PaymentSheetComposeKt {
24022463
public static final fun rememberPaymentSheet (Lcom/stripe/android/paymentsheet/CreateIntentCallback;Lcom/stripe/android/paymentsheet/ExternalPaymentMethodConfirmHandler;Lcom/stripe/android/paymentsheet/PaymentSheetResultCallback;Landroidx/compose/runtime/Composer;II)Lcom/stripe/android/paymentsheet/PaymentSheet;
24032464
public static final fun rememberPaymentSheet (Lcom/stripe/android/paymentsheet/CreateIntentCallback;Lcom/stripe/android/paymentsheet/PaymentSheetResultCallback;Landroidx/compose/runtime/Composer;I)Lcom/stripe/android/paymentsheet/PaymentSheet;

paymentsheet/detekt-baseline.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<ID>LongMethod:PaymentDetails.kt$@Preview(showBackground = true) @Composable private fun PaymentDetailsListItemPreview()</ID>
4545
<ID>LongMethod:PaymentElementLoader.kt$DefaultPaymentElementLoader$private suspend fun createLinkConfiguration( configuration: CommonConfiguration, customer: CustomerInfo?, elementsSession: ElementsSession, initializationMode: PaymentElementLoader.InitializationMode ): LinkConfiguration?</ID>
4646
<ID>LongMethod:PaymentMethodVerticalLayoutInteractor.kt$DefaultPaymentMethodVerticalLayoutInteractor.Companion$fun create( viewModel: BaseSheetViewModel, paymentMethodMetadata: PaymentMethodMetadata, customerStateHolder: CustomerStateHolder, bankFormInteractor: BankFormInteractor, ): PaymentMethodVerticalLayoutInteractor</ID>
47-
<ID>LongMethod:PaymentSheetConfigurationKtx.kt$internal fun PaymentSheet.Appearance.parseAppearance()</ID>
47+
<ID>LongMethod:PaymentSheetConfigurationKtx.kt$@OptIn(ExtendedAppearancePreview::class) internal fun PaymentSheet.Appearance.parseAppearance()</ID>
4848
<ID>LongMethod:PaymentSheetScreen.kt$@Composable private fun PaymentSheetContent( viewModel: BaseSheetViewModel, headerText: ResolvableString?, walletsState: WalletsState?, walletsProcessingState: WalletsProcessingState?, error: ResolvableString?, currentScreen: PaymentSheetScreen, mandateText: MandateText?, modifier: Modifier )</ID>
4949
<ID>LongMethod:PaymentSheetViewModelTest.kt$PaymentSheetViewModelTest$@Test fun `Can complete payment after switching to another LPM from card selection with inline Link signup state`()</ID>
5050
<ID>LongMethod:PlaceholderHelperTest.kt$PlaceholderHelperTest$@Test fun `Test correct placeholder is removed for placeholder spec`()</ID>

paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheet.kt

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,7 @@ class PaymentSheet internal constructor(
16091609
}
16101610

16111611
@Parcelize
1612-
data class Typography(
1612+
data class Typography @ExtendedAppearancePreview constructor(
16131613
/**
16141614
* The scale factor for all fonts in PaymentSheet, the default value is 1.0.
16151615
* When this value increases fonts will increase in size and decrease when this value is lowered.
@@ -1620,8 +1620,90 @@ class PaymentSheet internal constructor(
16201620
* The font used in text. This should be a resource ID value.
16211621
*/
16221622
@FontRes
1623-
val fontResId: Int?
1623+
val fontResId: Int?,
1624+
1625+
/**
1626+
* Custom font configuration for specific text styles
1627+
* Note: When set, these fonts override the default font calculations for their respective text styles
1628+
*/
1629+
val custom: Custom,
16241630
) : Parcelable {
1631+
@OptIn(ExtendedAppearancePreview::class)
1632+
constructor(
1633+
/**
1634+
* The scale factor for all fonts in PaymentSheet, the default value is 1.0.
1635+
* When this value increases fonts will increase in size and decrease when this value is lowered.
1636+
*/
1637+
sizeScaleFactor: Float,
1638+
/**
1639+
* The font used in text. This should be a resource ID value.
1640+
*/
1641+
@FontRes
1642+
fontResId: Int?
1643+
) : this(
1644+
sizeScaleFactor = sizeScaleFactor,
1645+
fontResId = fontResId,
1646+
custom = Custom(),
1647+
)
1648+
1649+
@ExtendedAppearancePreview
1650+
@Parcelize
1651+
data class Custom(
1652+
/**
1653+
* The font used for headlines (e.g., "Add your payment information")
1654+
*
1655+
* Note: If `null`, uses the calculated font based on `base` and `sizeScaleFactor`
1656+
*/
1657+
val h1: Font? = null,
1658+
) : Parcelable
1659+
1660+
@ExtendedAppearancePreview
1661+
@Parcelize
1662+
data class Font(
1663+
/**
1664+
* The font used in text. This should be a resource ID value.
1665+
*/
1666+
@FontRes
1667+
val fontFamily: Int? = null,
1668+
/**
1669+
* The font size used for the text. This should represent a sp value.
1670+
*/
1671+
val fontSizeSp: Float? = null,
1672+
/**
1673+
* The font weight used for the text.
1674+
*/
1675+
val fontWeight: Int? = null,
1676+
/**
1677+
* The letter spacing used for the text. This should represent a sp value.
1678+
*/
1679+
val letterSpacingSp: Float? = null,
1680+
) : Parcelable {
1681+
constructor(
1682+
context: Context,
1683+
/**
1684+
* The font used in text. This should be a resource ID value.
1685+
*/
1686+
@FontRes fontFamily: Int?,
1687+
/**
1688+
* The font size resource used for the text. This should represent a sp value.
1689+
*/
1690+
@DimenRes fontSizeRes: Int? = null,
1691+
/**
1692+
* The font weight used for the text.
1693+
*/
1694+
fontWeight: Int? = null,
1695+
/**
1696+
* The letter spacing resource used for the text. This should represent a sp value.
1697+
*/
1698+
@DimenRes letterSpacingRes: Int? = null,
1699+
) : this(
1700+
fontFamily = fontFamily,
1701+
fontSizeSp = fontSizeRes?.let { context.getRawValueFromDimenResource(it) },
1702+
fontWeight = fontWeight,
1703+
letterSpacingSp = letterSpacingRes?.let { context.getRawValueFromDimenResource(it) },
1704+
)
1705+
}
1706+
16251707
companion object {
16261708
val default = Typography(
16271709
sizeScaleFactor = StripeThemeDefaults.typography.fontSizeMultiplier,

paymentsheet/src/main/java/com/stripe/android/paymentsheet/PaymentSheetConfigurationKtx.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@ package com.stripe.android.paymentsheet
33
import androidx.compose.material.darkColors
44
import androidx.compose.material.lightColors
55
import androidx.compose.ui.graphics.Color
6+
import androidx.compose.ui.text.TextStyle
7+
import androidx.compose.ui.text.font.Font
8+
import androidx.compose.ui.text.font.FontFamily
9+
import androidx.compose.ui.text.font.FontWeight
10+
import androidx.compose.ui.unit.TextUnit
611
import androidx.compose.ui.unit.sp
12+
import com.stripe.android.paymentelement.ExtendedAppearancePreview
713
import com.stripe.android.uicore.PrimaryButtonColors
814
import com.stripe.android.uicore.PrimaryButtonShape
915
import com.stripe.android.uicore.PrimaryButtonTypography
1016
import com.stripe.android.uicore.StripeTheme
1117
import com.stripe.android.uicore.StripeThemeDefaults
1218

19+
@OptIn(ExtendedAppearancePreview::class)
1320
internal fun PaymentSheet.Appearance.parseAppearance() {
1421
StripeTheme.colorsLightMutable = StripeThemeDefaults.colorsLight.copy(
1522
component = Color(colorsLight.component),
@@ -51,7 +58,8 @@ internal fun PaymentSheet.Appearance.parseAppearance() {
5158

5259
StripeTheme.typographyMutable = StripeThemeDefaults.typography.copy(
5360
fontFamily = typography.fontResId,
54-
fontSizeMultiplier = typography.sizeScaleFactor
61+
fontSizeMultiplier = typography.sizeScaleFactor,
62+
h4 = typography.custom.h1?.toTextStyle(),
5563
)
5664

5765
StripeTheme.primaryButtonStyle = StripeThemeDefaults.primaryButtonStyle.copy(
@@ -89,3 +97,13 @@ internal fun PaymentSheet.Appearance.parseAppearance() {
8997
bottom = formInsetValues.bottomDp
9098
)
9199
}
100+
101+
@OptIn(ExtendedAppearancePreview::class)
102+
private fun PaymentSheet.Typography.Font.toTextStyle(): TextStyle {
103+
return TextStyle(
104+
fontSize = fontSizeSp?.sp ?: TextUnit.Unspecified,
105+
fontWeight = fontWeight?.let { FontWeight(it) },
106+
fontFamily = fontFamily?.let { FontFamily(Font(it)) },
107+
letterSpacing = letterSpacingSp?.sp ?: TextUnit.Unspecified,
108+
)
109+
}

paymentsheet/src/test/java/com/stripe/android/customersheet/CustomerSheetFixtures.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal object CustomerSheetFixtures {
2727
cornerRadiusDp = 0.0f,
2828
borderStrokeWidthDp = 0.0f
2929
),
30-
typography = PaymentSheet.Typography.default.copy(
30+
typography = PaymentSheet.Typography(
3131
sizeScaleFactor = 1.1f,
3232
fontResId = 0
3333
),

paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/bacs/BacsConfirmationDefinitionTest.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,9 @@ class BacsConfirmationDefinitionTest {
233233
val launcher = FakeBacsMandateConfirmationLauncher()
234234

235235
val appearance = PaymentSheet.Appearance().copy(
236-
typography = PaymentSheet.Typography.default.copy(
237-
sizeScaleFactor = 2f
236+
typography = PaymentSheet.Typography(
237+
sizeScaleFactor = 2f,
238+
fontResId = PaymentSheet.Typography.default.fontResId,
238239
)
239240
)
240241
val bacsMandateData = BacsMandateData(

paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetFixtures.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ internal object PaymentSheetFixtures {
6868
cornerRadiusDp = 0.0f,
6969
borderStrokeWidthDp = 0.0f
7070
),
71-
typography = PaymentSheet.Typography.default.copy(
71+
typography = PaymentSheet.Typography(
7272
sizeScaleFactor = 1.1f,
7373
fontResId = 0
7474
),

paymentsheet/src/test/java/com/stripe/android/utils/screenshots/PaymentSheetAppearance.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.stripe.android.utils.screenshots
22

33
import android.graphics.Color
4+
import com.stripe.android.paymentelement.ExtendedAppearancePreview
45
import com.stripe.android.paymentsheet.PaymentSheet
56
import com.stripe.android.paymentsheet.R
67
import com.stripe.android.paymentsheet.parseAppearance
@@ -28,6 +29,7 @@ enum class PaymentSheetAppearance(val appearance: PaymentSheet.Appearance) : Pap
2829
),
2930
),
3031

32+
@OptIn(ExtendedAppearancePreview::class)
3133
CrazyAppearance(
3234
appearance = PaymentSheet.Appearance(
3335
colorsLight = PaymentSheet.Colors(
@@ -70,7 +72,19 @@ enum class PaymentSheetAppearance(val appearance: PaymentSheet.Appearance) : Pap
7072
topDp = 20f,
7173
endDp = 40f,
7274
bottomDp = 60f
73-
)
75+
),
76+
typography = PaymentSheet.Typography(
77+
sizeScaleFactor = 1f,
78+
fontResId = null,
79+
custom = PaymentSheet.Typography.Custom(
80+
h1 = PaymentSheet.Typography.Font(
81+
fontFamily = R.font.cursive,
82+
fontSizeSp = 24f,
83+
fontWeight = 700,
84+
letterSpacingSp = 0.15f,
85+
)
86+
)
87+
),
7488
),
7589
);
7690

stripe-ui-core/detekt-baseline.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<ID>FunctionParameterNaming:IdentifierSpec.kt$IdentifierSpec.Companion$_value: String</ID>
1515
<ID>LongMethod:Html.kt$@Composable @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) fun annotatedStringResource( text: String, imageGetter: Map&lt;String, EmbeddableImage> = emptyMap(), urlSpanStyle: SpanStyle = SpanStyle(textDecoration = TextDecoration.Underline) ): AnnotatedString</ID>
1616
<ID>LongMethod:OTPElementUI.kt$@OptIn(ExperimentalComposeUiApi::class) @Composable @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) fun OTPElementUI( enabled: Boolean, element: OTPElement, modifier: Modifier = Modifier, boxShape: Shape = MaterialTheme.shapes.medium, boxTextStyle: TextStyle = OTPElementUI.defaultTextStyle(), boxSpacing: Dp = 8.dp, middleSpacing: Dp = 20.dp, otpInputPlaceholder: String = "●", colors: OTPElementColors = OTPElementColors( selectedBorder = MaterialTheme.colors.primary, unselectedBorder = MaterialTheme.stripeColors.componentBorder, placeholder = MaterialTheme.stripeColors.placeholderText, background = Color.Transparent ), focusRequester: FocusRequester = remember { FocusRequester() } )</ID>
17+
<ID>LongMethod:StripeTheme.kt$@Composable @ReadOnlyComposable @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) fun StripeTypography.toComposeTypography(): Typography</ID>
1718
<ID>MagicNumber:AnimationConstants.kt$34</ID>
1819
<ID>MagicNumber:DateConfig.kt$DateConfig$4</ID>
1920
<ID>MagicNumber:DateConfig.kt$DateConfig.Companion$100</ID>

0 commit comments

Comments
 (0)