-
Notifications
You must be signed in to change notification settings - Fork 649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CBC dropdown to UpdatePaymentMethodUI without full functionality #9686
Merged
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
577092e
Refactor view state out of cbc dropdown
amk-stripe 71ed3c8
Rename Dropdown -> CardBrandDropdown
amk-stripe fcb7911
Refactor view action handler out of CardBrandDropdown
amk-stripe ac9ece2
Move CardBrandChoice type out of EditPaymentMethodViewState
amk-stripe 54445bc
Add cardBrandFilter to getAvailableNetworks function
amk-stripe b7ee0e6
Update choice extension functions to work on cards instead of payment…
amk-stripe 14bcbe4
Move choice extension functions outside of interactor so they can be …
amk-stripe 5caa563
Add CBC drop down UI to UpdatePaymentMethodUI
amk-stripe 058898c
Fix lint
amk-stripe 491c4de
Add UI test
amk-stripe a19e55f
Fix compilation issues
amk-stripe e18fb68
Add screenshot test with CBC dropdown
amk-stripe e178b8c
Revert unneeded change
amk-stripe 94da3bf
Merge branch 'master' into make-cbc-dropdown-more-independent
amk-stripe 37e7c90
Fix lint issue
amk-stripe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was moved from EditPaymentMethod. It previously took in an EditPaymentMethodViewState and an EditPaymentMethodViewActionHandler as params. I refactored it so that it didn't rely on those specific types, so that we could re-use it in UpdatePaymentMethodUI |
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was moved from EditPaymentMethodViewState. I didn't make any changes to the existing type