Skip to content

Commit

Permalink
Replace PaymentOptionEditState type with a boolean (#9846)
Browse files Browse the repository at this point in the history
  • Loading branch information
amk-stripe authored Jan 3, 2025
1 parent 9eb16c2 commit f2c6fad
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 30 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal val SavedPaymentMethodsTopContentPadding = 12.dp
internal fun SavedPaymentMethodTab(
viewWidth: Dp,
isSelected: Boolean,
editState: PaymentOptionEditState,
shouldShowModifyBadge: Boolean,
isEnabled: Boolean,
isClickable: Boolean = isEnabled,
iconRes: Int,
Expand All @@ -78,7 +78,7 @@ internal fun SavedPaymentMethodTab(
badge = {
SavedPaymentMethodBadge(
isSelected = isSelected,
editState = editState,
shouldShowModifyBadge = shouldShowModifyBadge,
onModifyListener = onModifyListener,
onModifyAccessibilityDescription = onModifyAccessibilityDescription
)
Expand Down Expand Up @@ -117,20 +117,17 @@ internal fun SavedPaymentMethodTab(
@Composable
private fun SavedPaymentMethodBadge(
isSelected: Boolean,
editState: PaymentOptionEditState,
shouldShowModifyBadge: Boolean,
onModifyListener: (() -> Unit)? = null,
onModifyAccessibilityDescription: String = ""
) {
when (editState) {
PaymentOptionEditState.Modifiable -> ModifyBadge(
if (shouldShowModifyBadge) {
ModifyBadge(
onModifyAccessibilityDescription = onModifyAccessibilityDescription,
onPressed = { onModifyListener?.invoke() },
modifier = Modifier.offset(x = (-14).dp, y = 1.dp),
)
PaymentOptionEditState.None -> Unit
}

if (isSelected) {
} else if (isSelected) {
SelectedBadge(
modifier = Modifier.offset(x = (-18).dp, y = 58.dp),
)
Expand Down Expand Up @@ -219,7 +216,7 @@ private fun SavedPaymentMethodTabUISelected() {
SavedPaymentMethodTab(
viewWidth = 100.dp,
isSelected = true,
editState = PaymentOptionEditState.None,
shouldShowModifyBadge = false,
isEnabled = true,
iconRes = R.drawable.stripe_ic_paymentsheet_card_visa,
labelText = "MasterCard",
Expand All @@ -236,7 +233,7 @@ private fun SavedPaymentMethodTabUIModifiable() {
SavedPaymentMethodTab(
viewWidth = 100.dp,
isSelected = false,
editState = PaymentOptionEditState.Modifiable,
shouldShowModifyBadge = true,
isEnabled = true,
iconRes = R.drawable.stripe_ic_paymentsheet_card_visa,
labelText = "MasterCard",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private fun AddCardTab(

SavedPaymentMethodTab(
viewWidth = width,
editState = PaymentOptionEditState.None,
shouldShowModifyBadge = false,
isSelected = false,
labelText = stringResource(R.string.stripe_paymentsheet_add_payment_method_button_label),
isEnabled = isEnabled,
Expand All @@ -311,7 +311,7 @@ private fun GooglePayTab(
) {
SavedPaymentMethodTab(
viewWidth = width,
editState = PaymentOptionEditState.None,
shouldShowModifyBadge = false,
isSelected = isSelected,
isEnabled = isEnabled,
iconRes = R.drawable.stripe_google_pay_mark,
Expand All @@ -332,7 +332,7 @@ private fun LinkTab(
) {
SavedPaymentMethodTab(
viewWidth = width,
editState = PaymentOptionEditState.None,
shouldShowModifyBadge = false,
isSelected = isSelected,
isEnabled = isEnabled,
iconRes = R.drawable.stripe_ic_paymentsheet_link,
Expand Down Expand Up @@ -371,10 +371,7 @@ private fun SavedPaymentMethodTab(
) {
SavedPaymentMethodTab(
viewWidth = width,
editState = when {
isEnabled && isEditing -> PaymentOptionEditState.Modifiable
else -> PaymentOptionEditState.None
},
shouldShowModifyBadge = isEnabled && isEditing,
isSelected = isSelected,
isEnabled = isEnabled,
isClickable = !isEditing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PaymentOptionScreenshotTest {
SavedPaymentMethodTab(
viewWidth = 160.dp,
isSelected = false,
editState = PaymentOptionEditState.None,
shouldShowModifyBadge = false,
isEnabled = true,
iconRes = R.drawable.stripe_ic_paymentsheet_card_visa,
labelText = "••••4242",
Expand All @@ -41,7 +41,7 @@ class PaymentOptionScreenshotTest {
SavedPaymentMethodTab(
viewWidth = 160.dp,
isSelected = false,
editState = PaymentOptionEditState.None,
shouldShowModifyBadge = false,
isEnabled = false,
iconRes = R.drawable.stripe_ic_paymentsheet_card_visa,
labelText = "••••4242",
Expand All @@ -57,7 +57,7 @@ class PaymentOptionScreenshotTest {
SavedPaymentMethodTab(
viewWidth = 160.dp,
isSelected = true,
editState = PaymentOptionEditState.None,
shouldShowModifyBadge = false,
isEnabled = true,
iconRes = R.drawable.stripe_ic_paymentsheet_card_visa,
labelText = "••••4242",
Expand All @@ -73,7 +73,7 @@ class PaymentOptionScreenshotTest {
SavedPaymentMethodTab(
viewWidth = 160.dp,
isSelected = true,
editState = PaymentOptionEditState.None,
shouldShowModifyBadge = false,
isEnabled = false,
iconRes = R.drawable.stripe_ic_paymentsheet_card_visa,
labelText = "••••4242",
Expand All @@ -89,7 +89,7 @@ class PaymentOptionScreenshotTest {
SavedPaymentMethodTab(
viewWidth = 160.dp,
isSelected = false,
editState = PaymentOptionEditState.Modifiable,
shouldShowModifyBadge = true,
isEnabled = true,
iconRes = R.drawable.stripe_ic_paymentsheet_card_visa,
labelText = "••••4242",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PaymentOptionTest {
SavedPaymentMethodTab(
viewWidth = 100.dp,
isSelected = false,
editState = PaymentOptionEditState.None,
shouldShowModifyBadge = false,
isEnabled = true,
iconRes = R.drawable.stripe_ic_paymentsheet_card_visa,
labelText = label,
Expand Down

0 comments on commit f2c6fad

Please sign in to comment.