Skip to content

Commit

Permalink
add nullables to make construction easier
Browse files Browse the repository at this point in the history
  • Loading branch information
skyler-stripe committed Apr 20, 2022
1 parent 37a4072 commit 9252188
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 53 deletions.
42 changes: 30 additions & 12 deletions paymentsheet/api/paymentsheet.api
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ public final class com/stripe/android/paymentsheet/PaymentSheet$GooglePayConfigu
public final class com/stripe/android/paymentsheet/PaymentSheet$PrimaryButton : 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$PrimaryButtonColors;Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonColors;Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonShape;Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonTypography;)V
public synthetic fun <init> (Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonColors;Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonColors;Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonShape;Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonTypography;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonColors;
public final fun component2 ()Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonColors;
public final fun component3 ()Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonShape;
Expand All @@ -347,42 +349,54 @@ public final class com/stripe/android/paymentsheet/PaymentSheet$PrimaryButton :
public final class com/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonColors : android/os/Parcelable {
public static final field $stable I
public static final field CREATOR Landroid/os/Parcelable$Creator;
public fun <init> (III)V
public final fun component1 ()I
public static final field Companion Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonColors$Companion;
public fun <init> (Ljava/lang/Integer;II)V
public final fun component1 ()Ljava/lang/Integer;
public final fun component2 ()I
public final fun component3 ()I
public final fun copy (III)Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonColors;
public static synthetic fun copy$default (Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonColors;IIIILjava/lang/Object;)Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonColors;
public final fun copy (Ljava/lang/Integer;II)Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonColors;
public static synthetic fun copy$default (Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonColors;Ljava/lang/Integer;IIILjava/lang/Object;)Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonColors;
public fun describeContents ()I
public fun equals (Ljava/lang/Object;)Z
public final fun getBackground ()I
public final fun getBackground ()Ljava/lang/Integer;
public final fun getBorder ()I
public final fun getOnBackground ()I
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public fun writeToParcel (Landroid/os/Parcel;I)V
}

public final class com/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonColors$Companion {
public final fun getDefaultDark ()Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonColors;
public final fun getDefaultLight ()Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonColors;
}

public final class com/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonShape : android/os/Parcelable {
public static final field $stable I
public static final field CREATOR Landroid/os/Parcelable$Creator;
public fun <init> (FF)V
public final fun component1 ()F
public final fun component2 ()F
public final fun copy (FF)Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonShape;
public static synthetic fun copy$default (Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonShape;FFILjava/lang/Object;)Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonShape;
public static final field Companion Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonShape$Companion;
public fun <init> (Ljava/lang/Float;Ljava/lang/Float;)V
public final fun component1 ()Ljava/lang/Float;
public final fun component2 ()Ljava/lang/Float;
public final fun copy (Ljava/lang/Float;Ljava/lang/Float;)Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonShape;
public static synthetic fun copy$default (Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonShape;Ljava/lang/Float;Ljava/lang/Float;ILjava/lang/Object;)Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonShape;
public fun describeContents ()I
public fun equals (Ljava/lang/Object;)Z
public final fun getBorderStrokeWidthDp ()F
public final fun getCornerRadiusDp ()F
public final fun getBorderStrokeWidthDp ()Ljava/lang/Float;
public final fun getCornerRadiusDp ()Ljava/lang/Float;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public fun writeToParcel (Landroid/os/Parcel;I)V
}

public final class com/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonShape$Companion {
public final fun getDefault ()Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonShape;
}

public final class com/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonTypography : android/os/Parcelable {
public static final field $stable I
public static final field CREATOR Landroid/os/Parcelable$Creator;
public static final field Companion Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonTypography$Companion;
public fun <init> (Ljava/lang/Integer;)V
public final fun component1 ()Ljava/lang/Integer;
public final fun copy (Ljava/lang/Integer;)Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonTypography;
Expand All @@ -395,6 +409,10 @@ public final class com/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonTyp
public fun writeToParcel (Landroid/os/Parcel;I)V
}

public final class com/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonTypography$Companion {
public final fun getDefault ()Lcom/stripe/android/paymentsheet/PaymentSheet$PrimaryButtonTypography;
}

public final class com/stripe/android/paymentsheet/PaymentSheet$Shapes : android/os/Parcelable {
public static final field $stable I
public static final field CREATOR Landroid/os/Parcelable$Creator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,32 +194,7 @@ class PaymentSheet internal constructor(
val typography: Typography = Typography.default,

// Describes appearance of the primary button (e.g., the "Pay" button) in PaymentSheet
val primaryButton: PrimaryButton = PrimaryButton(
colorsLight = PrimaryButtonColors(
background =
colorsLight.primary,
onBackground =
PaymentsThemeDefaults.primaryButtonStyle.colorsLight.onBackground.toArgb(),
border =
PaymentsThemeDefaults.primaryButtonStyle.colorsLight.border.toArgb()
),
colorsDark = PrimaryButtonColors(
background =
colorsDark.primary,
onBackground =
PaymentsThemeDefaults.primaryButtonStyle.colorsDark.onBackground.toArgb(),
border =
PaymentsThemeDefaults.primaryButtonStyle.colorsDark.border.toArgb()
),
shape = PrimaryButtonShape(
cornerRadiusDp = shapes.cornerRadiusDp,
borderStrokeWidthDp = shapes.borderStrokeWidthDp
),
typography = PrimaryButtonTypography(
fontResId = typography.fontResId
)
)

val primaryButton: PrimaryButton = PrimaryButton()
) : Parcelable {
fun getColors(isDark: Boolean): Colors {
return if (isDark) colorsDark else colorsLight
Expand All @@ -236,7 +211,7 @@ class PaymentSheet internal constructor(
fun colorsDark(colors: Colors) = apply { this.colorsDark = colors }
fun shapes(shapes: Shapes) = apply { this.shapes = shapes }
fun typography(typography: Typography) = apply { this.typography = typography }
fun primaryButtonModifier(primaryButton: PrimaryButton) =
fun primaryButton(primaryButton: PrimaryButton) =
apply { this.primaryButton = primaryButton }
}
}
Expand Down Expand Up @@ -367,42 +342,60 @@ class PaymentSheet internal constructor(
@Parcelize
data class PrimaryButton(
// Describes the colors used while the system is in light mode
val colorsLight: PrimaryButtonColors,
val colorsLight: PrimaryButtonColors = PrimaryButtonColors.defaultLight,
// Describes the colors used while the system is in dark mode
val colorsDark: PrimaryButtonColors,
val colorsDark: PrimaryButtonColors = PrimaryButtonColors.defaultDark,
// Describes the shape of the primary button.
val shape: PrimaryButtonShape,
val shape: PrimaryButtonShape = PrimaryButtonShape(),
// Describes the typography of the primary button.
val typography: PrimaryButtonTypography
val typography: PrimaryButtonTypography = PrimaryButtonTypography()
) : Parcelable

@Parcelize
data class PrimaryButtonColors(
// The background color of the primary button
// Note: if 'null' the Appearance.Colors.primary is used.
@ColorInt
val background: Int,
val background: Int?,
// The color appearing on the primary button
@ColorInt
val onBackground: Int,
// The border color of the primary button
@ColorInt
val border: Int,
) : Parcelable
) : Parcelable {
companion object {
val defaultLight = PrimaryButtonColors(
background = null,
onBackground =
PaymentsThemeDefaults.primaryButtonStyle.colorsLight.onBackground.toArgb(),
border = PaymentsThemeDefaults.primaryButtonStyle.colorsLight.border.toArgb(),
)
val defaultDark = PrimaryButtonColors(
background = null,
onBackground =
PaymentsThemeDefaults.primaryButtonStyle.colorsDark.onBackground.toArgb(),
border = PaymentsThemeDefaults.primaryButtonStyle.colorsDark.border.toArgb(),
)
}
}

@Parcelize
data class PrimaryButtonShape(
// The corner radius of the primary button
val cornerRadiusDp: Float,
// Note: if 'null' the Appearance.Shapes.cornerRadiusDp is used.
val cornerRadiusDp: Float? = null,
// The border width of the primary button
val borderStrokeWidthDp: Float
// Note: if 'null' the Appearance.Shapes.borderStrokeWidthDp is used.
val borderStrokeWidthDp: Float? = null
) : Parcelable

@Parcelize
data class PrimaryButtonTypography(
// The font used in the primary button.
// Note: if 'null' the Appearance.Typography.fontResId is used.
@FontRes
val fontResId: Int?
val fontResId: Int? = null
) : Parcelable

@Parcelize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,22 @@ internal fun PaymentSheet.Appearance.parseAppearance() {

PaymentsTheme.primaryButtonStyle = PaymentsThemeDefaults.primaryButtonStyle.copy(
colorsLight = PrimaryButtonColors(
background = Color(primaryButton.colorsLight.background),
background = Color(primaryButton.colorsLight.background ?: colorsLight.primary),
onBackground = Color(primaryButton.colorsLight.onBackground),
border = Color(primaryButton.colorsLight.border),
),
colorsDark = PrimaryButtonColors(
background = Color(primaryButton.colorsDark.background),
background = Color(primaryButton.colorsDark.background ?: colorsDark.primary),
onBackground = Color(primaryButton.colorsDark.onBackground),
border = Color(primaryButton.colorsDark.border),
),
shape = PrimaryButtonShape(
cornerRadius = primaryButton.shape.cornerRadiusDp,
borderStrokeWidth = primaryButton.shape.borderStrokeWidthDp,
cornerRadius = primaryButton.shape.cornerRadiusDp ?: shapes.cornerRadiusDp,
borderStrokeWidth =
primaryButton.shape.borderStrokeWidthDp ?: shapes.borderStrokeWidthDp,
),
typography = PrimaryButtonTypography(
fontFamily = primaryButton.typography.fontResId
fontFamily = primaryButton.typography.fontResId ?: typography.fontResId
)
)
}

0 comments on commit 9252188

Please sign in to comment.