Skip to content

Commit

Permalink
Fix issue with flow controller appearance (#5388)
Browse files Browse the repository at this point in the history
* Fix issue with flow controller appearance
  • Loading branch information
jameswoo-stripe authored Aug 10, 2022
1 parent 23038ce commit 7a96684
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* [ADDED][5340](https://github.com/stripe/stripe-android/pull/5340) Add a `resetCustomer` method to
`PaymentSheet`, that clears any persisted authentication state.
* [FIXED][5388](https://github.com/stripe/stripe-android/pull/5388) Fixed issue with Appearance API
not working with `FlowController`

## 20.8.0 - 2022-08-01

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.stripe.android.paymentsheet.ui.AnimationConstants
import com.stripe.android.paymentsheet.ui.BaseSheetActivity
import com.stripe.android.paymentsheet.ui.PrimaryButton
import com.stripe.android.paymentsheet.viewmodels.BaseSheetViewModel
import java.security.InvalidParameterException

/**
* An `Activity` for selecting a payment option.
Expand Down Expand Up @@ -70,13 +71,20 @@ internal class PaymentOptionsActivity : BaseSheetActivity<PaymentOptionResult>()
override val bottomSpacer: View by lazy { viewBinding.bottomSpacer }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val starterArgs = this.starterArgs
if (starterArgs == null) {
finish()
return
}
try {
starterArgs.config?.validate()
starterArgs.config?.appearance?.parseAppearance()
} catch (e: InvalidParameterException) {
finish()
return
}

super.onCreate(savedInstanceState)

starterArgs.statusBarColor?.let {
window.statusBarColor = it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ internal class PrimaryButton @JvmOverloads constructor(
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {
private var defaultTintList: ColorStateList? = null
@VisibleForTesting
internal var defaultTintList: ColorStateList? = null
private var state: State? = null
private val animator = PrimaryButtonAnimator(context)

Expand Down Expand Up @@ -88,8 +89,8 @@ internal class PrimaryButton @JvmOverloads constructor(
viewBinding.lockIcon.imageTintList = ColorStateList.valueOf(
primaryButtonStyle.getOnBackgroundColor(context)
)
backgroundTintList = tintList
defaultTintList = tintList
backgroundTintList = tintList
}

override fun setBackgroundTintList(tintList: ColorStateList?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package com.stripe.android.paymentsheet
import android.app.Application
import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.core.os.bundleOf
import androidx.core.view.isVisible
import androidx.lifecycle.SavedStateHandle
Expand Down Expand Up @@ -380,6 +383,38 @@ class PaymentOptionsActivityTest {
}
}

@Test
fun `primary button appearance is set`() {
val scenario = activityScenario()
scenario.launch(
createIntent(
args = PAYMENT_OPTIONS_CONTRACT_ARGS.copy(
config = PaymentSheetFixtures.CONFIG_MINIMUM.copy(
appearance = PaymentSheet.Appearance(
primaryButton = PaymentSheet.PrimaryButton(
colorsLight = PaymentSheet.PrimaryButtonColors(
background = Color.Magenta,
onBackground = Color.Magenta,
border = Color.Magenta
),
shape = PaymentSheet.PrimaryButtonShape(),
typography = PaymentSheet.PrimaryButtonTypography()
)
)
)
)
)
).use {
idleLooper()
it.onActivity { activity ->
assertThat(activity.viewBinding.continueButton.isVisible).isTrue()
assertThat(activity.viewBinding.continueButton.defaultTintList).isEqualTo(
ColorStateList.valueOf(Color.Magenta.toArgb())
)
}
}
}

private fun createIntent(
args: PaymentOptionContract.Args = PAYMENT_OPTIONS_CONTRACT_ARGS
): Intent {
Expand Down

0 comments on commit 7a96684

Please sign in to comment.