Skip to content
Draft

Fix icon #12085

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 @@ -28,6 +28,7 @@ data class CustomFlowViewState(
val paymentSheetConfig: PaymentSheet.Configuration
get() = PaymentSheet.Configuration.Builder(merchantDisplayName = "Example, Inc.")
.customer(customerConfiguration)
.appearance(PaymentSheet.Appearance.Builder().colorsDark(PaymentSheet.Colors.Builder.light().build()).build())
.googlePay(
PaymentSheet.GooglePayConfiguration(
environment = PaymentSheet.GooglePayConfiguration.Environment.Test,
Expand Down
16 changes: 0 additions & 16 deletions paymentsheet/res/values-night/styles.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal class PaymentOptionFactory @Inject constructor(
) {
fun create(selection: PaymentSelection): PaymentOption {
val drawableResourceId = selection.drawableResourceId
val drawableResourceIdNight = selection.drawableResourceIdNight
val lightThemeIconUrl = selection.lightThemeIconUrl
val darkThemeIconUrl = selection.darkThemeIconUrl

Expand All @@ -24,7 +25,7 @@ internal class PaymentOptionFactory @Inject constructor(
imageLoader = {
iconLoader.load(
drawableResourceId = drawableResourceId,
drawableResourceIdNight = drawableResourceId,
drawableResourceIdNight = drawableResourceIdNight,
lightThemeIconUrl = lightThemeIconUrl,
darkThemeIconUrl = darkThemeIconUrl,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ import com.stripe.android.paymentsheet.paymentdatacollection.ach.BankFormScreenS
import com.stripe.android.paymentsheet.paymentdatacollection.ach.USBankAccountTextBuilder
import com.stripe.android.paymentsheet.ui.MIN_LUMINANCE_FOR_LIGHT_ICON
import com.stripe.android.paymentsheet.ui.createCardLabel
import com.stripe.android.paymentsheet.ui.getCardBrandIcon
import com.stripe.android.paymentsheet.ui.getCardBrandIconRef
import com.stripe.android.paymentsheet.ui.getLabel
import com.stripe.android.paymentsheet.ui.getLinkIcon
import com.stripe.android.paymentsheet.ui.getNightIcon
import com.stripe.android.paymentsheet.ui.getSavedPaymentMethodIcon
import com.stripe.android.uicore.StripeTheme
import com.stripe.android.uicore.image.StripeImageLoader
Expand Down Expand Up @@ -292,17 +293,14 @@ internal sealed class PaymentSelection : Parcelable {
private val resources: Resources,
private val imageLoader: StripeImageLoader,
) {
private fun isDarkTheme(): Boolean {
return resources.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK) ==
Configuration.UI_MODE_NIGHT_YES ||
isCustomDarkTheme()
}

/**
* Some users implement a custom dark mode and will pass dark colors into colors light.
*/
private fun isCustomDarkTheme(): Boolean {
return StripeTheme.colorsLightMutable.component.luminance() < MIN_LUMINANCE_FOR_LIGHT_ICON
private fun isDarkBackground(): Boolean {
val isSystemInDarkTheme = resources.configuration?.uiMode?.and(Configuration.UI_MODE_NIGHT_MASK) ==
Configuration.UI_MODE_NIGHT_YES
return StripeTheme.getColors(isSystemInDarkTheme).component.luminance() <
MIN_LUMINANCE_FOR_LIGHT_ICON
}

suspend fun load(
Expand All @@ -316,7 +314,7 @@ internal sealed class PaymentSelection : Parcelable {
return runCatching {
ResourcesCompat.getDrawable(
resources,
if (!isDarkTheme()) drawableResourceId else drawableResourceIdNight ?: drawableResourceId,
if (!isDarkBackground()) drawableResourceId else drawableResourceIdNight ?: drawableResourceId,
null
)
}.getOrNull() ?: emptyDrawable
Expand All @@ -330,7 +328,7 @@ internal sealed class PaymentSelection : Parcelable {

// If the payment option has an icon URL, we prefer it.
// Some payment options don't have an icon URL, and are loaded locally via resource.
return if (isDarkTheme() && darkThemeIconUrl != null) {
return if (isDarkBackground() && darkThemeIconUrl != null) {
loadIcon(darkThemeIconUrl)
} else if (lightThemeIconUrl != null) {
loadIcon(lightThemeIconUrl)
Expand Down Expand Up @@ -370,7 +368,7 @@ internal val PaymentSelection.drawableResourceId: Int
is PaymentSelection.CustomPaymentMethod -> 0
PaymentSelection.GooglePay -> R.drawable.stripe_google_pay_mark
is PaymentSelection.Link -> getLinkIcon(iconOnly = true)
is PaymentSelection.New.Card -> brand.getCardBrandIcon()
is PaymentSelection.New.Card -> brand.getCardBrandIconRef()
is PaymentSelection.New.GenericPaymentMethod -> iconResource
is PaymentSelection.New.USBankAccount -> iconResource
is PaymentSelection.Saved -> getSavedIcon(this)
Expand All @@ -383,7 +381,7 @@ internal val PaymentSelection.drawableResourceIdNight: Int
is PaymentSelection.CustomPaymentMethod -> 0
PaymentSelection.GooglePay -> R.drawable.stripe_google_pay_mark
is PaymentSelection.Link -> getLinkIcon(iconOnly = true)
is PaymentSelection.New.Card -> brand.getCardBrandIcon()
is PaymentSelection.New.Card -> brand.getNightIcon()
is PaymentSelection.New.GenericPaymentMethod -> iconResourceNight ?: iconResource
is PaymentSelection.New.USBankAccount -> iconResource
is PaymentSelection.Saved -> getSavedIcon(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ internal fun EditCardPayload.getSavedPaymentMethodIcon(
}
}

@DrawableRes
internal fun CardBrand.getCardBrandIcon(): Int {
return this.getCardBrandIconRef()
}

@DrawableRes
internal fun CardBrand.getCardBrandIconForVerticalMode(): Int = when (this) {
CardBrand.Visa -> com.stripe.payments.model.R.drawable.stripe_ic_visa_unpadded
Expand Down Expand Up @@ -133,7 +128,7 @@ internal fun CardBrand.getCardBrandIconForHorizontalMode(
}

@DrawableRes
private fun CardBrand.getCardBrandIconRef(): Int {
internal fun CardBrand.getCardBrandIconRef(): Int {
return when (this) {
CardBrand.Visa -> R.drawable.stripe_ic_paymentsheet_card_visa_ref
CardBrand.AmericanExpress -> R.drawable.stripe_ic_paymentsheet_card_amex_ref
Expand All @@ -149,7 +144,7 @@ private fun CardBrand.getCardBrandIconRef(): Int {
}

@DrawableRes
private fun CardBrand.getNightIcon(): Int {
internal fun CardBrand.getNightIcon(): Int {
return when (this) {
CardBrand.Visa -> R.drawable.stripe_ic_paymentsheet_card_visa_night
CardBrand.AmericanExpress -> R.drawable.stripe_ic_paymentsheet_card_amex_night
Expand Down
Loading