-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CBC dropdown to UpdatePaymentMethodUI without full functionality (#…
…9686) * Refactor view state out of cbc dropdown * Rename Dropdown -> CardBrandDropdown * Refactor view action handler out of CardBrandDropdown * Move CardBrandChoice type out of EditPaymentMethodViewState * Add cardBrandFilter to getAvailableNetworks function * Update choice extension functions to work on cards instead of payment methods * Move choice extension functions outside of interactor so they can be reused * Add CBC drop down UI to UpdatePaymentMethodUI * Fix lint * Add UI test * Fix compilation issues * Add screenshot test with CBC dropdown * Revert unneeded change * Fix lint issue
- Loading branch information
1 parent
5c60031
commit f6720ce
Showing
23 changed files
with
261 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/CardBrandChoice.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.stripe.android.paymentsheet.ui | ||
|
||
import com.stripe.android.core.strings.ResolvableString | ||
import com.stripe.android.core.strings.resolvableString | ||
import com.stripe.android.model.CardBrand | ||
import com.stripe.android.uicore.elements.SingleChoiceDropdownItem | ||
|
||
internal data class CardBrandChoice( | ||
val brand: CardBrand | ||
) : SingleChoiceDropdownItem { | ||
override val icon: Int | ||
get() = brand.icon | ||
|
||
override val label: ResolvableString | ||
get() = brand.displayName.resolvableString | ||
} |
92 changes: 92 additions & 0 deletions
92
paymentsheet/src/main/java/com/stripe/android/paymentsheet/ui/CardBrandDropdown.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.stripe.android.paymentsheet.ui | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.testTag | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.semantics.contentDescription | ||
import androidx.compose.ui.semantics.semantics | ||
import androidx.compose.ui.unit.dp | ||
import com.stripe.android.core.strings.resolvableString | ||
import com.stripe.android.uicore.R | ||
import com.stripe.android.uicore.elements.DROPDOWN_MENU_CLICKABLE_TEST_TAG | ||
import com.stripe.android.uicore.elements.SingleChoiceDropdown | ||
import com.stripe.android.uicore.stripeColors | ||
|
||
@Composable | ||
internal fun CardBrandDropdown( | ||
selectedBrand: CardBrandChoice, | ||
availableBrands: List<CardBrandChoice>, | ||
onBrandOptionsShown: () -> Unit, | ||
onBrandChoiceChanged: (CardBrandChoice) -> Unit, | ||
onBrandChoiceOptionsDismissed: () -> Unit, | ||
) { | ||
var expanded by remember { | ||
mutableStateOf(false) | ||
} | ||
|
||
Box( | ||
modifier = Modifier | ||
.clickable { | ||
if (!expanded) { | ||
expanded = true | ||
|
||
onBrandOptionsShown() | ||
} | ||
} | ||
.semantics { | ||
this.contentDescription = selectedBrand.brand.displayName | ||
} | ||
.testTag(DROPDOWN_MENU_CLICKABLE_TEST_TAG) | ||
) { | ||
Row( | ||
modifier = Modifier.padding(10.dp), | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = Arrangement.spacedBy(4.dp) | ||
) { | ||
Image( | ||
painter = painterResource(id = selectedBrand.icon), | ||
contentDescription = null | ||
) | ||
|
||
Icon( | ||
painter = painterResource( | ||
id = R.drawable.stripe_ic_chevron_down | ||
), | ||
contentDescription = null | ||
) | ||
} | ||
|
||
SingleChoiceDropdown( | ||
expanded = expanded, | ||
title = com.stripe.android.R.string.stripe_card_brand_choice_selection_header.resolvableString, | ||
currentChoice = selectedBrand, | ||
choices = availableBrands, | ||
headerTextColor = MaterialTheme.stripeColors.subtitle, | ||
optionTextColor = MaterialTheme.stripeColors.onComponent, | ||
onChoiceSelected = { item -> | ||
expanded = false | ||
|
||
onBrandChoiceChanged(item) | ||
}, | ||
onDismiss = { | ||
expanded = false | ||
|
||
onBrandChoiceOptionsDismissed() | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.