Skip to content

Commit 5c96095

Browse files
committed
Support custom h1 font modification
1 parent 7fd436f commit 5c96095

File tree

42 files changed

+308
-18
lines changed

Some content is hidden

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

42 files changed

+308
-18
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-example/src/main/java/com/stripe/android/paymentsheet/example/playground/activity/AppearanceBottomSheetDialogFragment.kt

Lines changed: 101 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,14 @@ import androidx.fragment.app.setFragmentResult
6767
import com.godaddy.android.colorpicker.ClassicColorPicker
6868
import com.godaddy.android.colorpicker.HsvColor
6969
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
70+
import com.stripe.android.paymentelement.ExtendedAppearancePreview
7071
import com.stripe.android.paymentsheet.PaymentSheet
7172
import com.stripe.android.paymentsheet.example.R
7273
import com.stripe.android.paymentsheet.example.playground.activity.AppearanceBottomSheetDialogFragment.Companion.EMBEDDED_KEY
7374
import com.stripe.android.paymentsheet.example.playground.settings.EmbeddedAppearance
7475
import com.stripe.android.paymentsheet.example.playground.settings.EmbeddedRow
76+
import com.stripe.android.uicore.StripeThemeDefaults
77+
import kotlin.math.roundToInt
7578

7679
private val BASE_FONT_SIZE = 20.sp
7780
private val BASE_PADDING = 8.dp
@@ -180,6 +183,12 @@ private fun AppearancePicker(
180183
updateAppearance = updateAppearance,
181184
)
182185
}
186+
CustomizationCard("Custom Typography") {
187+
CustomTypography(
188+
currentAppearance = currentAppearance,
189+
updateAppearance = updateAppearance,
190+
)
191+
}
183192
CustomizationCard("PrimaryButton") {
184193
PrimaryButton(
185194
currentAppearance = currentAppearance,
@@ -441,6 +450,7 @@ private fun Shapes(
441450
}
442451
}
443452

453+
@OptIn(ExtendedAppearancePreview::class)
444454
@Composable
445455
private fun Typography(
446456
currentAppearance: PaymentSheet.Appearance,
@@ -467,6 +477,89 @@ private fun Typography(
467477
}
468478
}
469479

480+
@OptIn(ExtendedAppearancePreview::class)
481+
@Composable
482+
private fun CustomTypography(
483+
currentAppearance: PaymentSheet.Appearance,
484+
updateAppearance: (PaymentSheet.Appearance) -> Unit,
485+
) {
486+
CustomFont(
487+
title = "h1",
488+
font = currentAppearance.typography.custom.h1,
489+
) {
490+
updateAppearance(
491+
currentAppearance.copy(
492+
typography = currentAppearance.typography.copy(
493+
custom = currentAppearance.typography.custom.copy(
494+
h1 = it
495+
),
496+
),
497+
)
498+
)
499+
}
500+
}
501+
502+
@OptIn(ExtendedAppearancePreview::class)
503+
@Composable
504+
private fun CustomFont(
505+
title: String,
506+
font: PaymentSheet.Typography.Font?,
507+
updateFont: (PaymentSheet.Typography.Font?) -> Unit
508+
) {
509+
AppearanceToggle(title, font != null) { show ->
510+
updateFont(
511+
PaymentSheet.Typography.Font(
512+
fontFamily = null,
513+
fontSizeSp = 10f,
514+
fontWeight = 400,
515+
letterSpacingSp = 0f,
516+
).takeIf { show }
517+
)
518+
}
519+
520+
font?.let { safeFont ->
521+
Divider()
522+
FontDropDown(safeFont.fontFamily) {
523+
updateFont(
524+
safeFont.copy(
525+
fontFamily = it,
526+
)
527+
)
528+
}
529+
Divider()
530+
IncrementDecrementItem(
531+
label = "fontSizeSp",
532+
value = safeFont.fontSizeSp ?: StripeThemeDefaults.typography.xLargeFontSize.value
533+
) {
534+
updateFont(
535+
safeFont.copy(
536+
fontSizeSp = it,
537+
)
538+
)
539+
}
540+
Divider()
541+
IncrementDecrementItem(
542+
label = "fontWeight",
543+
value = safeFont.fontWeight?.toFloat() ?: StripeThemeDefaults.typography.fontWeightBold.toFloat(),
544+
incrementValue = 100f
545+
) {
546+
updateFont(
547+
safeFont.copy(
548+
fontWeight = it.roundToInt(),
549+
)
550+
)
551+
}
552+
Divider()
553+
IncrementDecrementItem("letterSpacingSp", safeFont.letterSpacingSp ?: 0f, incrementValue = 0.01f) {
554+
updateFont(
555+
safeFont.copy(
556+
letterSpacingSp = it,
557+
)
558+
)
559+
}
560+
}
561+
}
562+
470563
@Composable
471564
private fun PrimaryButton(
472565
currentAppearance: PaymentSheet.Appearance,
@@ -887,7 +980,12 @@ private fun ColorIcon(innerColor: Color) {
887980
}
888981

889982
@Composable
890-
private fun IncrementDecrementItem(label: String, value: Float, onValueChange: (Float) -> Unit) {
983+
private fun IncrementDecrementItem(
984+
label: String,
985+
value: Float,
986+
incrementValue: Float = 1f,
987+
onValueChange: (Float) -> Unit,
988+
) {
891989
Row(
892990
modifier = Modifier
893991
.fillMaxWidth()
@@ -904,7 +1002,7 @@ private fun IncrementDecrementItem(label: String, value: Float, onValueChange: (
9041002
.height(32.dp)
9051003
.width(50.dp)
9061004
.clickable {
907-
val newValue = value - 1
1005+
val newValue = value - incrementValue
9081006
onValueChange(if (newValue < 0) 0.0f else newValue)
9091007
}
9101008
) {
@@ -920,7 +1018,7 @@ private fun IncrementDecrementItem(label: String, value: Float, onValueChange: (
9201018
.height(32.dp)
9211019
.width(50.dp)
9221020
.clickable {
923-
onValueChange(value + 1)
1021+
onValueChange(value + incrementValue)
9241022
}
9251023
) {
9261024
Icon(

paymentsheet/api/paymentsheet.api

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,12 +2343,15 @@ public final class com/stripe/android/paymentsheet/PaymentSheet$Typography : and
23432343
public static final field CREATOR Landroid/os/Parcelable$Creator;
23442344
public static final field Companion Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Companion;
23452345
public fun <init> (FLjava/lang/Integer;)V
2346+
public fun <init> (FLjava/lang/Integer;Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;)V
23462347
public final fun component1 ()F
23472348
public final fun component2 ()Ljava/lang/Integer;
2348-
public final fun copy (FLjava/lang/Integer;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;
2349-
public static synthetic fun copy$default (Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;FLjava/lang/Integer;ILjava/lang/Object;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;
2349+
public final fun component3 ()Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;
2350+
public final fun copy (FLjava/lang/Integer;Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography;
2351+
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;
23502352
public final fun describeContents ()I
23512353
public fun equals (Ljava/lang/Object;)Z
2354+
public final fun getCustom ()Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;
23522355
public final fun getFontResId ()Ljava/lang/Integer;
23532356
public final fun getSizeScaleFactor ()F
23542357
public fun hashCode ()I
@@ -2368,6 +2371,64 @@ public final class com/stripe/android/paymentsheet/PaymentSheet$Typography$Creat
23682371
public synthetic fun newArray (I)[Ljava/lang/Object;
23692372
}
23702373

2374+
public final class com/stripe/android/paymentsheet/PaymentSheet$Typography$Custom : android/os/Parcelable {
2375+
public static final field $stable I
2376+
public static final field CREATOR Landroid/os/Parcelable$Creator;
2377+
public fun <init> ()V
2378+
public fun <init> (Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;)V
2379+
public synthetic fun <init> (Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
2380+
public final fun component1 ()Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;
2381+
public final fun copy (Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;
2382+
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;
2383+
public final fun describeContents ()I
2384+
public fun equals (Ljava/lang/Object;)Z
2385+
public final fun getH1 ()Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;
2386+
public fun hashCode ()I
2387+
public fun toString ()Ljava/lang/String;
2388+
public final fun writeToParcel (Landroid/os/Parcel;I)V
2389+
}
2390+
2391+
public final class com/stripe/android/paymentsheet/PaymentSheet$Typography$Custom$Creator : android/os/Parcelable$Creator {
2392+
public fun <init> ()V
2393+
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;
2394+
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
2395+
public final fun newArray (I)[Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Custom;
2396+
public synthetic fun newArray (I)[Ljava/lang/Object;
2397+
}
2398+
2399+
public final class com/stripe/android/paymentsheet/PaymentSheet$Typography$Font : android/os/Parcelable {
2400+
public static final field $stable I
2401+
public static final field CREATOR Landroid/os/Parcelable$Creator;
2402+
public fun <init> ()V
2403+
public fun <init> (Landroid/content/Context;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;)V
2404+
public synthetic fun <init> (Landroid/content/Context;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;Ljava/lang/Integer;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
2405+
public fun <init> (Ljava/lang/Integer;Ljava/lang/Float;Ljava/lang/Integer;Ljava/lang/Float;)V
2406+
public synthetic fun <init> (Ljava/lang/Integer;Ljava/lang/Float;Ljava/lang/Integer;Ljava/lang/Float;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
2407+
public final fun component1 ()Ljava/lang/Integer;
2408+
public final fun component2 ()Ljava/lang/Float;
2409+
public final fun component3 ()Ljava/lang/Integer;
2410+
public final fun component4 ()Ljava/lang/Float;
2411+
public final fun copy (Ljava/lang/Integer;Ljava/lang/Float;Ljava/lang/Integer;Ljava/lang/Float;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;
2412+
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;
2413+
public final fun describeContents ()I
2414+
public fun equals (Ljava/lang/Object;)Z
2415+
public final fun getFontFamily ()Ljava/lang/Integer;
2416+
public final fun getFontSizeSp ()Ljava/lang/Float;
2417+
public final fun getFontWeight ()Ljava/lang/Integer;
2418+
public final fun getLetterSpacingSp ()Ljava/lang/Float;
2419+
public fun hashCode ()I
2420+
public fun toString ()Ljava/lang/String;
2421+
public final fun writeToParcel (Landroid/os/Parcel;I)V
2422+
}
2423+
2424+
public final class com/stripe/android/paymentsheet/PaymentSheet$Typography$Font$Creator : android/os/Parcelable$Creator {
2425+
public fun <init> ()V
2426+
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;
2427+
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
2428+
public final fun newArray (I)[Lcom/stripe/android/paymentsheet/PaymentSheet$Typography$Font;
2429+
public synthetic fun newArray (I)[Ljava/lang/Object;
2430+
}
2431+
23712432
public final class com/stripe/android/paymentsheet/PaymentSheetComposeKt {
23722433
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;
23732434
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
@@ -1604,7 +1604,7 @@ class PaymentSheet internal constructor(
16041604
}
16051605

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

0 commit comments

Comments
 (0)