Skip to content

Commit

Permalink
Display selected PM in playground. (#9701)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaynewstrom-stripe authored Nov 25, 2024
1 parent 20408fe commit 755d428
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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 = { },
)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fun PaymentMethodSelector(
isEnabled: Boolean,
paymentMethodLabel: String,
paymentMethodPainter: Painter?,
clickable: Boolean = isEnabled,
onClick: () -> Unit,
) {
Row(
Expand All @@ -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)
Expand Down

0 comments on commit 755d428

Please sign in to comment.