Skip to content

Commit

Permalink
Remove font resource to save space and default to system default (#4861)
Browse files Browse the repository at this point in the history
* remove font resource to save space and default to system default

* changelog
  • Loading branch information
skyler-stripe authored Apr 12, 2022
1 parent 2d357d1 commit 44141cc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# CHANGELOG
## x.x.x - xxxx-xx-xx

### PaymentSheet
* [FIXED] [4861](https://github.com/stripe/stripe-android/pull/4861) Remove font resource to save space and default to system default

## 20.0.1 - 2022-04-11
This release includes several PaymentSheet bug fixes.

Expand Down
Binary file removed payments-ui-core/res/font/roboto.ttf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ data class PaymentsTypography(
val largeFontSize: TextUnit,
val xLargeFontSize: TextUnit,
@FontRes
val fontFamily: Int
val fontFamily: Int?
)

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
Expand Down Expand Up @@ -129,7 +129,7 @@ object PaymentsThemeDefaults {
mediumFontSize = 14.sp,
largeFontSize = 16.sp,
xLargeFontSize = 20.sp,
fontFamily = R.font.roboto
fontFamily = null // We default to the default system font.
)
}

Expand Down Expand Up @@ -192,18 +192,20 @@ fun PaymentsShapes.toComposeShapes(): PaymentsComposeShapes {
@ReadOnlyComposable
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
fun PaymentsTypography.toComposeTypography(): Typography {

val fontFamily = if (fontFamily != null) FontFamily(Font(fontFamily)) else FontFamily.Default
// h4 is our largest headline. It is used for the most important labels in our UI
// ex: "Select your payment method" in Payment Sheet.
val h4 = TextStyle.Default.copy(
fontFamily = FontFamily(Font(fontFamily)),
fontFamily = fontFamily,
fontSize = (xLargeFontSize * fontSizeMultiplier),
fontWeight = FontWeight(fontWeightBold),
)

// h5 is our medium headline label.
// ex: "Pay $50.99" in Payment Sheet's buy button.
val h5 = TextStyle.Default.copy(
fontFamily = FontFamily(Font(fontFamily)),
fontFamily = fontFamily,
fontSize = (largeFontSize * fontSizeMultiplier),
fontWeight = FontWeight(fontWeightMedium),
letterSpacing = (-0.32).sp
Expand All @@ -212,7 +214,7 @@ fun PaymentsTypography.toComposeTypography(): Typography {
// h6 is our smallest headline label.
// ex: Section labels in Payment Sheet
val h6 = TextStyle.Default.copy(
fontFamily = FontFamily(Font(fontFamily)),
fontFamily = fontFamily,
fontSize = (smallFontSize * fontSizeMultiplier),
fontWeight = FontWeight(fontWeightMedium),
letterSpacing = (-0.15).sp
Expand All @@ -221,15 +223,15 @@ fun PaymentsTypography.toComposeTypography(): Typography {
// body1 is our larger body text. Used for the bulk of our elements and forms.
// ex: the text used in Payment Sheet's text form elements.
val body1 = TextStyle.Default.copy(
fontFamily = FontFamily(Font(fontFamily)),
fontFamily = fontFamily,
fontSize = (mediumFontSize * fontSizeMultiplier),
fontWeight = FontWeight(fontWeightNormal),
)

// subtitle1 is our only subtitle size. Used for labeling fields.
// ex: the placeholder texts that appear when you type in Payment Sheet's forms.
val subtitle1 = TextStyle.Default.copy(
fontFamily = FontFamily(Font(fontFamily)),
fontFamily = fontFamily,
fontSize = (mediumFontSize * fontSizeMultiplier),
fontWeight = FontWeight(fontWeightNormal),
letterSpacing = (-0.15).sp
Expand All @@ -238,15 +240,15 @@ fun PaymentsTypography.toComposeTypography(): Typography {
// caption is used to label images in payment sheet.
// ex: the labels under our payment method selectors in Payment Sheet.
val caption = TextStyle.Default.copy(
fontFamily = FontFamily(Font(fontFamily)),
fontFamily = fontFamily,
fontSize = (xSmallFontSize * fontSizeMultiplier),
fontWeight = FontWeight(fontWeightMedium)
)

// body2 is our smaller body text. Used for less important fields that are not required to
// read. Ex: our mandate texts in Payment Sheet.
val body2 = TextStyle.Default.copy(
fontFamily = FontFamily(Font(fontFamily)),
fontFamily = fontFamily,
fontSize = (xxSmallFontSize * fontSizeMultiplier),
fontWeight = FontWeight(fontWeightNormal),
letterSpacing = (-0.15).sp
Expand Down Expand Up @@ -339,7 +341,7 @@ fun createTextSpanFromTextStyle(
fontSizeDp: Dp,
color: Color,
@FontRes
fontFamily: Int
fontFamily: Int?
): SpannableString {
val span = SpannableString(text ?: "")

Expand All @@ -348,10 +350,14 @@ fun createTextSpanFromTextStyle(

span.setSpan(ForegroundColorSpan(color.toArgb()), 0, span.length, 0)

ResourcesCompat.getFont(
context,
fontFamily
)?.let {
if (fontFamily != null) {
ResourcesCompat.getFont(
context,
fontFamily
)
} else {
Typeface.DEFAULT
}?.let {
span.setSpan(CustomTypefaceSpan(it), 0, span.length, 0)
}

Expand Down

0 comments on commit 44141cc

Please sign in to comment.