Skip to content

Support custom h1 font modification #10930

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

Merged
merged 3 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.text.TextStyle
import com.google.accompanist.themeadapter.material.createMdcTheme
import com.stripe.android.uicore.LocalColors
import com.stripe.android.uicore.LocalShapes
Expand Down Expand Up @@ -75,7 +76,9 @@ internal fun AdoptForStripeTheme(
val stripeTypography: StripeTypography = StripeThemeDefaults.typography.copy(
body1FontFamily = hostingAppTypography.body1.fontFamily,
body2FontFamily = hostingAppTypography.body2.fontFamily,
h4FontFamily = hostingAppTypography.h4.fontFamily,
h4 = TextStyle(
fontFamily = hostingAppTypography.h4.fontFamily,
),
h5FontFamily = hostingAppTypography.h5.fontFamily,
h6FontFamily = hostingAppTypography.h6.fontFamily,
subtitle1FontFamily = hostingAppTypography.subtitle1.fontFamily,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import androidx.fragment.app.setFragmentResult
import com.godaddy.android.colorpicker.ClassicColorPicker
import com.godaddy.android.colorpicker.HsvColor
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.stripe.android.paymentelement.AppearanceAPIAdditionsPreview
import com.stripe.android.paymentsheet.PaymentSheet
import com.stripe.android.paymentsheet.example.R
import com.stripe.android.paymentsheet.example.playground.activity.AppearanceBottomSheetDialogFragment.Companion.EMBEDDED_KEY
Expand Down Expand Up @@ -501,6 +502,7 @@ private fun Insets(
}
}

@OptIn(AppearanceAPIAdditionsPreview::class)
@Composable
private fun Typography(
currentAppearance: PaymentSheet.Appearance,
Expand Down
63 changes: 61 additions & 2 deletions paymentsheet/api/paymentsheet.api
Original file line number Diff line number Diff line change
Expand Up @@ -2372,12 +2372,15 @@ public final class com/stripe/android/paymentsheet/PaymentSheet$Typography : and
public static final field CREATOR Landroid/os/Parcelable$Creator;
public static final field Companion Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Companion;
public fun <init> (FLjava/lang/Integer;)V
public fun <init> (FLjava/lang/Integer;Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;)V
public final fun component1 ()F
public final fun component2 ()Ljava/lang/Integer;
public final fun copy (FLjava/lang/Integer;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;
public static synthetic fun copy$default (Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;FLjava/lang/Integer;ILjava/lang/Object;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;
public final fun component3 ()Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;
public final fun copy (FLjava/lang/Integer;Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;
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;
public final fun describeContents ()I
public fun equals (Ljava/lang/Object;)Z
public final fun getCustom ()Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;
public final fun getFontResId ()Ljava/lang/Integer;
public final fun getSizeScaleFactor ()F
public fun hashCode ()I
Expand All @@ -2397,6 +2400,62 @@ public final class com/stripe/android/paymentsheet/PaymentSheet$Typography$Creat
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/paymentsheet/PaymentSheet$Typography$Custom : android/os/Parcelable {
public static final field $stable I
public static final field CREATOR Landroid/os/Parcelable$Creator;
public fun <init> ()V
public fun <init> (Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;)V
public synthetic fun <init> (Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;
public final fun copy (Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;
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;
public final fun describeContents ()I
public fun equals (Ljava/lang/Object;)Z
public final fun getH1 ()Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public final fun writeToParcel (Landroid/os/Parcel;I)V
}

public final class com/stripe/android/paymentsheet/PaymentSheet$Typography$Custom$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/paymentsheet/PaymentSheet$Typography$Font : android/os/Parcelable {
public static final field $stable I
public static final field CREATOR Landroid/os/Parcelable$Creator;
public fun <init> ()V
public fun <init> (Ljava/lang/Integer;Ljava/lang/Float;Ljava/lang/Integer;Ljava/lang/Float;)V
public synthetic fun <init> (Ljava/lang/Integer;Ljava/lang/Float;Ljava/lang/Integer;Ljava/lang/Float;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/Integer;
public final fun component2 ()Ljava/lang/Float;
public final fun component3 ()Ljava/lang/Integer;
public final fun component4 ()Ljava/lang/Float;
public final fun copy (Ljava/lang/Integer;Ljava/lang/Float;Ljava/lang/Integer;Ljava/lang/Float;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;
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;
public final fun describeContents ()I
public fun equals (Ljava/lang/Object;)Z
public final fun getFontFamily ()Ljava/lang/Integer;
public final fun getFontSizeSp ()Ljava/lang/Float;
public final fun getFontWeight ()Ljava/lang/Integer;
public final fun getLetterSpacingSp ()Ljava/lang/Float;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public final fun writeToParcel (Landroid/os/Parcel;I)V
}

public final class com/stripe/android/paymentsheet/PaymentSheet$Typography$Font$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/paymentsheet/PaymentSheetComposeKt {
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;
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;
Expand Down
2 changes: 1 addition & 1 deletion paymentsheet/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<ID>LongMethod:PaymentDetails.kt$@Preview(showBackground = true) @Composable private fun PaymentDetailsListItemPreview()</ID>
<ID>LongMethod:PaymentElementLoader.kt$DefaultPaymentElementLoader$private suspend fun createLinkConfiguration( configuration: CommonConfiguration, customer: CustomerInfo?, elementsSession: ElementsSession, initializationMode: PaymentElementLoader.InitializationMode ): LinkConfiguration?</ID>
<ID>LongMethod:PaymentMethodVerticalLayoutInteractor.kt$DefaultPaymentMethodVerticalLayoutInteractor.Companion$fun create( viewModel: BaseSheetViewModel, paymentMethodMetadata: PaymentMethodMetadata, customerStateHolder: CustomerStateHolder, bankFormInteractor: BankFormInteractor, ): PaymentMethodVerticalLayoutInteractor</ID>
<ID>LongMethod:PaymentSheetConfigurationKtx.kt$internal fun PaymentSheet.Appearance.parseAppearance()</ID>
<ID>LongMethod:PaymentSheetConfigurationKtx.kt$@OptIn(AppearanceAPIAdditionsPreview::class) internal fun PaymentSheet.Appearance.parseAppearance()</ID>
<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>
<ID>LongMethod:PaymentSheetViewModelTest.kt$PaymentSheetViewModelTest$@Test fun `Can complete payment after switching to another LPM from card selection with inline Link signup state`()</ID>
<ID>LongMethod:PlaceholderHelperTest.kt$PlaceholderHelperTest$@Test fun `Test correct placeholder is removed for placeholder spec`()</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,7 @@ class PaymentSheet internal constructor(
}

@Parcelize
data class Typography(
data class Typography @AppearanceAPIAdditionsPreview constructor(
/**
* The scale factor for all fonts in PaymentSheet, the default value is 1.0.
* When this value increases fonts will increase in size and decrease when this value is lowered.
Expand All @@ -1608,8 +1608,65 @@ class PaymentSheet internal constructor(
* The font used in text. This should be a resource ID value.
*/
@FontRes
val fontResId: Int?
val fontResId: Int?,

/**
* Custom font configuration for specific text styles
* Note: When set, these fonts override the default font calculations for their respective text styles
*/
val custom: Custom,
) : Parcelable {
@OptIn(AppearanceAPIAdditionsPreview::class)
constructor(
/**
* The scale factor for all fonts in PaymentSheet, the default value is 1.0.
* When this value increases fonts will increase in size and decrease when this value is lowered.
*/
sizeScaleFactor: Float,
/**
* The font used in text. This should be a resource ID value.
*/
@FontRes
fontResId: Int?
) : this(
sizeScaleFactor = sizeScaleFactor,
fontResId = fontResId,
custom = Custom(),
)

@AppearanceAPIAdditionsPreview
@Parcelize
data class Custom(
/**
* The font used for headlines (e.g., "Add your payment information")
*
* Note: If `null`, uses the calculated font based on `base` and `sizeScaleFactor`
*/
val h1: Font? = null,
) : Parcelable

@AppearanceAPIAdditionsPreview
@Parcelize
data class Font(
/**
* The font used in text. This should be a resource ID value.
*/
@FontRes
val fontFamily: Int? = null,
/**
* The font size used for the text. This should represent a sp value.
*/
val fontSizeSp: Float? = null,
/**
* The font weight used for the text.
*/
val fontWeight: Int? = null,
/**
* The letter spacing used for the text. This should represent a sp value.
*/
val letterSpacingSp: Float? = null,
) : Parcelable

companion object {
val default = Typography(
sizeScaleFactor = StripeThemeDefaults.typography.fontSizeMultiplier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ package com.stripe.android.paymentsheet
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.sp
import com.stripe.android.paymentelement.AppearanceAPIAdditionsPreview
import com.stripe.android.uicore.PrimaryButtonColors
import com.stripe.android.uicore.PrimaryButtonShape
import com.stripe.android.uicore.PrimaryButtonTypography
import com.stripe.android.uicore.StripeTheme
import com.stripe.android.uicore.StripeThemeDefaults

@OptIn(AppearanceAPIAdditionsPreview::class)
internal fun PaymentSheet.Appearance.parseAppearance() {
StripeTheme.colorsLightMutable = StripeThemeDefaults.colorsLight.copy(
component = Color(colorsLight.component),
Expand Down Expand Up @@ -51,7 +58,8 @@ internal fun PaymentSheet.Appearance.parseAppearance() {

StripeTheme.typographyMutable = StripeThemeDefaults.typography.copy(
fontFamily = typography.fontResId,
fontSizeMultiplier = typography.sizeScaleFactor
fontSizeMultiplier = typography.sizeScaleFactor,
h4 = typography.custom.h1?.toTextStyle(),
)

StripeTheme.primaryButtonStyle = StripeThemeDefaults.primaryButtonStyle.copy(
Expand Down Expand Up @@ -89,3 +97,13 @@ internal fun PaymentSheet.Appearance.parseAppearance() {
bottom = formInsetValues.bottomDp
)
}

@OptIn(AppearanceAPIAdditionsPreview::class)
private fun PaymentSheet.Typography.Font.toTextStyle(): TextStyle {
return TextStyle(
fontSize = fontSizeSp?.sp ?: TextUnit.Unspecified,
fontWeight = fontWeight?.let { FontWeight(it) },
fontFamily = fontFamily?.let { FontFamily(Font(it)) },
letterSpacing = letterSpacingSp?.sp ?: TextUnit.Unspecified,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal object CustomerSheetFixtures {
cornerRadiusDp = 0.0f,
borderStrokeWidthDp = 0.0f
),
typography = PaymentSheet.Typography.default.copy(
typography = PaymentSheet.Typography(
sizeScaleFactor = 1.1f,
fontResId = 0
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,9 @@ class BacsConfirmationDefinitionTest {
val launcher = FakeBacsMandateConfirmationLauncher()

val appearance = PaymentSheet.Appearance().copy(
typography = PaymentSheet.Typography.default.copy(
sizeScaleFactor = 2f
typography = PaymentSheet.Typography(
sizeScaleFactor = 2f,
fontResId = PaymentSheet.Typography.default.fontResId,
)
)
val bacsMandateData = BacsMandateData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ internal object PaymentSheetFixtures {
cornerRadiusDp = 0.0f,
borderStrokeWidthDp = 0.0f
),
typography = PaymentSheet.Typography.default.copy(
typography = PaymentSheet.Typography(
sizeScaleFactor = 1.1f,
fontResId = 0
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stripe.android.utils.screenshots

import android.graphics.Color
import com.stripe.android.paymentelement.AppearanceAPIAdditionsPreview
import com.stripe.android.paymentsheet.PaymentSheet
import com.stripe.android.paymentsheet.R
import com.stripe.android.paymentsheet.parseAppearance
Expand Down Expand Up @@ -28,6 +29,7 @@ enum class PaymentSheetAppearance(val appearance: PaymentSheet.Appearance) : Pap
),
),

@OptIn(AppearanceAPIAdditionsPreview::class)
CrazyAppearance(
appearance = PaymentSheet.Appearance(
colorsLight = PaymentSheet.Colors(
Expand Down Expand Up @@ -70,7 +72,19 @@ enum class PaymentSheetAppearance(val appearance: PaymentSheet.Appearance) : Pap
topDp = 20f,
endDp = 40f,
bottomDp = 60f
)
),
typography = PaymentSheet.Typography(
sizeScaleFactor = 1f,
fontResId = null,
custom = PaymentSheet.Typography.Custom(
h1 = PaymentSheet.Typography.Font(
fontFamily = R.font.cursive,
fontSizeSp = 24f,
fontWeight = 700,
letterSpacingSp = 0.15f,
)
)
),
),
);

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions stripe-ui-core/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ID>FunctionParameterNaming:IdentifierSpec.kt$IdentifierSpec.Companion$_value: String</ID>
<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>
<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>
<ID>LongMethod:StripeTheme.kt$@Composable @ReadOnlyComposable @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) fun StripeTypography.toComposeTypography(): Typography</ID>
<ID>MagicNumber:AnimationConstants.kt$34</ID>
<ID>MagicNumber:DateConfig.kt$DateConfig$4</ID>
<ID>MagicNumber:DateConfig.kt$DateConfig.Companion$100</ID>
Expand Down
Loading
Loading