Skip to content
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

Display selected PM in embedded playground. #9701

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading