From 8b9e6420671cc76d5eac722970bc7ea96eea2c1c Mon Sep 17 00:00:00 2001 From: Jay Newstrom Date: Mon, 25 Nov 2024 06:13:01 -0700 Subject: [PATCH] Display selected PM in playground. --- .../embedded/EmbeddedPlaygroundActivity.kt | 33 ++++++++++++++++++- .../example/samples/ui/shared/Payment.kt | 5 +-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/embedded/EmbeddedPlaygroundActivity.kt b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/embedded/EmbeddedPlaygroundActivity.kt index 49c8bacda28..8998568f353 100644 --- a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/embedded/EmbeddedPlaygroundActivity.kt +++ b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/embedded/EmbeddedPlaygroundActivity.kt @@ -5,11 +5,21 @@ import android.content.Intent import android.os.Bundle import androidx.activity.compose.setContent import androidx.appcompat.app.AppCompatActivity +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp import com.stripe.android.paymentelement.EmbeddedPaymentElement import com.stripe.android.paymentelement.ExperimentalEmbeddedPaymentElementApi import com.stripe.android.paymentsheet.example.playground.PlaygroundState import com.stripe.android.paymentsheet.example.playground.settings.PlaygroundConfigurationData +import com.stripe.android.paymentsheet.example.samples.ui.shared.PaymentMethodSelector +import com.stripe.android.uicore.utils.collectAsState @OptIn(ExperimentalEmbeddedPaymentElementApi::class) internal class EmbeddedPlaygroundActivity : AppCompatActivity() { @@ -41,7 +51,28 @@ internal class EmbeddedPlaygroundActivity : AppCompatActivity() { configuration = playgroundState.embeddedConfiguration(), ) } - embeddedPaymentElement.Content() + + val scrollState = rememberScrollState() + Column( + modifier = Modifier + .fillMaxSize() + .verticalScroll(scrollState) + .padding(16.dp) + ) { + embeddedPaymentElement.Content() + + val selectedPaymentOption by embeddedPaymentElement.paymentOption.collectAsState() + + selectedPaymentOption?.let { selectedPaymentOption -> + PaymentMethodSelector( + isEnabled = true, + paymentMethodLabel = selectedPaymentOption.label, + paymentMethodPainter = selectedPaymentOption.iconPainter, + clickable = false, + onClick = { }, + ) + } + } } } } diff --git a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/shared/Payment.kt b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/shared/Payment.kt index fa4eeab4532..ca01bb9d71e 100644 --- a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/shared/Payment.kt +++ b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/samples/ui/shared/Payment.kt @@ -32,6 +32,7 @@ fun PaymentMethodSelector( isEnabled: Boolean, paymentMethodLabel: String, paymentMethodPainter: Painter?, + clickable: Boolean = isEnabled, onClick: () -> Unit, ) { Row( @@ -49,8 +50,8 @@ fun PaymentMethodSelector( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.End, modifier = Modifier.clickable( - enabled = isEnabled, - onClick = onClick + enabled = clickable, + onClick = onClick, ).semantics { testTag = PAYMENT_METHOD_SELECTOR_TEST_TAG text = AnnotatedString(paymentMethodLabel)